mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 00:38:12 +08:00
Implement bounding box function for bezier-rs (#726)
* Implement bounding box function for bezier-rs * Fix eslint errors Co-authored-by: Linda Zheng <linda-zheng@users.noreply.github.com> * Rename bbox to bounding_box * Address Keavon's comments * Fix eslint issue Co-authored-by: Hannah Li <hannahli2010@gmail.com> Co-authored-by: Linda Zheng <linda-zheng@users.noreply.github.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Linda Zheng
Hannah Li
parent
4ebdd1abb1
commit
c05c93c8a2
@@ -773,6 +773,26 @@ impl Bezier {
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
/// Return the min and max corners that represent the bounding box of the curve.
|
||||
pub fn bounding_box(&self) -> [DVec2; 2] {
|
||||
// Start by taking min/max of endpoints.
|
||||
let mut endpoints_min = self.start.min(self.end);
|
||||
let mut endpoints_max = self.start.max(self.end);
|
||||
|
||||
// Iterate through extrema points.
|
||||
let extrema = self.local_extrema();
|
||||
for t_values in extrema {
|
||||
for t in t_values {
|
||||
let point = self.evaluate(t);
|
||||
// Update bounding box if new min/max is found.
|
||||
endpoints_min = endpoints_min.min(point);
|
||||
endpoints_max = endpoints_max.max(point);
|
||||
}
|
||||
}
|
||||
|
||||
[endpoints_min, endpoints_max]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user