ferroui_base/platform/i_geometry_impl.rs
1use crate::media::{IPen, IntersectionResult};
2use crate::platform::ITransformedGeometryImpl;
3use crate::{Matrix, Point, Rect};
4use std::sync::Arc;
5
6/// Defines the platform-specific interface for a geometry.
7pub trait IGeometryImpl: Send + Sync + 'static {
8 /// The geometry's bounding rectangle.
9 fn bounds(&self) -> Rect;
10
11 /// The geometry's total length as if all its contours are placed in a
12 /// straight line.
13 fn contour_length(&self) -> f64;
14
15 /// Gets the geometry's bounding rectangle with the specified pen.
16 fn get_render_bounds(&self, pen: Option<&dyn IPen>) -> Rect;
17
18 /// Gets a geometry that is the shape defined by the stroke on the
19 /// geometry produced by the specified pen.
20 fn get_widened_geometry(&self, pen: &dyn IPen) -> Arc<dyn IGeometryImpl>;
21
22 /// Indicates whether the geometry's fill contains the specified point.
23 fn fill_contains(&self, point: Point) -> bool;
24
25 /// Gets the relation between this geometry's fill and another one's.
26 fn get_fill_intersection_result(&self, geometry: &dyn IGeometryImpl) -> IntersectionResult;
27
28 /// Intersects the geometry with another geometry.
29 ///
30 /// Returns a new geometry object representing the intersection or `None`
31 /// when the operation failed.
32 fn intersect(&self, geometry: &dyn IGeometryImpl) -> Option<Arc<dyn IGeometryImpl>>;
33
34 /// Indicates whether the geometry's stroke contains the specified point.
35 fn stroke_contains(&self, pen: Option<&dyn IPen>, point: Point) -> bool;
36
37 /// Makes a clone of the geometry with the specified transform.
38 fn with_transform(&self, transform: Matrix) -> Arc<dyn ITransformedGeometryImpl>;
39
40 /// Attempts to get the corresponding point at the specified distance.
41 fn try_get_point_at_distance(&self, distance: f64) -> Option<Point>;
42
43 /// Attempts to get the corresponding point and tangent from the
44 /// specified distance along the contour of the geometry.
45 fn try_get_point_and_tangent_at_distance(&self, distance: f64) -> Option<(Point, Point)>;
46
47 /// Attempts to get the corresponding path segment given by the two
48 /// distances specified. Imagine it like snipping a part of the current
49 /// geometry.
50 ///
51 /// When `start_on_begin_figure` is true, the resulting snipped path
52 /// begins with a figure start.
53 fn try_get_segment(
54 &self,
55 start_distance: f64,
56 stop_distance: f64,
57 start_on_begin_figure: bool,
58 ) -> Option<Arc<dyn IGeometryImpl>>;
59
60 /// Lets the backend recover its concrete type.
61 fn as_any(&self) -> &dyn std::any::Any;
62
63 /// The geometry viewed as [`ITransformedGeometryImpl`], when it is one.
64 fn as_transformed_geometry(&self) -> Option<&dyn ITransformedGeometryImpl> {
65 None
66 }
67}