Improvements on flex layout positioning

This commit is contained in:
alonso.torres 2025-03-18 16:08:21 +01:00
parent 4c12af957c
commit a830c27ceb
6 changed files with 175 additions and 72 deletions

View file

@ -5,6 +5,8 @@ pub type Matrix = skia::Matrix;
pub type Vector = skia::Vector;
pub type Point = skia::Point;
const THRESHOLD: f32 = 0.001;
pub trait VectorExt {
fn new_points(a: &Point, b: &Point) -> Vector;
}
@ -16,7 +18,20 @@ impl VectorExt for Vector {
}
}
#[derive(Debug, Clone, PartialEq)]
pub fn is_close_to(current: f32, value: f32) -> bool {
(current - value).abs() <= THRESHOLD
}
pub fn identitish(m: Matrix) -> bool {
is_close_to(m.scale_x(), 1.0)
&& is_close_to(m.scale_y(), 1.0)
&& is_close_to(m.translate_x(), 0.0)
&& is_close_to(m.translate_y(), 0.0)
&& is_close_to(m.skew_x(), 0.0)
&& is_close_to(m.skew_y(), 0.0)
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Bounds {
pub nw: Point,
pub ne: Point,
@ -95,9 +110,9 @@ impl Bounds {
self.sw = mtx.map_point(self.sw);
}
// pub fn box_bounds(&self, other: &Self) -> Option<Self> {
// self.from_points(other.points())
// }
pub fn box_bounds(&self, other: &Self) -> Option<Self> {
self.from_points(other.points())
}
pub fn from_points(&self, points: Vec<Point>) -> Option<Self> {
let hv = self.horizontal_vec();