Remove snap rotate from layerdata (#435)

This commit is contained in:
0HyperCube
2021-12-28 18:30:41 +01:00
committed by Keavon Chambers
parent 9afa29097b
commit c1560dbec3
3 changed files with 20 additions and 21 deletions
+2 -14
View File
@@ -1,4 +1,3 @@
use crate::consts::VIEWPORT_ROTATE_SNAP_INTERVAL;
use glam::{DAffine2, DVec2};
use graphene::layers::{style::ViewMode, BlendMode, Layer, LayerData as DocumentLayerData, LayerDataType};
use graphene::LayerId;
@@ -12,7 +11,6 @@ pub struct LayerData {
pub expanded: bool,
pub translation: DVec2,
pub rotation: f64,
pub snap_rotate: bool,
pub scale: f64,
}
@@ -23,25 +21,15 @@ impl LayerData {
expanded,
translation: DVec2::ZERO,
rotation: 0.,
snap_rotate: false,
scale: 1.,
}
}
pub fn snapped_angle(&self) -> f64 {
let increment_radians: f64 = VIEWPORT_ROTATE_SNAP_INTERVAL.to_radians();
if self.snap_rotate {
(self.rotation / increment_radians).round() * increment_radians
} else {
self.rotation
}
}
pub fn calculate_offset_transform(&self, offset: DVec2) -> DAffine2 {
pub fn calculate_offset_transform(&self, offset: DVec2, snapped_angle: f64) -> DAffine2 {
// TODO: replace with DAffine2::from_scale_angle_translation and fix the errors
let offset_transform = DAffine2::from_translation(offset);
let scale_transform = DAffine2::from_scale(DVec2::new(self.scale, self.scale));
let angle_transform = DAffine2::from_angle(self.snapped_angle());
let angle_transform = DAffine2::from_angle(snapped_angle);
let translation_transform = DAffine2::from_translation(self.translation);
scale_transform * offset_transform * angle_transform * translation_transform
}