Skip to main content

GeometryResolver

Struct GeometryResolver 

Source
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>

Source

pub fn new() -> Self

Creates an empty resolver.

Source

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());
Source

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);
Source

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.

Source

pub fn extend( &mut self, geometries: impl IntoIterator<Item = AbstractGeometryKindRef<'a>>, )

Indexes every geometry in geometries that carries an id.

Source

pub fn resolve(&self, id: &Id) -> Option<AbstractGeometryKindRef<'a>>

Looks up the geometry stored under id, if any.

Source

pub fn resolve_as<T>(&self, id: &Id) -> Option<T>

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());
Source

pub fn contains(&self, id: &Id) -> bool

Returns true if id is indexed.

Source

pub fn ids(&self) -> impl Iterator<Item = &Id>

Returns an iterator over all indexed ids, in arbitrary order.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Id, &AbstractGeometryKindRef<'a>)>

Returns an iterator over all indexed (id, geometry) pairs, in arbitrary order.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<'a> Clone for GeometryResolver<'a>

Source§

fn clone(&self) -> GeometryResolver<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for GeometryResolver<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for GeometryResolver<'a>

Source§

fn default() -> GeometryResolver<'a>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.