aboutsummaryrefslogtreecommitdiff
path: root/src/map/wall.rs
diff options
context:
space:
mode:
authorArne Dußin2020-12-20 03:58:46 +0100
committerArne Dußin2020-12-20 16:41:52 +0100
commit48f321a80970ebeb8374072b1d2e0a4d297aa348 (patch)
tree8f6dbffef7ed507ae118919917fd69a7a9528c39 /src/map/wall.rs
parentc073618d9773216ab4a2dcd7944589f38b1df751 (diff)
downloadgraf_karto-48f321a80970ebeb8374072b1d2e0a4d297aa348.tar.gz
graf_karto-48f321a80970ebeb8374072b1d2e0a4d297aa348.zip
Add dimensional indicator with scaling
Diffstat (limited to 'src/map/wall.rs')
-rw-r--r--src/map/wall.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/map/wall.rs b/src/map/wall.rs
index 22393bb..d18096b 100644
--- a/src/map/wall.rs
+++ b/src/map/wall.rs
@@ -1,10 +1,11 @@
use super::Mappable;
use crate::colours::DEFAULT_COLOURS;
use crate::math::{LineSegment, Rect, Vec2};
-use crate::scaleable::Scaleable;
use crate::transform::Transform;
+use crate::transformable::NonRigidTransformable;
use raylib::drawing::{RaylibDraw, RaylibDrawHandle};
use std::ops::{Deref, DerefMut};
+use nalgebra::{Matrix3, Point2};
pub type WallData = LineSegment<f64>;
@@ -81,18 +82,24 @@ impl Mappable for Wall {
fn bounding_rect(&self) -> Rect<f64> {
Rect::bounding_rect(self.data.start, self.data.end)
}
-}
-impl Scaleable for Wall {
- 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(&self) -> Option<&dyn NonRigidTransformable> {
+ Some(self as &dyn NonRigidTransformable)
+ }
+
+ fn as_non_rigid_mut(&mut self) -> Option<&mut dyn NonRigidTransformable> {
+ Some(self as &mut dyn NonRigidTransformable)
+ }
+}
- self.data.start.x *= by.x;
- self.data.start.y *= by.y;
- self.data.end.x *= by.x;
- self.data.end.y *= by.y;
+impl NonRigidTransformable for Wall {
+ fn apply_matrix(&mut self, matrix: &Matrix3<f64>) {
+ self.data.start = matrix
+ .transform_point(&self.data.start.into())
+ .into();
+ self.data.end = matrix
+ .transform_point(&self.data.end.into())
+ .into();
}
}