Struct fj_kernel::storage::HandleWrapper
source · pub struct HandleWrapper<T>(pub Handle<T>);Expand description
A wrapper around Handle to define equality based on identity
This is a utility type that implements Eq/PartialEq and other common
traits that are based on those, based on the identity of object that the
wrapped handle references. This is useful, if a type of object doesn’t
implement Eq/PartialEq, which means handles referencing it won’t
implement those types either.
Typically, if an object doesn’t implement Eq/PartialEq, it will do
so for good reason. If you need something that represents the object and
implements those missing traits, you might want to be explicit about what
you’re doing, and access its ID via Handle::id instead.
But if you have a struct that owns a Handle to such an object, and you
want to be able to derive various traits that are not available for the
Handle itself, this wrapper is for you.
Tuple Fields§
§0: Handle<T>Methods from Deref<Target = Handle<T>>§
sourcepub fn id(&self) -> ObjectId
pub fn id(&self) -> ObjectId
Access this pointer’s unique id
Examples found in repository?
206 207 208 209 210 211 212 213 214 215 216 217 218
fn get<T>(&mut self, handle: &Handle<T>) -> Option<Inner<T>>
where
T: HasPartial + 'static,
{
self.map().get(&handle.id()).cloned()
}
fn insert<T>(&mut self, handle: &Handle<T>, inner: Inner<T>)
where
T: HasPartial + 'static,
{
self.map().insert(handle.id(), inner);
}More examples
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
fn get<T: 'static>(&mut self, key: &Handle<T>) -> Option<&Handle<T>> {
let map = self
.0
.entry::<BTreeMap<ObjectId, Handle<T>>>()
.or_insert_with(BTreeMap::new);
map.get(&key.id())
}
fn insert<T: 'static>(&mut self, key: Handle<T>, value: Handle<T>) {
let map = self
.0
.entry::<BTreeMap<ObjectId, Handle<T>>>()
.or_insert_with(BTreeMap::new);
map.insert(key.id(), value);
}168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
pub fn insert(
&mut self,
handle: Handle<GlobalCurve>,
range: RangeOnPath,
approx: GlobalCurveApprox,
) -> GlobalCurveApprox {
self.inner.insert((handle.id(), range), approx.clone());
approx
}
/// Access the approximation for the given [`GlobalCurve`], if available
pub fn get(
&self,
handle: Handle<GlobalCurve>,
range: RangeOnPath,
) -> Option<GlobalCurveApprox> {
self.inner.get(&(handle.id(), range)).cloned()
}115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
fn check_curve_identity(half_edge: &HalfEdge) -> Result<(), Self> {
let back_curve = half_edge.back().curve();
let front_curve = half_edge.front().curve();
if back_curve.id() != front_curve.id() {
return Err(Self::CurveMismatch {
back_curve: back_curve.clone(),
front_curve: front_curve.clone(),
});
}
Ok(())
}
fn check_global_curve_identity(half_edge: &HalfEdge) -> Result<(), Self> {
let global_curve_from_curve = half_edge.curve().global_form();
let global_curve_from_global_form = half_edge.global_form().curve();
if global_curve_from_curve.id() != global_curve_from_global_form.id() {
return Err(Self::GlobalCurveMismatch {
global_curve_from_curve: global_curve_from_curve.clone(),
global_curve_from_global_form: global_curve_from_global_form
.clone(),
});
}
Ok(())
}
fn check_global_vertex_identity(half_edge: &HalfEdge) -> Result<(), Self> {
let global_vertices_from_vertices = {
let (global_vertices_from_vertices, _) =
VerticesInNormalizedOrder::new(
half_edge
.vertices()
.each_ref_ext()
.map(|vertex| vertex.global_form().clone()),
);
global_vertices_from_vertices.access_in_normalized_order()
};
let global_vertices_from_global_form = half_edge
.global_form()
.vertices()
.access_in_normalized_order();
let ids_from_vertices = global_vertices_from_vertices
.each_ref_ext()
.map(|global_vertex| global_vertex.id());
let ids_from_global_form = global_vertices_from_global_form
.each_ref_ext()
.map(|global_vertex| global_vertex.id());
if ids_from_vertices != ids_from_global_form {
return Err(Self::GlobalVertexMismatch {
global_vertices_from_vertices,
global_vertices_from_global_form,
});
}
Ok(())
}64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn check_surface_identity(face: &Face) -> Result<(), Self> {
let surface = face.surface();
for interior in face.interiors() {
if surface.id() != interior.surface().id() {
return Err(Self::SurfaceMismatch {
surface: surface.clone(),
interior: interior.clone(),
face: face.clone(),
});
}
}
Ok(())
}sourcepub fn clone_object(&self) -> Twhere
T: Clone,
pub fn clone_object(&self) -> Twhere
T: Clone,
Return a clone of the object this handle refers to
Examples found in repository?
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
fn transform_with_cache(
self,
transform: &Transform,
objects: &mut Service<Objects>,
cache: &mut TransformCache,
) -> Self {
if let Some(object) = cache.get(&self) {
return object.clone();
}
let transformed = self
.clone_object()
.transform_with_cache(transform, objects, cache)
.insert(objects);
cache.insert(self.clone(), transformed.clone());
transformed
}More examples
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn check_position(
vertex: &Vertex,
config: &ValidationConfig,
) -> Result<(), Self> {
let curve_position_as_surface = vertex
.curve()
.path()
.point_from_path_coords(vertex.position());
let surface_position = vertex.surface_form().position();
let distance = curve_position_as_surface.distance_to(&surface_position);
if distance > config.identical_max_distance {
return Err(Self::PositionMismatch {
vertex: vertex.clone(),
surface_vertex: vertex.surface_form().clone_object(),
curve_position_as_surface,
distance,
});
}
Ok(())
}
}
/// [`SurfaceVertex`] validation error
#[derive(Clone, Debug, thiserror::Error)]
pub enum SurfaceVertexValidationError {
/// Mismatch between position and position of global form
#[error(
"`SurfaceVertex` position doesn't match position of its global form\n\
- `SurfaceVertex`: {surface_vertex:#?}\n\
- `GlobalVertex`: {global_vertex:#?}\n\
- `SurfaceVertex` position as global: {surface_position_as_global:?}\n\
- Distance between the positions: {distance}"
)]
PositionMismatch {
/// The surface vertex
surface_vertex: SurfaceVertex,
/// The mismatched global vertex
global_vertex: GlobalVertex,
/// The surface position converted into a global position
surface_position_as_global: Point<3>,
/// The distance between the positions
distance: Scalar,
},
}
impl SurfaceVertexValidationError {
fn check_position(
surface_vertex: &SurfaceVertex,
config: &ValidationConfig,
) -> Result<(), Self> {
let surface_position_as_global = surface_vertex
.surface()
.geometry()
.point_from_surface_coords(surface_vertex.position());
let global_position = surface_vertex.global_form().position();
let distance = surface_position_as_global.distance_to(&global_position);
if distance > config.identical_max_distance {
return Err(Self::PositionMismatch {
surface_vertex: surface_vertex.clone(),
global_vertex: surface_vertex.global_form().clone_object(),
surface_position_as_global,
distance,
});
}
Ok(())
}Trait Implementations§
source§impl<T> Clone for HandleWrapper<T>
impl<T> Clone for HandleWrapper<T>
source§impl<T> Debug for HandleWrapper<T>where
T: Debug,
impl<T> Debug for HandleWrapper<T>where
T: Debug,
source§impl<T> Deref for HandleWrapper<T>
impl<T> Deref for HandleWrapper<T>
source§impl<T> From<Handle<T>> for HandleWrapper<T>
impl<T> From<Handle<T>> for HandleWrapper<T>
source§impl<T> From<HandleWrapper<T>> for Handle<T>
impl<T> From<HandleWrapper<T>> for Handle<T>
source§fn from(wrapper: HandleWrapper<T>) -> Self
fn from(wrapper: HandleWrapper<T>) -> Self
source§impl<T> Hash for HandleWrapper<T>
impl<T> Hash for HandleWrapper<T>
source§impl<T> Ord for HandleWrapper<T>
impl<T> Ord for HandleWrapper<T>
source§impl<T> PartialEq<HandleWrapper<T>> for HandleWrapper<T>
impl<T> PartialEq<HandleWrapper<T>> for HandleWrapper<T>
source§impl<T> PartialOrd<HandleWrapper<T>> for HandleWrapper<T>
impl<T> PartialOrd<HandleWrapper<T>> for HandleWrapper<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl<T> Eq for HandleWrapper<T>
impl<T> Send for HandleWrapper<T>
impl<T> Sync for HandleWrapper<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for HandleWrapper<T>
impl<T> Unpin for HandleWrapper<T>
impl<T> !UnwindSafe for HandleWrapper<T>
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§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.§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.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.