summaryrefslogtreecommitdiff
path: root/src/geom/point.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-23 22:04:08 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-23 22:04:08 +0100
commit8a88f71cb11565c1a78bd57f02a8df17cb2bf7a0 (patch)
tree8802c1ff48e2be118e3872d25bd2f2c1f7a21b4a /src/geom/point.rs
parentc77c5a0f0ae6560a03a85e847006c29de9c7ae62 (diff)
Transformations
Diffstat (limited to 'src/geom/point.rs')
-rw-r--r--src/geom/point.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/geom/point.rs b/src/geom/point.rs
index 7c11e81b..49e3018a 100644
--- a/src/geom/point.rs
+++ b/src/geom/point.rs
@@ -25,6 +25,16 @@ impl Point {
Self { x: value, y: value }
}
+ /// Create a new point with y set to zero.
+ pub const fn with_x(x: Length) -> Self {
+ Self { x, y: Length::zero() }
+ }
+
+ /// Create a new point with x set to zero.
+ pub const fn with_y(y: Length) -> Self {
+ Self { x: Length::zero(), y }
+ }
+
/// Convert to the generic representation.
pub const fn to_gen(self, block: SpecAxis) -> Gen<Length> {
match block {
@@ -32,6 +42,14 @@ impl Point {
SpecAxis::Vertical => Gen::new(self.x, self.y),
}
}
+
+ /// Transform the point with the given transformation.
+ pub fn transform(self, transform: Transform) -> Self {
+ Self::new(
+ transform.sx.resolve(self.x) + transform.kx.resolve(self.y) + transform.tx,
+ transform.ky.resolve(self.x) + transform.sy.resolve(self.y) + transform.ty,
+ )
+ }
}
impl Get<SpecAxis> for Point {