ability to set tolerances, but with sane defaults (#3397)
* allow for setting of tolerances Signed-off-by: Jess Frazelle <github@jessfraz.com> * autocomplete fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix inches default Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
@ -92895,6 +92895,13 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tolerance": {
|
||||||
|
"description": "The tolerance for the fillet.",
|
||||||
|
"default": null,
|
||||||
|
"type": "number",
|
||||||
|
"format": "double",
|
||||||
|
"nullable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -98094,7 +98101,8 @@
|
|||||||
"unpublished": false,
|
"unpublished": false,
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
"examples": [
|
"examples": [
|
||||||
"const width = 20\nconst length = 10\nconst thickness = 1\nconst filletRadius = 2\n\nconst mountingPlateSketch = startSketchOn(\"XY\")\n |> startProfileAt([-width / 2, -length / 2], %)\n |> lineTo([width / 2, -length / 2], %, $edge1)\n |> lineTo([width / 2, length / 2], %, $edge2)\n |> lineTo([-width / 2, length / 2], %, $edge3)\n |> close(%, $edge4)\n\nconst mountingPlate = extrude(thickness, mountingPlateSketch)\n |> fillet({\n radius: filletRadius,\n tags: [\n getNextAdjacentEdge(edge1),\n getNextAdjacentEdge(edge2),\n getNextAdjacentEdge(edge3),\n getNextAdjacentEdge(edge4)\n ]\n }, %)"
|
"const width = 20\nconst length = 10\nconst thickness = 1\nconst filletRadius = 2\n\nconst mountingPlateSketch = startSketchOn(\"XY\")\n |> startProfileAt([-width / 2, -length / 2], %)\n |> lineTo([width / 2, -length / 2], %, $edge1)\n |> lineTo([width / 2, length / 2], %, $edge2)\n |> lineTo([-width / 2, length / 2], %, $edge3)\n |> close(%, $edge4)\n\nconst mountingPlate = extrude(thickness, mountingPlateSketch)\n |> fillet({\n radius: filletRadius,\n tags: [\n getNextAdjacentEdge(edge1),\n getNextAdjacentEdge(edge2),\n getNextAdjacentEdge(edge3),\n getNextAdjacentEdge(edge4)\n ]\n }, %)",
|
||||||
|
"const width = 20\nconst length = 10\nconst thickness = 1\nconst filletRadius = 1\n\nconst mountingPlateSketch = startSketchOn(\"XY\")\n |> startProfileAt([-width / 2, -length / 2], %)\n |> lineTo([width / 2, -length / 2], %, $edge1)\n |> lineTo([width / 2, length / 2], %, $edge2)\n |> lineTo([-width / 2, length / 2], %, $edge3)\n |> close(%, $edge4)\n\nconst mountingPlate = extrude(thickness, mountingPlateSketch)\n |> fillet({\n radius: filletRadius,\n tolerance: 0.000001,\n tags: [\n getNextAdjacentEdge(edge1),\n getNextAdjacentEdge(edge2),\n getNextAdjacentEdge(edge3),\n getNextAdjacentEdge(edge4)\n ]\n }, %)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -184059,6 +184067,13 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"tolerance": {
|
||||||
|
"description": "Tolerance for the revolve operation.",
|
||||||
|
"default": null,
|
||||||
|
"type": "number",
|
||||||
|
"format": "double",
|
||||||
|
"nullable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -189967,6 +189982,7 @@
|
|||||||
"const part001 = startSketchOn('XY')\n |> startProfileAt([4, 12], %)\n |> line([2, 0], %)\n |> line([0, -6], %)\n |> line([4, -6], %)\n |> line([0, -6], %)\n |> line([-3.75, -4.5], %)\n |> line([0, -5.5], %)\n |> line([-2, 0], %)\n |> close(%)\n |> revolve({ axis: 'y', angle: 180 }, %)\nconst part002 = startSketchOn(part001, 'end')\n |> startProfileAt([4.5, -5], %)\n |> line([0, 5], %)\n |> line([5, 0], %)\n |> line([0, -5], %)\n |> close(%)\n |> extrude(5, %)",
|
"const part001 = startSketchOn('XY')\n |> startProfileAt([4, 12], %)\n |> line([2, 0], %)\n |> line([0, -6], %)\n |> line([4, -6], %)\n |> line([0, -6], %)\n |> line([-3.75, -4.5], %)\n |> line([0, -5.5], %)\n |> line([-2, 0], %)\n |> close(%)\n |> revolve({ axis: 'y', angle: 180 }, %)\nconst part002 = startSketchOn(part001, 'end')\n |> startProfileAt([4.5, -5], %)\n |> line([0, 5], %)\n |> line([5, 0], %)\n |> line([0, -5], %)\n |> close(%)\n |> extrude(5, %)",
|
||||||
"const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 20], %)\n |> line([20, 0], %)\n |> line([0, -20], %)\n |> close(%)\n |> extrude(20, %)\n\nconst sketch001 = startSketchOn(box, \"END\")\n |> circle([10, 10], 4, %)\n |> revolve({ angle: -90, axis: 'y' }, %)",
|
"const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 20], %)\n |> line([20, 0], %)\n |> line([0, -20], %)\n |> close(%)\n |> extrude(20, %)\n\nconst sketch001 = startSketchOn(box, \"END\")\n |> circle([10, 10], 4, %)\n |> revolve({ angle: -90, axis: 'y' }, %)",
|
||||||
"const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 20], %)\n |> line([20, 0], %)\n |> line([0, -20], %, $revolveAxis)\n |> close(%)\n |> extrude(20, %)\n\nconst sketch001 = startSketchOn(box, \"END\")\n |> circle([10, 10], 4, %)\n |> revolve({\n angle: 90,\n axis: getOppositeEdge(revolveAxis)\n }, %)",
|
"const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 20], %)\n |> line([20, 0], %)\n |> line([0, -20], %, $revolveAxis)\n |> close(%)\n |> extrude(20, %)\n\nconst sketch001 = startSketchOn(box, \"END\")\n |> circle([10, 10], 4, %)\n |> revolve({\n angle: 90,\n axis: getOppositeEdge(revolveAxis)\n }, %)",
|
||||||
|
"const box = startSketchOn('XY')\n |> startProfileAt([0, 0], %)\n |> line([0, 20], %)\n |> line([20, 0], %)\n |> line([0, -20], %, $revolveAxis)\n |> close(%)\n |> extrude(20, %)\n\nconst sketch001 = startSketchOn(box, \"END\")\n |> circle([10, 10], 4, %)\n |> revolve({\n angle: 90,\n axis: getOppositeEdge(revolveAxis),\n tolerance: 0.0001\n }, %)",
|
||||||
"const sketch001 = startSketchOn('XY')\n |> startProfileAt([10, 0], %)\n |> line([5, -5], %)\n |> line([5, 5], %)\n |> lineTo([profileStartX(%), profileStartY(%)], %)\n |> close(%)\n\nconst part001 = revolve({\n axis: {\n custom: {\n axis: [0.0, 1.0, 0.0],\n origin: [0.0, 0.0, 0.0]\n }\n }\n}, sketch001)"
|
"const sketch001 = startSketchOn('XY')\n |> startProfileAt([10, 0], %)\n |> line([5, -5], %)\n |> line([5, 5], %)\n |> lineTo([profileStartX(%), profileStartY(%)], %)\n |> close(%)\n\nconst part001 = revolve({\n axis: {\n custom: {\n axis: [0.0, 1.0, 0.0],\n origin: [0.0, 0.0, 0.0]\n }\n }\n}, sketch001)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -513,19 +513,27 @@ pub fn get_autocomplete_snippet_from_schema(
|
|||||||
let mut fn_docs = String::new();
|
let mut fn_docs = String::new();
|
||||||
fn_docs.push_str("{\n");
|
fn_docs.push_str("{\n");
|
||||||
// Let's print out the object's properties.
|
// Let's print out the object's properties.
|
||||||
for (i, (prop_name, prop)) in obj_val.properties.iter().enumerate() {
|
let mut i = 0;
|
||||||
|
for (prop_name, prop) in obj_val.properties.iter() {
|
||||||
if prop_name.starts_with('_') {
|
if prop_name.starts_with('_') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tolerance is a an optional property that we don't want to show in the
|
||||||
|
// autocomplete, since it is mostly for advanced users.
|
||||||
|
if prop_name == "tolerance" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some((_, snippet)) = get_autocomplete_snippet_from_schema(prop, index + i)? {
|
if let Some((_, snippet)) = get_autocomplete_snippet_from_schema(prop, index + i)? {
|
||||||
fn_docs.push_str(&format!("\t{}: {},\n", prop_name, snippet));
|
fn_docs.push_str(&format!("\t{}: {},\n", prop_name, snippet));
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_docs.push('}');
|
fn_docs.push('}');
|
||||||
|
|
||||||
return Ok(Some((index + obj_val.properties.len() - 1, fn_docs)));
|
return Ok(Some((index + i - 1, fn_docs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(array_val) = &o.array {
|
if let Some(array_val) = &o.array {
|
||||||
@ -902,8 +910,8 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
snippet,
|
snippet,
|
||||||
r#"revolve({
|
r#"revolve({
|
||||||
axis: ${1:"X"},
|
axis: ${0:"X"},
|
||||||
}, ${2:%})${}"#
|
}, ${1:%})${}"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,11 +11,10 @@ use crate::{
|
|||||||
ast::types::TagDeclarator,
|
ast::types::TagDeclarator,
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
executor::{EdgeCut, ExtrudeGroup, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, TagIdentifier, UserVal},
|
executor::{EdgeCut, ExtrudeGroup, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, TagIdentifier, UserVal},
|
||||||
|
settings::types::UnitLength,
|
||||||
std::Args,
|
std::Args,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) const DEFAULT_TOLERANCE: f64 = 0.0000001;
|
|
||||||
|
|
||||||
/// Data for fillets.
|
/// Data for fillets.
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
@ -25,6 +24,9 @@ pub struct FilletData {
|
|||||||
pub radius: f64,
|
pub radius: f64,
|
||||||
/// The tags of the paths you want to fillet.
|
/// The tags of the paths you want to fillet.
|
||||||
pub tags: Vec<EdgeReference>,
|
pub tags: Vec<EdgeReference>,
|
||||||
|
/// The tolerance for the fillet.
|
||||||
|
#[serde(default)]
|
||||||
|
pub tolerance: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A tag or a uuid of an edge.
|
/// A tag or a uuid of an edge.
|
||||||
@ -77,6 +79,32 @@ pub async fn fillet(args: Args) -> Result<KclValue, KclError> {
|
|||||||
/// ],
|
/// ],
|
||||||
/// }, %)
|
/// }, %)
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```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)
|
||||||
|
/// ],
|
||||||
|
/// }, %)
|
||||||
|
/// ```
|
||||||
#[stdlib {
|
#[stdlib {
|
||||||
name = "fillet",
|
name = "fillet",
|
||||||
}]
|
}]
|
||||||
@ -112,7 +140,7 @@ async fn inner_fillet(
|
|||||||
edge_id,
|
edge_id,
|
||||||
object_id: extrude_group.id,
|
object_id: extrude_group.id,
|
||||||
radius: data.radius,
|
radius: data.radius,
|
||||||
tolerance: DEFAULT_TOLERANCE, // We can let the user set this in the future.
|
tolerance: data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units)),
|
||||||
cut_type: Some(kittycad::types::CutType::Fillet),
|
cut_type: Some(kittycad::types::CutType::Fillet),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -382,3 +410,14 @@ async fn inner_get_previous_adjacent_edge(tag: TagIdentifier, args: Args) -> Res
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,7 +11,7 @@ use crate::{
|
|||||||
executor::{ExtrudeGroup, KclValue, SketchGroup},
|
executor::{ExtrudeGroup, KclValue, SketchGroup},
|
||||||
std::{
|
std::{
|
||||||
extrude::do_post_extrude,
|
extrude::do_post_extrude,
|
||||||
fillet::{EdgeReference, DEFAULT_TOLERANCE},
|
fillet::{default_tolerance, EdgeReference},
|
||||||
Args,
|
Args,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -25,6 +25,9 @@ pub struct RevolveData {
|
|||||||
pub angle: Option<f64>,
|
pub angle: Option<f64>,
|
||||||
/// Axis of revolution.
|
/// Axis of revolution.
|
||||||
pub axis: RevolveAxis,
|
pub axis: RevolveAxis,
|
||||||
|
/// Tolerance for the revolve operation.
|
||||||
|
#[serde(default)]
|
||||||
|
pub tolerance: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Axis of revolution or tagged edge.
|
/// Axis of revolution or tagged edge.
|
||||||
@ -207,6 +210,24 @@ pub async fn revolve(args: Args) -> Result<KclValue, KclError> {
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
|
/// const box = startSketchOn('XY')
|
||||||
|
/// |> startProfileAt([0, 0], %)
|
||||||
|
/// |> line([0, 20], %)
|
||||||
|
/// |> line([20, 0], %)
|
||||||
|
/// |> line([0, -20], %, $revolveAxis)
|
||||||
|
/// |> close(%)
|
||||||
|
/// |> extrude(20, %)
|
||||||
|
///
|
||||||
|
/// const sketch001 = startSketchOn(box, "END")
|
||||||
|
/// |> circle([10,10], 4, %)
|
||||||
|
/// |> revolve({
|
||||||
|
/// angle: 90,
|
||||||
|
/// axis: getOppositeEdge(revolveAxis),
|
||||||
|
/// tolerance: 0.0001
|
||||||
|
/// }, %)
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
/// const sketch001 = startSketchOn('XY')
|
/// const sketch001 = startSketchOn('XY')
|
||||||
/// |> startProfileAt([10, 0], %)
|
/// |> startProfileAt([10, 0], %)
|
||||||
/// |> line([5, -5], %)
|
/// |> line([5, -5], %)
|
||||||
@ -254,7 +275,7 @@ async fn inner_revolve(
|
|||||||
target: sketch_group.id,
|
target: sketch_group.id,
|
||||||
axis,
|
axis,
|
||||||
origin,
|
origin,
|
||||||
tolerance: DEFAULT_TOLERANCE,
|
tolerance: data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units)),
|
||||||
axis_is_2d: true,
|
axis_is_2d: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -271,7 +292,7 @@ async fn inner_revolve(
|
|||||||
angle,
|
angle,
|
||||||
target: sketch_group.id,
|
target: sketch_group.id,
|
||||||
edge_id,
|
edge_id,
|
||||||
tolerance: DEFAULT_TOLERANCE,
|
tolerance: data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units)),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 77 KiB |
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 81 KiB |
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 130 KiB |
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 122 KiB |
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 121 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 105 KiB |
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 122 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 142 KiB |
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 122 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 129 KiB |
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 139 KiB |