pub struct GeometryResolver<'a> { /* private fields */ }Expand description
Resolves gml:id/xlink:href references to the geometry they point at.
Indexes borrowed AbstractGeometryKindRefs by Id, so lookups by
reference are O(1) instead of re-walking the geometry tree. Geometries
without an id are not indexed — they cannot be referenced by
xlink:href in the first place.
Implementations§
Source§impl<'a> GeometryResolver<'a>
impl<'a> GeometryResolver<'a>
Sourcepub fn build<T: IterGeometries>(root: &'a T) -> Self
pub fn build<T: IterGeometries>(root: &'a T) -> Self
Builds a resolver by recursively walking root and indexing every
descendant geometry (including root itself) that carries an id.
§Examples
use egml_core::model::geometry::DirectPosition;
use egml_core::model::geometry::primitives::Point;
use egml_core::model::base::{AsAbstractGmlMut, Id};
use egml_core::resolver::GeometryResolver;
let mut point = Point::new(DirectPosition::new(1.0, 2.0, 3.0).unwrap());
point.set_id(Id::try_from("point-1").expect("valid id"));
let resolver = GeometryResolver::build(&point);
assert!(resolver.resolve(&Id::try_from("point-1").expect("valid id")).is_some());Sourcepub fn insert_root<T: IterGeometries>(&mut self, root: &'a T)
pub fn insert_root<T: IterGeometries>(&mut self, root: &'a T)
Recursively walks root and indexes every descendant geometry
(including root itself) that carries an id.
Unlike build, this adds to an existing resolver
instead of creating a new one — call it once per top-level geometry
when a document has several independent roots (e.g. one per feature
in a city model) that should all resolve through the same table.
§Examples
use egml_core::model::base::{AsAbstractGmlMut, Id};
use egml_core::model::geometry::DirectPosition;
use egml_core::model::geometry::primitives::Point;
use egml_core::resolver::GeometryResolver;
let mut first = Point::new(DirectPosition::new(1.0, 2.0, 3.0).unwrap());
first.set_id(Id::try_from("point-1").expect("valid id"));
let mut second = Point::new(DirectPosition::new(4.0, 5.0, 6.0).unwrap());
second.set_id(Id::try_from("point-2").expect("valid id"));
let mut resolver = GeometryResolver::new();
resolver.insert_root(&first);
resolver.insert_root(&second);
assert_eq!(resolver.len(), 2);Sourcepub fn insert(&mut self, geometry: AbstractGeometryKindRef<'a>) -> bool
pub fn insert(&mut self, geometry: AbstractGeometryKindRef<'a>) -> bool
Indexes a single geometry by its id, if it has one.
Returns true if the geometry had an id and was stored. If another
geometry was already indexed under the same id, it is silently
replaced — gml:id is supposed to be unique within a document, so a
collision indicates malformed input rather than a case this resolver
needs to arbitrate.
Sourcepub fn extend(
&mut self,
geometries: impl IntoIterator<Item = AbstractGeometryKindRef<'a>>,
)
pub fn extend( &mut self, geometries: impl IntoIterator<Item = AbstractGeometryKindRef<'a>>, )
Indexes every geometry in geometries that carries an id.
Sourcepub fn resolve(&self, id: &Id) -> Option<AbstractGeometryKindRef<'a>>
pub fn resolve(&self, id: &Id) -> Option<AbstractGeometryKindRef<'a>>
Looks up the geometry stored under id, if any.
Sourcepub fn resolve_as<T>(&self, id: &Id) -> Option<T>where
T: TryFrom<AbstractGeometryKindRef<'a>>,
pub fn resolve_as<T>(&self, id: &Id) -> Option<T>where
T: TryFrom<AbstractGeometryKindRef<'a>>,
Looks up the geometry stored under id and downcasts it to a concrete
leaf type or intermediate *Ref enum via the TryFrom conversions
generated across the geometry ref hierarchy.
Returns None if id is unresolved, or if it resolves to a geometry
of a different concrete type than T.
§Examples
use egml_core::model::base::{AsAbstractGmlMut, Id};
use egml_core::model::geometry::DirectPosition;
use egml_core::model::geometry::primitives::LinearRing;
use egml_core::resolver::GeometryResolver;
let mut ring = LinearRing::new([
DirectPosition::new(0.0, 0.0, 0.0).unwrap(),
DirectPosition::new(1.0, 0.0, 0.0).unwrap(),
DirectPosition::new(0.0, 1.0, 0.0).unwrap(),
])
.unwrap();
ring.set_id(Id::try_from("ring-1").expect("valid id"));
let resolver = GeometryResolver::build(&ring);
let resolved: Option<&LinearRing> = resolver.resolve_as(&Id::try_from("ring-1").expect("valid id"));
assert!(resolved.is_some());Sourcepub fn ids(&self) -> impl Iterator<Item = &Id>
pub fn ids(&self) -> impl Iterator<Item = &Id>
Returns an iterator over all indexed ids, in arbitrary order.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Id, &AbstractGeometryKindRef<'a>)>
pub fn iter(&self) -> impl Iterator<Item = (&Id, &AbstractGeometryKindRef<'a>)>
Returns an iterator over all indexed (id, geometry) pairs, in
arbitrary order.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl<'a> Clone for GeometryResolver<'a>
impl<'a> Clone for GeometryResolver<'a>
Source§fn clone(&self) -> GeometryResolver<'a>
fn clone(&self) -> GeometryResolver<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for GeometryResolver<'a>
impl<'a> Debug for GeometryResolver<'a>
Source§impl<'a> Default for GeometryResolver<'a>
impl<'a> Default for GeometryResolver<'a>
Source§fn default() -> GeometryResolver<'a>
fn default() -> GeometryResolver<'a>
Auto Trait Implementations§
impl<'a> Freeze for GeometryResolver<'a>
impl<'a> RefUnwindSafe for GeometryResolver<'a>
impl<'a> Send for GeometryResolver<'a>
impl<'a> Sync for GeometryResolver<'a>
impl<'a> Unpin for GeometryResolver<'a>
impl<'a> UnsafeUnpin for GeometryResolver<'a>
impl<'a> UnwindSafe for GeometryResolver<'a>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.