diff options
| author | Arne Dußin | 2020-12-20 03:58:46 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-12-20 16:41:52 +0100 |
| commit | 48f321a80970ebeb8374072b1d2e0a4d297aa348 (patch) | |
| tree | 8f6dbffef7ed507ae118919917fd69a7a9528c39 /src/map/polygon_room.rs | |
| parent | c073618d9773216ab4a2dcd7944589f38b1df751 (diff) | |
| download | graf_karto-48f321a80970ebeb8374072b1d2e0a4d297aa348.tar.gz graf_karto-48f321a80970ebeb8374072b1d2e0a4d297aa348.zip | |
Add dimensional indicator with scaling
Diffstat (limited to 'src/map/polygon_room.rs')
| -rw-r--r-- | src/map/polygon_room.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/map/polygon_room.rs b/src/map/polygon_room.rs index a209a7c..65eeaab 100644 --- a/src/map/polygon_room.rs +++ b/src/map/polygon_room.rs @@ -1,9 +1,10 @@ use super::Mappable; use crate::colours::DEFAULT_COLOURS; -use crate::math::{self, Polygon, Rect, Triangle, Vec2}; -use crate::scaleable::Scaleable; +use crate::math::{self, Polygon, Rect, Triangle}; use crate::transform::Transform; +use crate::transformable::NonRigidTransformable; use raylib::drawing::{RaylibDraw, RaylibDrawHandle}; +use nalgebra::{Matrix3, Point2}; pub type PolygonRoomData = Polygon<f64>; @@ -56,20 +57,21 @@ impl Mappable for PolygonRoom { Rect::bounding_rect_n(&self.data.corners()) } - fn as_scaleable(&self) -> Option<&dyn Scaleable> { - Some(self as &dyn Scaleable) + fn as_non_rigid(&self) -> Option<&dyn NonRigidTransformable> { + Some(self as &dyn NonRigidTransformable) } -} -impl Scaleable for PolygonRoom { - fn scale(&mut self, by: &Vec2<f64>) { - if by.x < 0. || by.y < 0. { - panic!("Cannot set dimensions with negative size"); - } + fn as_non_rigid_mut(&mut self) -> Option<&mut dyn NonRigidTransformable> { + Some(self as &mut dyn NonRigidTransformable) + } +} +impl NonRigidTransformable for PolygonRoom { + fn apply_matrix(&mut self, matrix: &Matrix3<f64>) { for corner in self.data.corners_mut() { - corner.x *= by.x; - corner.y *= by.y; + *corner = matrix + .transform_point(&Point2::new(corner.x, corner.y)) + .into(); } self.retriangulate(); |
