blockworx_editor/shape/pin.rs
1//! The pin vocabulary the geometry layer draws in: the document's pin
2//! entity and its value enums, plus the derived readings the drawing and
3//! hit-test paths take off a pin's registers.
4
5use blockworx_doc::geometry::PinSlot;
6
7pub use blockworx_doc::{
8 block_model::Pin,
9 values::{PinDir, PinSide},
10};
11
12/// The slot a pin occupies on its owner's boundary — the edge and the
13/// index, read as one atomic value.
14pub fn slot(pin: &Pin) -> PinSlot {
15 pin.slot
16}
17
18/// Which way a pin's *port body* faces when the pin is drawn as its own
19/// boundary port. `flip_lr` reads `false` as "opposite the edge the pin
20/// occupies", so the interior stub points inward, and `true` as "frozen to
21/// face that edge". Use this, never [`slot`]'s side, for every port-view
22/// drawing, hit test, and route anchor.
23pub fn orientation(pin: &Pin) -> PinSide {
24 let slot = slot(pin);
25 if pin.flip_lr {
26 slot.side
27 } else {
28 slot.side.flip()
29 }
30}
31
32/// The opposite sense, used when a pin is rendered as a port. `InOut` has no
33/// sense, so it is unchanged.
34pub fn flipped_dir(dir: PinDir) -> PinDir {
35 match dir {
36 PinDir::Input => PinDir::Output,
37 PinDir::Output => PinDir::Input,
38 PinDir::InOut => PinDir::InOut,
39 }
40}