Revolve adjacency info (#7008)

* check edge colinear

* cleanup

* revert cargo.toml

* revert cargo.toml properly

* undo yarn.lock

* clippy

* add new sim test

* move tolerance2

* typo

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fmt

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update snap

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* push real snap

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Ben Crabbe
2025-05-16 23:02:30 +01:00
committed by GitHub
parent d35531758d
commit e7d2289a14
18 changed files with 1103 additions and 5 deletions

View File

@ -161,6 +161,7 @@ async fn fix_tags_and_references(
},
exec_state,
args,
None,
)
.await?;

View File

@ -220,6 +220,7 @@ async fn inner_extrude(
},
exec_state,
&args,
None,
)
.await?,
);
@ -234,6 +235,7 @@ pub(crate) struct NamedCapTags<'a> {
pub end: Option<&'a TagNode>,
}
#[allow(clippy::too_many_arguments)]
pub(crate) async fn do_post_extrude<'a>(
sketch: &Sketch,
#[cfg(feature = "artifact-graph")] solid_id: ArtifactId,
@ -242,6 +244,7 @@ pub(crate) async fn do_post_extrude<'a>(
named_cap_tags: &'a NamedCapTags<'a>,
exec_state: &mut ExecState,
args: &Args,
edge_id: Option<Uuid>,
) -> Result<Solid, KclError> {
// Bring the object to the front of the scene.
// See: https://github.com/KittyCAD/modeling-app/issues/806
@ -251,7 +254,9 @@ pub(crate) async fn do_post_extrude<'a>(
)
.await?;
let any_edge_id = if let Some(edge_id) = sketch.mirror {
let any_edge_id = if let Some(id) = edge_id {
id
} else if let Some(edge_id) = sketch.mirror {
edge_id
} else {
// The "get extrusion face info" API call requires *any* edge on the sketch being extruded.

View File

@ -187,6 +187,7 @@ async fn inner_loft(
},
exec_state,
&args,
None,
)
.await?,
))

View File

@ -20,6 +20,8 @@ use crate::{
std::{axis_or_reference::Axis2dOrEdgeReference, extrude::do_post_extrude, Args},
};
extern crate nalgebra_glm as glm;
/// Revolve a sketch or set of sketches around an axis.
pub async fn revolve(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let sketches = args.get_unlabeled_kw_arg_typed("sketches", &RuntimeType::sketches(), exec_state)?;
@ -131,8 +133,9 @@ async fn inner_revolve(
let mut solids = Vec::new();
for sketch in &sketches {
let id = exec_state.next_uuid();
let tolerance = tolerance.as_ref().map(|t| t.to_mm()).unwrap_or(DEFAULT_TOLERANCE);
match &axis {
let direction = match &axis {
Axis2dOrEdgeReference::Axis { direction, origin } => {
args.batch_modeling_cmd(
id,
@ -149,12 +152,13 @@ async fn inner_revolve(
y: LengthUnit(origin[1].to_mm()),
z: LengthUnit(0.0),
},
tolerance: LengthUnit(tolerance.as_ref().map(|t| t.to_mm()).unwrap_or(DEFAULT_TOLERANCE)),
tolerance: LengthUnit(tolerance),
axis_is_2d: true,
opposite: opposite.clone(),
}),
)
.await?;
glm::DVec2::new(direction[0].to_mm(), direction[1].to_mm())
}
Axis2dOrEdgeReference::Edge(edge) => {
let edge_id = edge.get_engine_id(exec_state, &args)?;
@ -164,12 +168,29 @@ async fn inner_revolve(
angle,
target: sketch.id.into(),
edge_id,
tolerance: LengthUnit(tolerance.as_ref().map(|t| t.to_mm()).unwrap_or(DEFAULT_TOLERANCE)),
tolerance: LengthUnit(tolerance),
opposite: opposite.clone(),
}),
)
.await?;
//TODO: fix me! Need to be able to calculate this to ensure the path isn't colinear
glm::DVec2::new(0.0, 1.0)
}
};
let mut edge_id = None;
// If an edge lies on the axis of revolution it will not exist after the revolve, so
// it cannot be used to retrieve data about the solid
for path in sketch.paths.clone() {
let from = path.get_from();
let to = path.get_to();
let dir = glm::DVec2::new(to[0].n - from[0].n, to[1].n - from[1].n);
if glm::are_collinear2d(&dir, &direction, tolerance) {
continue;
}
edge_id = Some(path.get_id());
break;
}
solids.push(
@ -185,6 +206,7 @@ async fn inner_revolve(
},
exec_state,
&args,
edge_id,
)
.await?,
);

View File

@ -228,6 +228,7 @@ async fn inner_sweep(
},
exec_state,
&args,
None,
)
.await?,
);