2024-03-05 11:52:45 -08:00
|
|
|
//! Standard library fillets.
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
use derive_docs::stdlib;
|
2024-09-19 14:06:29 -07:00
|
|
|
use kcmc::{
|
|
|
|
each_cmd as mcmd, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, shared::CutType,
|
|
|
|
websocket::OkWebSocketResponseData, ModelingCmd,
|
|
|
|
};
|
2024-09-18 17:04:04 -05:00
|
|
|
use kittycad_modeling_cmds as kcmc;
|
2024-03-05 11:52:45 -08:00
|
|
|
use schemars::JsonSchema;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
use crate::{
|
2024-10-30 16:52:17 -04:00
|
|
|
ast::types::TagNode,
|
2024-03-05 11:52:45 -08:00
|
|
|
errors::{KclError, KclErrorDetails},
|
2024-11-14 17:27:19 -06:00
|
|
|
executor::{EdgeCut, ExecState, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, Solid, TagIdentifier},
|
2024-08-12 21:39:49 -07:00
|
|
|
settings::types::UnitLength,
|
2024-03-05 11:52:45 -08:00
|
|
|
std::Args,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Data for fillets.
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
|
|
|
#[ts(export)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct FilletData {
|
|
|
|
/// The radius of the fillet.
|
|
|
|
pub radius: f64,
|
|
|
|
/// The tags of the paths you want to fillet.
|
2024-03-26 19:07:16 -07:00
|
|
|
pub tags: Vec<EdgeReference>,
|
2024-08-12 21:39:49 -07:00
|
|
|
/// The tolerance for the fillet.
|
|
|
|
#[serde(default)]
|
|
|
|
pub tolerance: Option<f64>,
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
2024-06-24 14:45:07 -07:00
|
|
|
/// A tag or a uuid of an edge.
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Eq, Ord, PartialOrd, Hash)]
|
2024-03-05 11:52:45 -08:00
|
|
|
#[ts(export)]
|
|
|
|
#[serde(untagged)]
|
2024-03-26 19:07:16 -07:00
|
|
|
pub enum EdgeReference {
|
|
|
|
/// A uuid of an edge.
|
|
|
|
Uuid(uuid::Uuid),
|
2024-06-24 14:45:07 -07:00
|
|
|
/// A tag of an edge.
|
2024-07-27 22:56:46 -07:00
|
|
|
Tag(Box<TagIdentifier>),
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
2024-09-25 16:12:18 -07:00
|
|
|
impl EdgeReference {
|
|
|
|
pub fn get_engine_id(&self, exec_state: &mut ExecState, args: &Args) -> Result<uuid::Uuid, KclError> {
|
|
|
|
match self {
|
|
|
|
EdgeReference::Uuid(uuid) => Ok(*uuid),
|
|
|
|
EdgeReference::Tag(tag) => Ok(args.get_tag_engine_info(exec_state, tag)?.id),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 11:52:45 -08:00
|
|
|
/// Create fillets on tagged paths.
|
2024-09-16 15:10:33 -04:00
|
|
|
pub async fn fillet(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
2024-10-30 16:52:17 -04:00
|
|
|
let (data, solid, tag): (FilletData, Box<Solid>, Option<TagNode>) = args.get_data_and_solid_and_tag()?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-09-27 15:44:44 -07:00
|
|
|
let solid = inner_fillet(data, solid, tag, exec_state, args).await?;
|
|
|
|
Ok(KclValue::Solid(solid))
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
2024-08-06 20:27:26 -04:00
|
|
|
/// Blend a transitional edge along a tagged path, smoothing the sharp edge.
|
|
|
|
///
|
|
|
|
/// Fillet is similar in function and use to a chamfer, except
|
|
|
|
/// a chamfer will cut a sharp transition along an edge while fillet
|
|
|
|
/// will smoothly blend the transition.
|
2024-03-13 12:56:46 -07:00
|
|
|
///
|
|
|
|
/// ```no_run
|
2024-05-14 17:10:47 -07:00
|
|
|
/// const width = 20
|
|
|
|
/// const length = 10
|
|
|
|
/// const thickness = 1
|
|
|
|
/// const filletRadius = 2
|
|
|
|
///
|
|
|
|
/// const mountingPlateSketch = startSketchOn("XY")
|
|
|
|
/// |> startProfileAt([-width/2, -length/2], %)
|
2024-07-27 17:59:41 -07:00
|
|
|
/// |> lineTo([width/2, -length/2], %, $edge1)
|
|
|
|
/// |> lineTo([width/2, length/2], %, $edge2)
|
|
|
|
/// |> lineTo([-width/2, length/2], %, $edge3)
|
|
|
|
/// |> close(%, $edge4)
|
2024-05-14 17:10:47 -07:00
|
|
|
///
|
|
|
|
/// const mountingPlate = extrude(thickness, mountingPlateSketch)
|
|
|
|
/// |> fillet({
|
|
|
|
/// radius: filletRadius,
|
|
|
|
/// tags: [
|
2024-07-27 22:56:46 -07:00
|
|
|
/// getNextAdjacentEdge(edge1),
|
|
|
|
/// getNextAdjacentEdge(edge2),
|
|
|
|
/// getNextAdjacentEdge(edge3),
|
|
|
|
/// getNextAdjacentEdge(edge4)
|
2024-05-14 17:10:47 -07:00
|
|
|
/// ],
|
|
|
|
/// }, %)
|
2024-03-13 12:56:46 -07:00
|
|
|
/// ```
|
2024-08-12 21:39:49 -07:00
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// const width = 20
|
|
|
|
/// const length = 10
|
|
|
|
/// const thickness = 1
|
|
|
|
/// const filletRadius = 1
|
|
|
|
///
|
|
|
|
/// const mountingPlateSketch = startSketchOn("XY")
|
|
|
|
/// |> startProfileAt([-width/2, -length/2], %)
|
|
|
|
/// |> lineTo([width/2, -length/2], %, $edge1)
|
|
|
|
/// |> lineTo([width/2, length/2], %, $edge2)
|
|
|
|
/// |> lineTo([-width/2, length/2], %, $edge3)
|
|
|
|
/// |> close(%, $edge4)
|
|
|
|
///
|
|
|
|
/// const mountingPlate = extrude(thickness, mountingPlateSketch)
|
|
|
|
/// |> fillet({
|
|
|
|
/// radius: filletRadius,
|
|
|
|
/// tolerance: 0.000001,
|
|
|
|
/// tags: [
|
|
|
|
/// getNextAdjacentEdge(edge1),
|
|
|
|
/// getNextAdjacentEdge(edge2),
|
|
|
|
/// getNextAdjacentEdge(edge3),
|
|
|
|
/// getNextAdjacentEdge(edge4)
|
|
|
|
/// ],
|
|
|
|
/// }, %)
|
|
|
|
/// ```
|
2024-03-05 11:52:45 -08:00
|
|
|
#[stdlib {
|
|
|
|
name = "fillet",
|
|
|
|
}]
|
|
|
|
async fn inner_fillet(
|
|
|
|
data: FilletData,
|
2024-09-27 15:44:44 -07:00
|
|
|
solid: Box<Solid>,
|
2024-10-30 16:52:17 -04:00
|
|
|
tag: Option<TagNode>,
|
2024-09-16 15:10:33 -04:00
|
|
|
exec_state: &mut ExecState,
|
2024-03-05 11:52:45 -08:00
|
|
|
args: Args,
|
2024-09-27 15:44:44 -07:00
|
|
|
) -> Result<Box<Solid>, KclError> {
|
2024-03-05 11:52:45 -08:00
|
|
|
// Check if tags contains any duplicate values.
|
|
|
|
let mut tags = data.tags.clone();
|
|
|
|
tags.sort();
|
|
|
|
tags.dedup();
|
|
|
|
if tags.len() != data.tags.len() {
|
|
|
|
return Err(KclError::Type(KclErrorDetails {
|
|
|
|
message: "Duplicate tags are not allowed.".to_string(),
|
|
|
|
source_ranges: vec![args.source_range],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2024-09-27 15:44:44 -07:00
|
|
|
let mut solid = solid.clone();
|
2024-07-28 00:30:04 -07:00
|
|
|
for edge_tag in data.tags {
|
2024-09-25 16:12:18 -07:00
|
|
|
let edge_id = edge_tag.get_engine_id(exec_state, &args)?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-10-09 19:38:40 -04:00
|
|
|
let id = exec_state.id_generator.next_uuid();
|
2024-06-22 14:31:37 -07:00
|
|
|
args.batch_end_cmd(
|
2024-06-23 19:19:24 -07:00
|
|
|
id,
|
2024-09-18 17:04:04 -05:00
|
|
|
ModelingCmd::from(mcmd::Solid3dFilletEdge {
|
2024-03-05 11:52:45 -08:00
|
|
|
edge_id,
|
2024-09-27 15:44:44 -07:00
|
|
|
object_id: solid.id,
|
2024-09-18 17:04:04 -05:00
|
|
|
radius: LengthUnit(data.radius),
|
|
|
|
tolerance: LengthUnit(data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units))),
|
|
|
|
cut_type: CutType::Fillet,
|
2024-09-19 14:06:29 -07:00
|
|
|
// We pass in the command id as the face id.
|
|
|
|
// So the resulting face of the fillet will be the same.
|
|
|
|
// This is because that's how most other endpoints work.
|
|
|
|
face_id: Some(id),
|
2024-09-18 17:04:04 -05:00
|
|
|
}),
|
2024-03-05 11:52:45 -08:00
|
|
|
)
|
|
|
|
.await?;
|
2024-06-23 19:19:24 -07:00
|
|
|
|
2024-09-27 15:44:44 -07:00
|
|
|
solid.edge_cuts.push(EdgeCut::Fillet {
|
2024-06-23 19:19:24 -07:00
|
|
|
id,
|
|
|
|
edge_id,
|
|
|
|
radius: data.radius,
|
2024-07-28 00:30:04 -07:00
|
|
|
tag: Box::new(tag.clone()),
|
2024-06-23 19:19:24 -07:00
|
|
|
});
|
2024-07-28 00:30:04 -07:00
|
|
|
|
|
|
|
if let Some(ref tag) = tag {
|
2024-09-27 15:44:44 -07:00
|
|
|
solid.value.push(ExtrudeSurface::Fillet(FilletSurface {
|
2024-09-19 14:06:29 -07:00
|
|
|
face_id: id,
|
2024-07-28 00:30:04 -07:00
|
|
|
tag: Some(tag.clone()),
|
|
|
|
geo_meta: GeoMeta {
|
|
|
|
id,
|
|
|
|
metadata: args.source_range.into(),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
2024-09-27 15:44:44 -07:00
|
|
|
Ok(solid)
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the opposite edge to the edge given.
|
2024-09-16 15:10:33 -04:00
|
|
|
pub async fn get_opposite_edge(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
2024-07-27 22:56:46 -07:00
|
|
|
let tag: TagIdentifier = args.get_data()?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-09-16 15:10:33 -04:00
|
|
|
let edge = inner_get_opposite_edge(tag, exec_state, args.clone()).await?;
|
2024-11-14 17:27:19 -06:00
|
|
|
Ok(KclValue::Uuid {
|
|
|
|
value: edge,
|
2024-03-05 11:52:45 -08:00
|
|
|
meta: vec![args.source_range.into()],
|
2024-11-14 17:27:19 -06:00
|
|
|
})
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the opposite edge to the edge given.
|
2024-03-13 12:56:46 -07:00
|
|
|
///
|
|
|
|
/// ```no_run
|
2024-05-14 17:10:47 -07:00
|
|
|
/// const exampleSketch = startSketchOn('XZ')
|
|
|
|
/// |> startProfileAt([0, 0], %)
|
|
|
|
/// |> line([10, 0], %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 60,
|
|
|
|
/// length: 10,
|
|
|
|
/// }, %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 120,
|
|
|
|
/// length: 10,
|
|
|
|
/// }, %)
|
|
|
|
/// |> line([-10, 0], %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 240,
|
|
|
|
/// length: 10,
|
2024-07-27 17:59:41 -07:00
|
|
|
/// }, %, $referenceEdge)
|
2024-05-14 17:10:47 -07:00
|
|
|
/// |> close(%)
|
|
|
|
///
|
|
|
|
/// const example = extrude(5, exampleSketch)
|
|
|
|
/// |> fillet({
|
|
|
|
/// radius: 3,
|
2024-07-27 22:56:46 -07:00
|
|
|
/// tags: [getOppositeEdge(referenceEdge)],
|
2024-05-14 17:10:47 -07:00
|
|
|
/// }, %)
|
2024-03-13 12:56:46 -07:00
|
|
|
/// ```
|
2024-03-05 11:52:45 -08:00
|
|
|
#[stdlib {
|
|
|
|
name = "getOppositeEdge",
|
|
|
|
}]
|
2024-09-16 15:10:33 -04:00
|
|
|
async fn inner_get_opposite_edge(tag: TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<Uuid, KclError> {
|
2024-10-01 12:45:01 -07:00
|
|
|
if args.ctx.is_mock() {
|
2024-10-09 19:38:40 -04:00
|
|
|
return Ok(exec_state.id_generator.next_uuid());
|
2024-05-15 18:38:30 +10:00
|
|
|
}
|
2024-09-16 15:10:33 -04:00
|
|
|
let face_id = args.get_adjacent_face_to_tag(exec_state, &tag, false).await?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-10-09 19:38:40 -04:00
|
|
|
let id = exec_state.id_generator.next_uuid();
|
2024-09-16 15:10:33 -04:00
|
|
|
let tagged_path = args.get_tag_engine_info(exec_state, &tag)?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
|
|
|
let resp = args
|
|
|
|
.send_modeling_cmd(
|
2024-10-09 19:38:40 -04:00
|
|
|
id,
|
2024-09-18 17:04:04 -05:00
|
|
|
ModelingCmd::from(mcmd::Solid3dGetOppositeEdge {
|
2024-07-27 22:56:46 -07:00
|
|
|
edge_id: tagged_path.id,
|
2024-09-27 15:44:44 -07:00
|
|
|
object_id: tagged_path.sketch,
|
2024-03-05 11:52:45 -08:00
|
|
|
face_id,
|
2024-09-18 17:04:04 -05:00
|
|
|
}),
|
2024-03-05 11:52:45 -08:00
|
|
|
)
|
|
|
|
.await?;
|
2024-09-18 17:04:04 -05:00
|
|
|
let OkWebSocketResponseData::Modeling {
|
|
|
|
modeling_response: OkModelingCmdResponse::Solid3dGetOppositeEdge(opposite_edge),
|
2024-03-05 11:52:45 -08:00
|
|
|
} = &resp
|
|
|
|
else {
|
|
|
|
return Err(KclError::Engine(KclErrorDetails {
|
2024-09-18 17:04:04 -05:00
|
|
|
message: format!("mcmd::Solid3dGetOppositeEdge response was not as expected: {:?}", resp),
|
2024-03-05 11:52:45 -08:00
|
|
|
source_ranges: vec![args.source_range],
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(opposite_edge.edge)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the next adjacent edge to the edge given.
|
2024-09-16 15:10:33 -04:00
|
|
|
pub async fn get_next_adjacent_edge(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
2024-07-27 22:56:46 -07:00
|
|
|
let tag: TagIdentifier = args.get_data()?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-09-16 15:10:33 -04:00
|
|
|
let edge = inner_get_next_adjacent_edge(tag, exec_state, args.clone()).await?;
|
2024-11-14 17:27:19 -06:00
|
|
|
Ok(KclValue::Uuid {
|
|
|
|
value: edge,
|
2024-03-05 11:52:45 -08:00
|
|
|
meta: vec![args.source_range.into()],
|
2024-11-14 17:27:19 -06:00
|
|
|
})
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the next adjacent edge to the edge given.
|
2024-03-13 12:56:46 -07:00
|
|
|
///
|
|
|
|
/// ```no_run
|
2024-05-14 17:10:47 -07:00
|
|
|
/// const exampleSketch = startSketchOn('XZ')
|
|
|
|
/// |> startProfileAt([0, 0], %)
|
|
|
|
/// |> line([10, 0], %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 60,
|
|
|
|
/// length: 10,
|
|
|
|
/// }, %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 120,
|
|
|
|
/// length: 10,
|
|
|
|
/// }, %)
|
|
|
|
/// |> line([-10, 0], %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 240,
|
|
|
|
/// length: 10,
|
2024-07-27 17:59:41 -07:00
|
|
|
/// }, %, $referenceEdge)
|
2024-05-14 17:10:47 -07:00
|
|
|
/// |> close(%)
|
|
|
|
///
|
|
|
|
/// const example = extrude(5, exampleSketch)
|
|
|
|
/// |> fillet({
|
|
|
|
/// radius: 3,
|
2024-07-27 22:56:46 -07:00
|
|
|
/// tags: [getNextAdjacentEdge(referenceEdge)],
|
2024-05-14 17:10:47 -07:00
|
|
|
/// }, %)
|
2024-03-13 12:56:46 -07:00
|
|
|
/// ```
|
2024-03-05 11:52:45 -08:00
|
|
|
#[stdlib {
|
|
|
|
name = "getNextAdjacentEdge",
|
|
|
|
}]
|
2024-09-16 15:10:33 -04:00
|
|
|
async fn inner_get_next_adjacent_edge(
|
|
|
|
tag: TagIdentifier,
|
|
|
|
exec_state: &mut ExecState,
|
|
|
|
args: Args,
|
|
|
|
) -> Result<Uuid, KclError> {
|
2024-10-01 12:45:01 -07:00
|
|
|
if args.ctx.is_mock() {
|
2024-10-09 19:38:40 -04:00
|
|
|
return Ok(exec_state.id_generator.next_uuid());
|
2024-05-15 18:38:30 +10:00
|
|
|
}
|
2024-09-16 15:10:33 -04:00
|
|
|
let face_id = args.get_adjacent_face_to_tag(exec_state, &tag, false).await?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-10-09 19:38:40 -04:00
|
|
|
let id = exec_state.id_generator.next_uuid();
|
2024-09-16 15:10:33 -04:00
|
|
|
let tagged_path = args.get_tag_engine_info(exec_state, &tag)?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
|
|
|
let resp = args
|
|
|
|
.send_modeling_cmd(
|
2024-10-09 19:38:40 -04:00
|
|
|
id,
|
2024-09-18 17:04:04 -05:00
|
|
|
ModelingCmd::from(mcmd::Solid3dGetNextAdjacentEdge {
|
2024-07-27 22:56:46 -07:00
|
|
|
edge_id: tagged_path.id,
|
2024-09-27 15:44:44 -07:00
|
|
|
object_id: tagged_path.sketch,
|
2024-03-05 11:52:45 -08:00
|
|
|
face_id,
|
2024-09-18 17:04:04 -05:00
|
|
|
}),
|
2024-03-05 11:52:45 -08:00
|
|
|
)
|
|
|
|
.await?;
|
2024-09-18 17:04:04 -05:00
|
|
|
let OkWebSocketResponseData::Modeling {
|
|
|
|
modeling_response: OkModelingCmdResponse::Solid3dGetNextAdjacentEdge(adjacent_edge),
|
2024-03-05 11:52:45 -08:00
|
|
|
} = &resp
|
|
|
|
else {
|
|
|
|
return Err(KclError::Engine(KclErrorDetails {
|
2024-09-18 17:04:04 -05:00
|
|
|
message: format!(
|
|
|
|
"mcmd::Solid3dGetNextAdjacentEdge response was not as expected: {:?}",
|
|
|
|
resp
|
|
|
|
),
|
2024-03-05 11:52:45 -08:00
|
|
|
source_ranges: vec![args.source_range],
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2024-09-18 17:04:04 -05:00
|
|
|
adjacent_edge.edge.ok_or_else(|| {
|
2024-03-05 11:52:45 -08:00
|
|
|
KclError::Type(KclErrorDetails {
|
2024-06-24 14:45:07 -07:00
|
|
|
message: format!("No edge found next adjacent to tag: `{}`", tag.value),
|
2024-03-05 11:52:45 -08:00
|
|
|
source_ranges: vec![args.source_range],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the previous adjacent edge to the edge given.
|
2024-09-16 15:10:33 -04:00
|
|
|
pub async fn get_previous_adjacent_edge(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
2024-07-27 22:56:46 -07:00
|
|
|
let tag: TagIdentifier = args.get_data()?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-09-16 15:10:33 -04:00
|
|
|
let edge = inner_get_previous_adjacent_edge(tag, exec_state, args.clone()).await?;
|
2024-11-14 17:27:19 -06:00
|
|
|
Ok(KclValue::Uuid {
|
|
|
|
value: edge,
|
2024-03-05 11:52:45 -08:00
|
|
|
meta: vec![args.source_range.into()],
|
2024-11-14 17:27:19 -06:00
|
|
|
})
|
2024-03-05 11:52:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the previous adjacent edge to the edge given.
|
2024-03-13 12:56:46 -07:00
|
|
|
///
|
|
|
|
/// ```no_run
|
2024-05-14 17:10:47 -07:00
|
|
|
/// const exampleSketch = startSketchOn('XZ')
|
|
|
|
/// |> startProfileAt([0, 0], %)
|
|
|
|
/// |> line([10, 0], %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 60,
|
|
|
|
/// length: 10,
|
|
|
|
/// }, %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 120,
|
|
|
|
/// length: 10,
|
|
|
|
/// }, %)
|
|
|
|
/// |> line([-10, 0], %)
|
|
|
|
/// |> angledLine({
|
|
|
|
/// angle: 240,
|
|
|
|
/// length: 10,
|
2024-07-27 17:59:41 -07:00
|
|
|
/// }, %, $referenceEdge)
|
2024-05-14 17:10:47 -07:00
|
|
|
/// |> close(%)
|
|
|
|
///
|
|
|
|
/// const example = extrude(5, exampleSketch)
|
|
|
|
/// |> fillet({
|
|
|
|
/// radius: 3,
|
2024-07-27 22:56:46 -07:00
|
|
|
/// tags: [getPreviousAdjacentEdge(referenceEdge)],
|
2024-05-14 17:10:47 -07:00
|
|
|
/// }, %)
|
2024-03-13 12:56:46 -07:00
|
|
|
/// ```
|
2024-03-05 11:52:45 -08:00
|
|
|
#[stdlib {
|
|
|
|
name = "getPreviousAdjacentEdge",
|
|
|
|
}]
|
2024-09-16 15:10:33 -04:00
|
|
|
async fn inner_get_previous_adjacent_edge(
|
|
|
|
tag: TagIdentifier,
|
|
|
|
exec_state: &mut ExecState,
|
|
|
|
args: Args,
|
|
|
|
) -> Result<Uuid, KclError> {
|
2024-10-01 12:45:01 -07:00
|
|
|
if args.ctx.is_mock() {
|
2024-10-09 19:38:40 -04:00
|
|
|
return Ok(exec_state.id_generator.next_uuid());
|
2024-05-15 18:38:30 +10:00
|
|
|
}
|
2024-09-16 15:10:33 -04:00
|
|
|
let face_id = args.get_adjacent_face_to_tag(exec_state, &tag, false).await?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
2024-10-09 19:38:40 -04:00
|
|
|
let id = exec_state.id_generator.next_uuid();
|
2024-09-16 15:10:33 -04:00
|
|
|
let tagged_path = args.get_tag_engine_info(exec_state, &tag)?;
|
2024-03-05 11:52:45 -08:00
|
|
|
|
|
|
|
let resp = args
|
|
|
|
.send_modeling_cmd(
|
2024-10-09 19:38:40 -04:00
|
|
|
id,
|
2024-09-18 17:04:04 -05:00
|
|
|
ModelingCmd::from(mcmd::Solid3dGetPrevAdjacentEdge {
|
2024-07-27 22:56:46 -07:00
|
|
|
edge_id: tagged_path.id,
|
2024-09-27 15:44:44 -07:00
|
|
|
object_id: tagged_path.sketch,
|
2024-03-05 11:52:45 -08:00
|
|
|
face_id,
|
2024-09-18 17:04:04 -05:00
|
|
|
}),
|
2024-03-05 11:52:45 -08:00
|
|
|
)
|
|
|
|
.await?;
|
2024-09-18 17:04:04 -05:00
|
|
|
let OkWebSocketResponseData::Modeling {
|
|
|
|
modeling_response: OkModelingCmdResponse::Solid3dGetPrevAdjacentEdge(adjacent_edge),
|
2024-03-05 11:52:45 -08:00
|
|
|
} = &resp
|
|
|
|
else {
|
|
|
|
return Err(KclError::Engine(KclErrorDetails {
|
2024-09-18 17:04:04 -05:00
|
|
|
message: format!(
|
|
|
|
"mcmd::Solid3dGetPrevAdjacentEdge response was not as expected: {:?}",
|
|
|
|
resp
|
|
|
|
),
|
2024-03-05 11:52:45 -08:00
|
|
|
source_ranges: vec![args.source_range],
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2024-09-18 17:04:04 -05:00
|
|
|
adjacent_edge.edge.ok_or_else(|| {
|
2024-03-05 11:52:45 -08:00
|
|
|
KclError::Type(KclErrorDetails {
|
2024-06-24 14:45:07 -07:00
|
|
|
message: format!("No edge found previous adjacent to tag: `{}`", tag.value),
|
2024-03-05 11:52:45 -08:00
|
|
|
source_ranges: vec![args.source_range],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2024-08-12 21:39:49 -07:00
|
|
|
|
|
|
|
pub(crate) fn default_tolerance(units: &UnitLength) -> f64 {
|
|
|
|
match units {
|
|
|
|
UnitLength::Mm => 0.0000001,
|
|
|
|
UnitLength::Cm => 0.0000001,
|
|
|
|
UnitLength::In => 0.0000001,
|
|
|
|
UnitLength::Ft => 0.0001,
|
|
|
|
UnitLength::Yd => 0.001,
|
|
|
|
UnitLength::M => 0.001,
|
|
|
|
}
|
|
|
|
}
|