Change length of certain segment types to be a runtime error
This commit is contained in:
@ -1293,11 +1293,12 @@ impl Path {
|
|||||||
(*p, ty)
|
(*p, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Length of this path segment, in cartesian plane.
|
/// Length of this path segment, in cartesian plane. Not all segment types
|
||||||
pub fn length(&self) -> TyF64 {
|
/// are supported.
|
||||||
|
pub fn length(&self) -> Option<TyF64> {
|
||||||
let n = match self {
|
let n = match self {
|
||||||
Self::ToPoint { .. } | Self::Base { .. } | Self::Horizontal { .. } | Self::AngledLineTo { .. } => {
|
Self::ToPoint { .. } | Self::Base { .. } | Self::Horizontal { .. } | Self::AngledLineTo { .. } => {
|
||||||
linear_distance(&self.get_base().from, &self.get_base().to)
|
Some(linear_distance(&self.get_base().from, &self.get_base().to))
|
||||||
}
|
}
|
||||||
Self::TangentialArc {
|
Self::TangentialArc {
|
||||||
base: _,
|
base: _,
|
||||||
@ -1314,7 +1315,7 @@ impl Path {
|
|||||||
let radius = linear_distance(&self.get_base().from, center);
|
let radius = linear_distance(&self.get_base().from, center);
|
||||||
debug_assert_eq!(radius, linear_distance(&self.get_base().to, center));
|
debug_assert_eq!(radius, linear_distance(&self.get_base().to, center));
|
||||||
// TODO: Call engine utils to figure this out.
|
// TODO: Call engine utils to figure this out.
|
||||||
linear_distance(&self.get_base().from, &self.get_base().to)
|
Some(linear_distance(&self.get_base().from, &self.get_base().to))
|
||||||
}
|
}
|
||||||
Self::Circle { radius, .. } => 2.0 * std::f64::consts::PI * radius,
|
Self::Circle { radius, .. } => 2.0 * std::f64::consts::PI * radius,
|
||||||
Self::CircleThreePoint { .. } => {
|
Self::CircleThreePoint { .. } => {
|
||||||
@ -1327,23 +1328,23 @@ impl Path {
|
|||||||
&[circle_center.center[0], circle_center.center[1]],
|
&[circle_center.center[0], circle_center.center[1]],
|
||||||
&self.get_base().from,
|
&self.get_base().from,
|
||||||
);
|
);
|
||||||
2.0 * std::f64::consts::PI * radius
|
Some(2.0 * std::f64::consts::PI * radius)
|
||||||
}
|
}
|
||||||
Self::Arc { .. } => {
|
Self::Arc { .. } => {
|
||||||
// TODO: Call engine utils to figure this out.
|
// TODO: Call engine utils to figure this out.
|
||||||
linear_distance(&self.get_base().from, &self.get_base().to)
|
Some(linear_distance(&self.get_base().from, &self.get_base().to))
|
||||||
}
|
}
|
||||||
Self::ArcThreePoint { .. } => {
|
Self::ArcThreePoint { .. } => {
|
||||||
// TODO: Call engine utils to figure this out.
|
// TODO: Call engine utils to figure this out.
|
||||||
linear_distance(&self.get_base().from, &self.get_base().to)
|
Some(linear_distance(&self.get_base().from, &self.get_base().to))
|
||||||
}
|
}
|
||||||
Self::Ellipse { .. } => {
|
Self::Ellipse { .. } => {
|
||||||
//TODO: fix me
|
// Not supported.
|
||||||
10.0
|
None
|
||||||
}
|
}
|
||||||
Self::Conic { .. } => {
|
Self::Conic { .. } => {
|
||||||
//TODO: fix me
|
// Not supported.
|
||||||
10.0
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TyF64::new(n, self.get_base().units.into())
|
TyF64::new(n, self.get_base().units.into())
|
||||||
|
@ -200,7 +200,12 @@ fn inner_segment_length(tag: &TagIdentifier, exec_state: &mut ExecState, args: A
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(path.length())
|
path.length().ok_or_else(|| {
|
||||||
|
KclError::new_semantic(KclErrorDetails::new(
|
||||||
|
"Computing the length of this segment type is unsupported".to_owned(),
|
||||||
|
vec![args.source_range],
|
||||||
|
))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the angle of the segment.
|
/// Returns the angle of the segment.
|
||||||
|
Reference in New Issue
Block a user