added conic endpoint

This commit is contained in:
benjamaan476
2025-05-29 11:26:21 +01:00
parent 8cf67a29bf
commit 9f9601d49a
4 changed files with 109 additions and 1 deletions

View File

@ -1152,6 +1152,11 @@ pub enum Path {
minor_radius: f64, minor_radius: f64,
ccw: bool, ccw: bool,
}, },
//TODO: (bc) figure this out
Conic {
#[serde(flatten)]
base: BasePath,
}
} }
/// What kind of path is this? /// What kind of path is this?
@ -1167,6 +1172,7 @@ enum PathType {
AngledLineTo, AngledLineTo,
Arc, Arc,
Ellipse, Ellipse,
Conic,
} }
impl From<&Path> for PathType { impl From<&Path> for PathType {
@ -1183,6 +1189,7 @@ impl From<&Path> for PathType {
Path::Arc { .. } => Self::Arc, Path::Arc { .. } => Self::Arc,
Path::ArcThreePoint { .. } => Self::Arc, Path::ArcThreePoint { .. } => Self::Arc,
Path::Ellipse { .. } => Self::Ellipse, Path::Ellipse { .. } => Self::Ellipse,
Path::Conic { .. } => Self::Conic,
} }
} }
} }
@ -1201,6 +1208,7 @@ impl Path {
Path::Arc { base, .. } => base.geo_meta.id, Path::Arc { base, .. } => base.geo_meta.id,
Path::ArcThreePoint { base, .. } => base.geo_meta.id, Path::ArcThreePoint { base, .. } => base.geo_meta.id,
Path::Ellipse { base, .. } => base.geo_meta.id, Path::Ellipse { base, .. } => base.geo_meta.id,
Path::Conic { base, .. } => base.geo_meta.id,
} }
} }
@ -1217,6 +1225,7 @@ impl Path {
Path::Arc { base, .. } => base.geo_meta.id = id, Path::Arc { base, .. } => base.geo_meta.id = id,
Path::ArcThreePoint { base, .. } => base.geo_meta.id = id, Path::ArcThreePoint { base, .. } => base.geo_meta.id = id,
Path::Ellipse { base, .. } => base.geo_meta.id = id, Path::Ellipse { base, .. } => base.geo_meta.id = id,
Path::Conic { base, .. } => base.geo_meta.id = id,
} }
} }
@ -1233,6 +1242,7 @@ impl Path {
Path::Arc { base, .. } => base.tag.clone(), Path::Arc { base, .. } => base.tag.clone(),
Path::ArcThreePoint { base, .. } => base.tag.clone(), Path::ArcThreePoint { base, .. } => base.tag.clone(),
Path::Ellipse { base, .. } => base.tag.clone(), Path::Ellipse { base, .. } => base.tag.clone(),
Path::Conic { base, .. } => base.tag.clone(),
} }
} }
@ -1249,6 +1259,7 @@ impl Path {
Path::Arc { base, .. } => base, Path::Arc { base, .. } => base,
Path::ArcThreePoint { base, .. } => base, Path::ArcThreePoint { base, .. } => base,
Path::Ellipse { base, .. } => base, Path::Ellipse { base, .. } => base,
Path::Conic { base, .. } => base,
} }
} }
@ -1328,6 +1339,10 @@ impl Path {
//TODO: fix me //TODO: fix me
10.0 10.0
} }
Self::Conic { .. } => {
//TODO: fix me
10.0
}
}; };
TyF64::new(n, self.get_base().units.into()) TyF64::new(n, self.get_base().units.into())
} }
@ -1345,6 +1360,7 @@ impl Path {
Path::Arc { base, .. } => Some(base), Path::Arc { base, .. } => Some(base),
Path::ArcThreePoint { base, .. } => Some(base), Path::ArcThreePoint { base, .. } => Some(base),
Path::Ellipse { base, .. } => Some(base), Path::Ellipse { base, .. } => Some(base),
Path::Conic { base, .. } => Some(base),
} }
} }
@ -1380,6 +1396,7 @@ impl Path {
radius: circle.radius, radius: circle.radius,
} }
} }
// TODO: (bc) fix me
Path::Ellipse { Path::Ellipse {
center, center,
major_radius, major_radius,
@ -1392,6 +1409,7 @@ impl Path {
_minor_radius: *minor_radius, _minor_radius: *minor_radius,
ccw: *ccw, ccw: *ccw,
}, },
Path::Conic { .. } |
Path::ToPoint { .. } | Path::Horizontal { .. } | Path::AngledLineTo { .. } | Path::Base { .. } => { Path::ToPoint { .. } | Path::Horizontal { .. } | Path::AngledLineTo { .. } | Path::Base { .. } => {
let base = self.get_base(); let base = self.get_base();
GetTangentialInfoFromPathsResult::PreviousPoint(base.from) GetTangentialInfoFromPathsResult::PreviousPoint(base.from)

View File

@ -329,7 +329,9 @@ pub(crate) async fn do_post_extrude<'a>(
Path::Arc { .. } Path::Arc { .. }
| Path::TangentialArc { .. } | Path::TangentialArc { .. }
| Path::TangentialArcTo { .. } | Path::TangentialArcTo { .. }
// TODO: (bc) fix me
| Path::Ellipse { .. } | Path::Ellipse { .. }
| Path::Conic {.. }
| Path::Circle { .. } | Path::Circle { .. }
| Path::CircleThreePoint { .. } => { | Path::CircleThreePoint { .. } => {
let extrude_surface = ExtrudeSurface::ExtrudeArc(crate::execution::ExtrudeArc { let extrude_surface = ExtrudeSurface::ExtrudeArc(crate::execution::ExtrudeArc {

View File

@ -60,6 +60,7 @@ lazy_static! {
Box::new(crate::std::shapes::CircleThreePoint), Box::new(crate::std::shapes::CircleThreePoint),
Box::new(crate::std::shapes::Ellipse), Box::new(crate::std::shapes::Ellipse),
Box::new(crate::std::shapes::Polygon), Box::new(crate::std::shapes::Polygon),
Box::new(crate::std::sketch::Conic),
Box::new(crate::std::sketch::EllipticalArc), Box::new(crate::std::sketch::EllipticalArc),
Box::new(crate::std::sketch::InvoluteCircular), Box::new(crate::std::sketch::InvoluteCircular),
Box::new(crate::std::sketch::Line), Box::new(crate::std::sketch::Line),

View File

@ -2494,7 +2494,7 @@ pub(crate) async fn inner_elliptical_arc(
let start_angle = Angle::from_degrees(angle_start.to_degrees()); let start_angle = Angle::from_degrees(angle_start.to_degrees());
let end_angle = Angle::from_degrees(angle_end.to_degrees()); let end_angle = Angle::from_degrees(angle_end.to_degrees());
let to = [ let to = [
center_u[0] + major_radius.to_length_units(from.units) * start_angle.to_radians().cos(), center_u[0] + major_radius.to_length_units(from.units) * end_angle.to_radians().cos(),
center_u[1] + minor_radius.to_length_units(from.units) * end_angle.to_radians().sin(), center_u[1] + minor_radius.to_length_units(from.units) * end_angle.to_radians().sin(),
]; ];
@ -2554,6 +2554,93 @@ pub(crate) async fn inner_elliptical_arc(
Ok(new_sketch) Ok(new_sketch)
} }
/// Draw a conic section
pub async fn conic(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let sketch = args.get_unlabeled_kw_arg_typed("sketch", &RuntimeType::Primitive(PrimitiveType::Sketch), exec_state)?;
let start_tangent: [TyF64; 2] = args.get_kw_arg_typed("startTangent", &RuntimeType::point2d(), exec_state)?;
let end_tangent: [TyF64; 2] = args.get_kw_arg_typed("endTangent", &RuntimeType::point2d(), exec_state)?;
let end: [TyF64; 2] = args.get_kw_arg_typed("end", &RuntimeType::point2d(), exec_state)?;
let interior: [TyF64; 2] = args.get_kw_arg_typed("interior", &RuntimeType::point2d(), exec_state)?;
let tag = args.get_kw_arg_opt(NEW_TAG_KW)?;
let new_sketch = inner_conic(sketch, start_tangent, end, end_tangent, interior, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),
})
}
/// ```no_run
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [0, 0])
/// |> conic(
/// end = [10,0],
/// endTangent = [0,1],
/// interior = [5,5],
/// startTangent = [0, -1],
/// )
/// |> close()
/// example = extrude(exampleSketch, length = 10)
/// ```
#[stdlib {
name = "conic",
unlabeled_first = true,
args = {
sketch = { docs = "Which sketch should this path be added to?" },
start_tangent = { docs = "The tangent of the conic at the start point (the end of the previous path segement)" },
end_tangent = { docs = "The tangent of the conic at the end point" },
interior = { docs = "Any point between the arc's start and end?" },
end = { docs = "Where should this arc end?" },
tag = { docs = "Create a new tag which refers to this line"},
},
tags = ["sketch"]
}]
#[allow(clippy::too_many_arguments)]
pub(crate) async fn inner_conic(sketch: Sketch, start_tangent: [TyF64; 2], end: [TyF64; 2], end_tangent: [TyF64; 2], interior: [TyF64; 2], tag: Option<TagNode>, exec_state: &mut ExecState, args: Args
) -> Result<Sketch, KclError> {
let from: Point2d = sketch.current_pen_position()?;
let id = exec_state.next_uuid();
let (start_tangent, _) = untype_point(start_tangent);
let (end_tangent, _) = untype_point(end_tangent);
let (end, _) = untype_point(end);
let (interior, _) = untype_point(interior);
args.batch_modeling_cmd(
id,
ModelingCmd::from(mcmd::ExtendPath {
path: sketch.id.into(),
segment: PathSegment::ConicTo {
start_tangent: KPoint2d::from(untyped_point_to_mm(start_tangent, from.units)).map(LengthUnit),
end_tangent: KPoint2d::from(untyped_point_to_mm(end_tangent, from.units)).map(LengthUnit),
end: KPoint2d::from(untyped_point_to_mm(end, from.units)).map(LengthUnit),
interior: KPoint2d::from(untyped_point_to_mm(interior, from.units)).map(LengthUnit),
relative: false,
},
}),
).await?;
let current_path = Path::Conic {
base: BasePath {
from: from.ignore_units(),
to: end,
tag: tag.clone(),
units: sketch.units,
geo_meta: GeoMeta {
id,
metadata: args.source_range.into(),
},
},
};
let mut new_sketch = sketch.clone();
if let Some(tag) = &tag {
new_sketch.add_tag(tag, &current_path, exec_state);
}
new_sketch.paths.push(current_path);
Ok(new_sketch)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {