mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-24 07:48:12 +08:00
Context nullification, cached monitor nodes
This commit is contained in:
@@ -486,6 +486,21 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn center(&self) -> Option<DVec2> {
|
||||
let len = self.manipulator_groups.len();
|
||||
if len == 0 {
|
||||
return None;
|
||||
} else if len % 2 == 1 {
|
||||
return Some(self.manipulator_groups[len / 2].anchor);
|
||||
} else {
|
||||
let p0 = self.manipulator_groups[len / 2 - 1].anchor;
|
||||
let p1 = self.manipulator_groups[len / 2 - 1].out_handle;
|
||||
let p2 = self.manipulator_groups[len / 2].in_handle;
|
||||
let p3 = self.manipulator_groups[len / 2].anchor;
|
||||
Some(0.125 * p0 + 0.375 * p1.unwrap_or(p0) + 0.375 * p2.unwrap_or(p3) + 0.125 * p3)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the necessary information to create a round join with the provided center.
|
||||
/// The returned items correspond to:
|
||||
/// - The `out_handle` for the last manipulator group of `self`
|
||||
|
||||
@@ -123,6 +123,21 @@ pub fn downcast<'a, V: StaticType + 'a>(i: Box<dyn DynAny<'a> + 'a>) -> Result<B
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub fn try_downcast<'a, V: StaticType + 'a>(i: Box<dyn DynAny<'a> + 'a>) -> Result<Box<V>, Box<dyn DynAny<'a> + 'a>> {
|
||||
let type_id = DynAny::type_id(i.as_ref());
|
||||
if type_id == core::any::TypeId::of::<<V as StaticType>::Static>() {
|
||||
// SAFETY: caller guarantees that T is the correct type
|
||||
let ptr = Box::into_raw(i) as *mut V;
|
||||
Ok(unsafe { Box::from_raw(ptr) })
|
||||
} else {
|
||||
if type_id == core::any::TypeId::of::<&dyn DynAny<'static>>() {
|
||||
panic!("downcast error: type_id == core::any::TypeId::of::<dyn DynAny<'a>>()");
|
||||
}
|
||||
Err(i)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe trait StaticType {
|
||||
type Static: 'static + ?Sized;
|
||||
fn type_id(&self) -> core::any::TypeId {
|
||||
|
||||
Reference in New Issue
Block a user