pub struct AreaObject {
pub tags: HashMap<String, String>,
pub pattern_rotation: PatternRotation,
pub symbol: WeakAreaPathSymbol,
pub bezier_write_error: Option<NonNegativeF64>,
/* private fields */
}Expand description
An area (polygon) object on the map.
Fields§
The tags associated with the object
pattern_rotation: PatternRotationThe fill-pattern rotation and origin.
symbol: WeakAreaPathSymbolThe area or combined-area symbol used to render this object.
bezier_write_error: Option<NonNegativeF64>The permitted error when fitting Bézier curves for writing.
Bézier fitting is enabled when this is Some.
Implementations§
Source§impl AreaObject
impl AreaObject
Sourcepub fn new(symbol: impl Into<WeakAreaPathSymbol>, geometry: Polygon) -> Self
pub fn new(symbol: impl Into<WeakAreaPathSymbol>, geometry: Polygon) -> Self
Create a new area object with the given symbol and geometry.
Sourcepub fn into_geometry(self, allowed_error: f64) -> Result<Polygon, Error>
pub fn into_geometry(self, allowed_error: f64) -> Result<Polygon, Error>
Consume this object and return its polygon geometry.
§Errors
Returns an error if the object has no usable geometry or if uncached raw geometry cannot be flattened with the requested error tolerance.
Sourcepub fn get_geometry(&self, allowed_error: f64) -> Result<&Polygon, Error>
pub fn get_geometry(&self, allowed_error: f64) -> Result<&Polygon, Error>
Get the polygon geometry, flattening and caching raw Bézier coordinates when needed.
allowed_error is used only when initializing the cache. Later calls
return the previously cached geometry.
§Errors
Returns an error if the object has no usable geometry or if its raw geometry cannot be flattened with the requested error tolerance.
Examples found in repository?
28fn main() -> Result<(), Error> {
29 let mut map = Omap::from_path("./example_data/from_path.omap")?;
30
31 #[cfg(feature = "geo_ref")]
32 {
33 // we want to move the map center to the average position of all objects
34 let old_transform = map.geo_referencing.get_transform();
35
36 let mut mean_pos = Coord::zero();
37 let mut num_coords = 0;
38 for obj in map.parts.iter().flat_map(|part| part.iter_all_objects()) {
39 match obj {
40 MapObject::Point(object) => {
41 mean_pos = mean_pos + object.get_geometry().0;
42 num_coords += 1;
43 }
44 MapObject::Line(object) => {
45 let geometry = object.get_geometry(0.1)?;
46 mean_pos =
47 mean_pos + geometry.0.iter().copied().reduce(|sum, c| sum + c).unwrap();
48 num_coords += geometry.0.len();
49 }
50 MapObject::Area(object) => {
51 let geometry = object.get_geometry(0.1)?;
52 mean_pos = mean_pos
53 + geometry
54 .exterior()
55 .0
56 .iter()
57 .copied()
58 .reduce(|sum, c| sum + c)
59 .unwrap();
60 num_coords += geometry.exterior().0.len();
61 }
62 MapObject::Text(object) => {
63 match object.get_geometry() {
64 TextGeometry::SingleAnchor(coord) => mean_pos = mean_pos + *coord,
65 TextGeometry::WrapBox(wrap_box) => mean_pos = mean_pos + wrap_box.anchor,
66 }
67 num_coords += 1;
68 }
69 }
70 }
71 mean_pos = mean_pos / num_coords as f64;
72
73 // now transform that into projected coords
74 let mean_proj_pos = old_transform.to_projected(mean_pos);
75
76 // get the new georef info for that position
77 let new_gr = GeoRef::initialize(
78 mean_proj_pos,
79 map.geo_referencing.crs_type,
80 2_469.,
81 map.geo_referencing.scale_denominator,
82 )
83 .unwrap();
84
85 // assign the new info
86 map.geo_referencing = new_gr;
87
88 // get the new map transform
89 let new_transform = map.geo_referencing.get_transform();
90
91 // transfrom every object out of the old map space to projected coords
92 // and from projected coord to the new map space
93 // NB! If the new projection were different than the old,
94 // a transfrom between projections using a proj library like proj-core would be needed
95 // and this function would return Err
96 map.apply_affine_between(&old_transform, &new_transform)
97 .unwrap();
98 };
99
100 println!("Map colors in order:");
101 for color in map.colors.iter() {
102 match color {
103 Color::SpotColor(ref_cell) => {
104 let b = ref_cell.try_borrow().unwrap();
105 println!("{} with spot name {}", b.color_name, b.spotcolor_name);
106 }
107 Color::MixedColor(ref_cell) => {
108 println!("{}", ref_cell.try_borrow().unwrap().color_name);
109 }
110 }
111 }
112
113 let erosion_gully = map
114 .symbols
115 .get_symbol_by_code(Code::new(107, 0, 0))
116 .unwrap()
117 .downgrade();
118
119 let mut ls = LineObject::new(
120 WeakLinePathSymbol::try_from(erosion_gully).unwrap(),
121 // geometry coordinates are always in mm of paper
122 LineString::new(vec![Coord { x: -60., y: -50. }, Coord { x: 60., y: -50. }]),
123 );
124 ls.tags.insert("Some Key".to_owned(), "My value".to_owned());
125
126 map.parts.0[0].add_object(ls);
127
128 let weak_symbol = map
129 .symbols
130 .get_symbol_by_name("Contour value")
131 .unwrap()
132 .downgrade();
133
134 let ts = TextObject::new(
135 Weak::<RefCell<TextSymbol>>::try_from(weak_symbol)
136 .expect("The symbol type of Contour value is not Text"),
137 TextGeometry::SingleAnchor(Coord { x: 0., y: 0. }),
138 "This is the middle of the map".to_owned(),
139 );
140 map.parts.0[0].add_object(ts);
141
142 map.write_to_file("./from_path_out.omap")
143}Sourcepub fn bezier_geometry(&self) -> Option<BezierPolygon>
pub fn bezier_geometry(&self) -> Option<BezierPolygon>
Rebuild the original area geometry as mixed straight/cubic Bézier rings, including dash-point metadata for every vertex.
This is generated directly from the original file coordinates and
therefore preserves the exact Bézier handles. Every returned ring is
closed, matching Polygon’s invariant, and zero-segment rings are
omitted. For a successfully parsed object, ring order and count match
Self::get_geometry.
Returns None when the object was not read from raw file coordinates
or after Self::get_geometry_mut has marked those coordinates as
touched.
Sourcepub fn get_geometry_bezier(&self) -> Option<BezierPolygon>
👎Deprecated: renamed to bezier_geometry
pub fn get_geometry_bezier(&self) -> Option<BezierPolygon>
renamed to bezier_geometry
Rebuild the original area geometry as mixed straight/cubic Bézier rings.
Prefer Self::bezier_geometry, whose name makes the reconstruction
cost explicit.
Sourcepub fn get_geometry_mut(
&mut self,
allowed_error: f64,
) -> Result<&mut Polygon, Error>
pub fn get_geometry_mut( &mut self, allowed_error: f64, ) -> Result<&mut Polygon, Error>
Get a mutable reference to the polygon geometry, flattening it first when needed, and mark the coordinates as touched.
allowed_error is used only when initializing the cache.
§Errors
Returns an error if the object has no usable geometry or if its raw geometry cannot be flattened with the requested error tolerance.
Sourcepub fn raw_coords(&self) -> impl ExactSizeIterator<Item = (Coord, u8)> + '_
pub fn raw_coords(&self) -> impl ExactSizeIterator<Item = (Coord, u8)> + '_
Iterate over the raw file coordinates in mm with their flags.
These are the original control points (including Bézier handles) as read
from the file, converted from µm integers to mm floats. See the
COORD_FLAG_* constants in this module for the flag assignments.
The iterator is empty for objects not read from file data.
Sourcepub fn get_raw_coords(&self) -> Vec<(Coord, u8)>
👎Deprecated: use the allocation-free raw_coords iterator
pub fn get_raw_coords(&self) -> Vec<(Coord, u8)>
use the allocation-free raw_coords iterator
Get the raw file coordinates in mm with their flags.
Prefer Self::raw_coords when a collected Vec is not needed.
Sourcepub fn apply_affine(&mut self, transform: &AffineMapTransform)
pub fn apply_affine(&mut self, transform: &AffineMapTransform)
Apply an affine coordinate transform to both the geometry and the raw control points, preserving Bézier structure without re-approximation.
This does not mark the coordinates as touched, so the raw (affine transformed) control points (with Bézier flags) will still be used on write.
Sourcepub fn reverse_polygon(&mut self)
pub fn reverse_polygon(&mut self)
Reverse the winding order of all rings.
Sourcepub fn new_element(geometry: Polygon) -> Self
pub fn new_element(geometry: Polygon) -> Self
Create an AreaObject for use as a PointSymbol element (no map symbol needed)
Trait Implementations§
Source§impl Clone for AreaObject
impl Clone for AreaObject
Source§fn clone(&self) -> AreaObject
fn clone(&self) -> AreaObject
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AreaObject
impl Debug for AreaObject
Source§impl From<AreaObject> for MapObject
impl From<AreaObject> for MapObject
Source§fn from(value: AreaObject) -> Self
fn from(value: AreaObject) -> Self
Auto Trait Implementations§
impl !Freeze for AreaObject
impl !RefUnwindSafe for AreaObject
impl !Send for AreaObject
impl !Sync for AreaObject
impl !UnwindSafe for AreaObject
impl Unpin for AreaObject
impl UnsafeUnpin for AreaObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more