summaryrefslogtreecommitdiff
path: root/src/geom/path.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-20 15:51:07 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-20 15:51:07 +0100
commitcef46e6c40fed0089a20e44ff2f251c06878891c (patch)
treea4f12ced1441a014f0446f5b01e3f0f87bdd21b5 /src/geom/path.rs
parent70c0dd767452772d29167e39b1c4f919519422ce (diff)
Strokes
Diffstat (limited to 'src/geom/path.rs')
-rw-r--r--src/geom/path.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/geom/path.rs b/src/geom/path.rs
index bc0d3f2d..39e75312 100644
--- a/src/geom/path.rs
+++ b/src/geom/path.rs
@@ -20,22 +20,35 @@ impl Path {
Self(vec![])
}
+ /// Create a path that describes a rectangle.
+ pub fn rect(size: Size) -> Self {
+ let z = Length::zero();
+ let point = Point::new;
+ let mut path = Self::new();
+ path.move_to(point(z, z));
+ path.line_to(point(size.w, z));
+ path.line_to(point(size.w, size.h));
+ path.line_to(point(z, size.h));
+ path.close_path();
+ path
+ }
+
/// Create a path that approximates an axis-aligned ellipse.
pub fn ellipse(size: Size) -> Self {
// https://stackoverflow.com/a/2007782
+ let z = Length::zero();
let rx = size.w / 2.0;
let ry = size.h / 2.0;
let m = 0.551784;
let mx = m * rx;
let my = m * ry;
- let z = Length::zero();
- let point = Point::new;
+ let point = |x, y| Point::new(x + rx, y + ry);
let mut path = Self::new();
path.move_to(point(-rx, z));
- path.cubic_to(point(-rx, my), point(-mx, ry), point(z, ry));
- path.cubic_to(point(mx, ry), point(rx, my), point(rx, z));
- path.cubic_to(point(rx, -my), point(mx, -ry), point(z, -ry));
- path.cubic_to(point(-mx, -ry), point(-rx, -my), point(z - rx, z));
+ path.cubic_to(point(-rx, -my), point(-mx, -ry), point(z, -ry));
+ path.cubic_to(point(mx, -ry), point(rx, -my), point(rx, z));
+ path.cubic_to(point(rx, my), point(mx, ry), point(z, ry));
+ path.cubic_to(point(-mx, ry), point(-rx, my), point(-rx, z));
path
}