diff options
| author | Martin Haug <mhaug@live.de> | 2022-05-02 18:25:53 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-05-02 18:25:53 +0200 |
| commit | 9b4397cdab25daff448cefb179a4699f64fa3d3f (patch) | |
| tree | d5a684a4bcc0846e3213f3777f33159db21a2639 /src | |
| parent | f07395f9a47502c50f767f78a233d0e2a6e4445f (diff) | |
Tests for the new shape API
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval/value.rs | 5 | ||||
| -rw-r--r-- | src/geom/rect.rs | 9 | ||||
| -rw-r--r-- | src/library/graphics/shape.rs | 10 |
3 files changed, 15 insertions, 9 deletions
diff --git a/src/eval/value.rs b/src/eval/value.rs index c32614df..352906aa 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -596,7 +596,10 @@ impl<T: Cast> Cast for Smart<T> { } } -impl<T: Cast + Default + Clone> Cast for Sides<T> { +impl<T> Cast for Sides<T> +where + T: Cast + Default + Clone, +{ fn is(value: &Value) -> bool { matches!(value, Value::Dict(_)) || T::is(value) } diff --git a/src/geom/rect.rs b/src/geom/rect.rs index 839feda4..f0da2db6 100644 --- a/src/geom/rect.rs +++ b/src/geom/rect.rs @@ -28,7 +28,7 @@ impl Rect { res.push(Shape { geometry: self.fill_geometry(), fill, - stroke: stroke.left, + stroke: stroke.is_uniform().then(|| stroke.top).flatten(), }); } @@ -174,6 +174,8 @@ fn draw_side( } } +/// A state machine that indicates which sides of the border strokes in a 2D +/// polygon are connected to their neighboring sides. #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum Connection { None, @@ -183,6 +185,9 @@ enum Connection { } impl Connection { + /// Advance to the next clockwise side of the polygon. The argument + /// indicates whether the border is connected on the right side of the next + /// edge. pub fn advance(self, right: bool) -> Self { match self { Self::Right | Self::Both => { @@ -202,10 +207,12 @@ impl Connection { } } + /// Whether there is a connection on the left. fn left(self) -> bool { matches!(self, Self::Left | Self::Both) } + /// Whether there is a connection on the right. fn right(self) -> bool { matches!(self, Self::Right | Self::Both) } diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index e6fd2b7d..a5523a2e 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -171,13 +171,9 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { frame.size.y + outset.top + outset.bottom, ); - let radius = styles.get(Self::RADIUS); - let radius = Sides { - left: radius.left.relative_to(size.x / 2.0), - top: radius.top.relative_to(size.y / 2.0), - right: radius.right.relative_to(size.x / 2.0), - bottom: radius.bottom.relative_to(size.y / 2.0), - }; + let radius = styles + .get(Self::RADIUS) + .map(|side| side.relative_to(size.x.min(size.y) / 2.0)); let pos = Point::new(-outset.left, -outset.top); |
