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>
@ -513,19 +513,27 @@ pub fn get_autocomplete_snippet_from_schema(
|
||||
let mut fn_docs = String::new();
|
||||
fn_docs.push_str("{\n");
|
||||
// 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('_') {
|
||||
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)? {
|
||||
fn_docs.push_str(&format!("\t{}: {},\n", prop_name, snippet));
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -902,8 +910,8 @@ mod tests {
|
||||
assert_eq!(
|
||||
snippet,
|
||||
r#"revolve({
|
||||
axis: ${1:"X"},
|
||||
}, ${2:%})${}"#
|
||||
axis: ${0:"X"},
|
||||
}, ${1:%})${}"#
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -11,11 +11,10 @@ use crate::{
|
||||
ast::types::TagDeclarator,
|
||||
errors::{KclError, KclErrorDetails},
|
||||
executor::{EdgeCut, ExtrudeGroup, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, TagIdentifier, UserVal},
|
||||
settings::types::UnitLength,
|
||||
std::Args,
|
||||
};
|
||||
|
||||
pub(crate) const DEFAULT_TOLERANCE: f64 = 0.0000001;
|
||||
|
||||
/// Data for fillets.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
@ -25,6 +24,9 @@ pub struct FilletData {
|
||||
pub radius: f64,
|
||||
/// The tags of the paths you want to fillet.
|
||||
pub tags: Vec<EdgeReference>,
|
||||
/// The tolerance for the fillet.
|
||||
#[serde(default)]
|
||||
pub tolerance: Option<f64>,
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
name = "fillet",
|
||||
}]
|
||||
@ -112,7 +140,7 @@ async fn inner_fillet(
|
||||
edge_id,
|
||||
object_id: extrude_group.id,
|
||||
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),
|
||||
},
|
||||
)
|
||||
@ -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},
|
||||
std::{
|
||||
extrude::do_post_extrude,
|
||||
fillet::{EdgeReference, DEFAULT_TOLERANCE},
|
||||
fillet::{default_tolerance, EdgeReference},
|
||||
Args,
|
||||
},
|
||||
};
|
||||
@ -25,6 +25,9 @@ pub struct RevolveData {
|
||||
pub angle: Option<f64>,
|
||||
/// Axis of revolution.
|
||||
pub axis: RevolveAxis,
|
||||
/// Tolerance for the revolve operation.
|
||||
#[serde(default)]
|
||||
pub tolerance: Option<f64>,
|
||||
}
|
||||
|
||||
/// Axis of revolution or tagged edge.
|
||||
@ -207,6 +210,24 @@ pub async fn revolve(args: Args) -> Result<KclValue, KclError> {
|
||||
/// ```
|
||||
///
|
||||
/// ```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')
|
||||
/// |> startProfileAt([10, 0], %)
|
||||
/// |> line([5, -5], %)
|
||||
@ -254,7 +275,7 @@ async fn inner_revolve(
|
||||
target: sketch_group.id,
|
||||
axis,
|
||||
origin,
|
||||
tolerance: DEFAULT_TOLERANCE,
|
||||
tolerance: data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units)),
|
||||
axis_is_2d: true,
|
||||
},
|
||||
)
|
||||
@ -271,7 +292,7 @@ async fn inner_revolve(
|
||||
angle,
|
||||
target: sketch_group.id,
|
||||
edge_id,
|
||||
tolerance: DEFAULT_TOLERANCE,
|
||||
tolerance: data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units)),
|
||||
},
|
||||
)
|
||||
.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 |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 96 KiB |
BIN
src/wasm-lib/kcl/tests/outputs/serial_test_example_fillet1.png
Normal file
|
After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 131 KiB After Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 195 KiB |
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 132 KiB After Width: | Height: | Size: 131 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 176 KiB After Width: | Height: | Size: 178 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 307 KiB After Width: | Height: | Size: 261 KiB |
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 187 KiB After Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 232 KiB After Width: | Height: | Size: 232 KiB |
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 209 KiB After Width: | Height: | Size: 160 KiB |
BIN
src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve7.png
Normal file
|
After Width: | Height: | Size: 207 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 149 KiB After Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 127 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 129 KiB |