KCL: Default circular pattern rotateDuplicates=true, arcDegrees=360 (#7052)

KCL: Default circular pattern rotateDuplicates=true, arcDeg=360

Seems like most users would want these.
This commit is contained in:
Adam Chalmers
2025-05-18 21:46:00 -05:00
committed by GitHub
parent 658497da1d
commit f3e9d110c0
5 changed files with 47 additions and 47 deletions

View File

@ -12,8 +12,8 @@ patternCircular2d(
@sketchSet: [Sketch], @sketchSet: [Sketch],
instances: number, instances: number,
center: Point2d, center: Point2d,
arcDegrees: number, arcDegrees?: number,
rotateDuplicates: bool, rotateDuplicates?: bool,
useOriginal?: bool, useOriginal?: bool,
): [Sketch] ): [Sketch]
``` ```
@ -27,8 +27,8 @@ patternCircular2d(
| `sketchSet` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | Which sketch(es) to pattern | Yes | | `sketchSet` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | Which sketch(es) to pattern | Yes |
| `instances` | [`number`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes | | `instances` | [`number`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes |
| `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center about which to make the pattern. This is a 2D vector. | Yes | | `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center about which to make the pattern. This is a 2D vector. | Yes |
| `arcDegrees` | [`number`](/docs/kcl-std/types/std-types-number) | The arc angle (in degrees) to place the repetitions. Must be greater than 0. | Yes | | `arcDegrees` | [`number`](/docs/kcl-std/types/std-types-number) | The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360. | No |
| `rotateDuplicates` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether or not to rotate the duplicates as they are copied. | Yes | | `rotateDuplicates` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether or not to rotate the duplicates as they are copied. Defaults to true. | No |
| `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No | | `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No |
### Returns ### Returns

View File

@ -13,8 +13,8 @@ patternCircular3d(
instances: number, instances: number,
axis: [number], axis: [number],
center: Point3d, center: Point3d,
arcDegrees: number, arcDegrees?: number,
rotateDuplicates: bool, rotateDuplicates?: bool,
useOriginal?: bool, useOriginal?: bool,
): [Solid] ): [Solid]
``` ```
@ -29,8 +29,8 @@ patternCircular3d(
| `instances` | [`number`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes | | `instances` | [`number`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes |
| `axis` | [`[number]`](/docs/kcl-std/types/std-types-number) | The axis around which to make the pattern. This is a 3D vector | Yes | | `axis` | [`[number]`](/docs/kcl-std/types/std-types-number) | The axis around which to make the pattern. This is a 3D vector | Yes |
| `center` | [`Point3d`](/docs/kcl-std/types/std-types-Point3d) | The center about which to make the pattern. This is a 3D vector. | Yes | | `center` | [`Point3d`](/docs/kcl-std/types/std-types-Point3d) | The center about which to make the pattern. This is a 3D vector. | Yes |
| `arcDegrees` | [`number`](/docs/kcl-std/types/std-types-number) | The arc angle (in degrees) to place the repetitions. Must be greater than 0. | Yes | | `arcDegrees` | [`number`](/docs/kcl-std/types/std-types-number) | The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360. | No |
| `rotateDuplicates` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether or not to rotate the duplicates as they are copied. | Yes | | `rotateDuplicates` | [`bool`](/docs/kcl-std/types/std-types-bool) | Whether or not to rotate the duplicates as they are copied. Defaults to true. | No |
| `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No | | `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No |
### Returns ### Returns

View File

@ -127364,9 +127364,10 @@
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double", "title": "Nullable_double",
"type": "number", "type": "number",
"format": "double", "format": "double",
"nullable": true,
"definitions": { "definitions": {
"Sketch": { "Sketch": {
"type": "object", "type": "object",
@ -128959,9 +128960,8 @@
} }
} }
}, },
"required": true, "required": false,
"includeInSnippet": true, "description": "The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360.",
"description": "The arc angle (in degrees) to place the repetitions. Must be greater than 0.",
"labelRequired": true "labelRequired": true
}, },
{ {
@ -128969,8 +128969,9 @@
"type": "bool", "type": "bool",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "Boolean", "title": "Nullable_Boolean",
"type": "boolean", "type": "boolean",
"nullable": true,
"definitions": { "definitions": {
"Sketch": { "Sketch": {
"type": "object", "type": "object",
@ -130563,9 +130564,8 @@
} }
} }
}, },
"required": true, "required": false,
"includeInSnippet": true, "description": "Whether or not to rotate the duplicates as they are copied. Defaults to true.",
"description": "Whether or not to rotate the duplicates as they are copied.",
"labelRequired": true "labelRequired": true
}, },
{ {
@ -140234,9 +140234,10 @@
"type": "number", "type": "number",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double", "title": "Nullable_double",
"type": "number", "type": "number",
"format": "double", "format": "double",
"nullable": true,
"definitions": { "definitions": {
"Solid": { "Solid": {
"type": "object", "type": "object",
@ -141829,9 +141830,8 @@
} }
} }
}, },
"required": true, "required": false,
"includeInSnippet": true, "description": "The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360.",
"description": "The arc angle (in degrees) to place the repetitions. Must be greater than 0.",
"labelRequired": true "labelRequired": true
}, },
{ {
@ -141839,8 +141839,9 @@
"type": "bool", "type": "bool",
"schema": { "schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "Boolean", "title": "Nullable_Boolean",
"type": "boolean", "type": "boolean",
"nullable": true,
"definitions": { "definitions": {
"Solid": { "Solid": {
"type": "object", "type": "object",
@ -143433,9 +143434,8 @@
} }
} }
}, },
"required": true, "required": false,
"includeInSnippet": true, "description": "Whether or not to rotate the duplicates as they are copied. Defaults to true.",
"description": "Whether or not to rotate the duplicates as they are copied.",
"labelRequired": true "labelRequired": true
}, },
{ {

View File

@ -995,7 +995,7 @@ mod tests {
let snippet = pattern_fn.to_autocomplete_snippet().unwrap(); let snippet = pattern_fn.to_autocomplete_snippet().unwrap();
assert_eq!( assert_eq!(
snippet, snippet,
r#"patternCircular3d(${0:%}, instances = ${1:10}, axis = [${2:3.14}, ${3:3.14}, ${4:3.14}], center = [${5:3.14}, ${6:3.14}, ${7:3.14}], arcDegrees = ${8:3.14}, rotateDuplicates = ${9:false})"# r#"patternCircular3d(${0:%}, instances = ${1:10}, axis = [${2:3.14}, ${3:3.14}, ${4:3.14}], center = [${5:3.14}, ${6:3.14}, ${7:3.14}])"#
); );
} }

View File

@ -1014,9 +1014,9 @@ struct CircularPattern2dData {
/// The center about which to make the pattern. This is a 2D vector. /// The center about which to make the pattern. This is a 2D vector.
pub center: [TyF64; 2], pub center: [TyF64; 2],
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0. /// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
pub arc_degrees: f64, pub arc_degrees: Option<f64>,
/// Whether or not to rotate the duplicates as they are copied. /// Whether or not to rotate the duplicates as they are copied.
pub rotate_duplicates: bool, pub rotate_duplicates: Option<bool>,
/// If the target being patterned is itself a pattern, then, should you use the original solid, /// If the target being patterned is itself a pattern, then, should you use the original solid,
/// or the pattern? /// or the pattern?
#[serde(default)] #[serde(default)]
@ -1038,9 +1038,9 @@ struct CircularPattern3dData {
/// The center about which to make the pattern. This is a 3D vector. /// The center about which to make the pattern. This is a 3D vector.
pub center: [TyF64; 3], pub center: [TyF64; 3],
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0. /// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
pub arc_degrees: f64, pub arc_degrees: Option<f64>,
/// Whether or not to rotate the duplicates as they are copied. /// Whether or not to rotate the duplicates as they are copied.
pub rotate_duplicates: bool, pub rotate_duplicates: Option<bool>,
/// If the target being patterned is itself a pattern, then, should you use the original solid, /// If the target being patterned is itself a pattern, then, should you use the original solid,
/// or the pattern? /// or the pattern?
#[serde(default)] #[serde(default)]
@ -1095,14 +1095,14 @@ impl CircularPattern {
RepetitionsNeeded::from(n) RepetitionsNeeded::from(n)
} }
pub fn arc_degrees(&self) -> f64 { pub fn arc_degrees(&self) -> Option<f64> {
match self { match self {
CircularPattern::TwoD(lp) => lp.arc_degrees, CircularPattern::TwoD(lp) => lp.arc_degrees,
CircularPattern::ThreeD(lp) => lp.arc_degrees, CircularPattern::ThreeD(lp) => lp.arc_degrees,
} }
} }
pub fn rotate_duplicates(&self) -> bool { pub fn rotate_duplicates(&self) -> Option<bool> {
match self { match self {
CircularPattern::TwoD(lp) => lp.rotate_duplicates, CircularPattern::TwoD(lp) => lp.rotate_duplicates,
CircularPattern::ThreeD(lp) => lp.rotate_duplicates, CircularPattern::ThreeD(lp) => lp.rotate_duplicates,
@ -1122,15 +1122,15 @@ pub async fn pattern_circular_2d(exec_state: &mut ExecState, args: Args) -> Resu
let sketches = args.get_unlabeled_kw_arg_typed("sketches", &RuntimeType::sketches(), exec_state)?; let sketches = args.get_unlabeled_kw_arg_typed("sketches", &RuntimeType::sketches(), exec_state)?;
let instances: u32 = args.get_kw_arg("instances")?; let instances: u32 = args.get_kw_arg("instances")?;
let center: [TyF64; 2] = args.get_kw_arg_typed("center", &RuntimeType::point2d(), exec_state)?; let center: [TyF64; 2] = args.get_kw_arg_typed("center", &RuntimeType::point2d(), exec_state)?;
let arc_degrees: TyF64 = args.get_kw_arg_typed("arcDegrees", &RuntimeType::degrees(), exec_state)?; let arc_degrees: Option<TyF64> = args.get_kw_arg_opt_typed("arcDegrees", &RuntimeType::degrees(), exec_state)?;
let rotate_duplicates: bool = args.get_kw_arg("rotateDuplicates")?; let rotate_duplicates: Option<bool> = args.get_kw_arg_opt("rotateDuplicates")?;
let use_original: Option<bool> = args.get_kw_arg_opt("useOriginal")?; let use_original: Option<bool> = args.get_kw_arg_opt("useOriginal")?;
let sketches = inner_pattern_circular_2d( let sketches = inner_pattern_circular_2d(
sketches, sketches,
instances, instances,
center, center,
arc_degrees.n, arc_degrees.map(|x| x.n),
rotate_duplicates, rotate_duplicates,
use_original, use_original,
exec_state, exec_state,
@ -1169,8 +1169,8 @@ pub async fn pattern_circular_2d(exec_state: &mut ExecState, args: Args) -> Resu
sketch_set = { docs = "Which sketch(es) to pattern" }, sketch_set = { docs = "Which sketch(es) to pattern" },
instances = { docs = "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect."}, instances = { docs = "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect."},
center = { docs = "The center about which to make the pattern. This is a 2D vector."}, center = { docs = "The center about which to make the pattern. This is a 2D vector."},
arc_degrees = { docs = "The arc angle (in degrees) to place the repetitions. Must be greater than 0."}, arc_degrees = { docs = "The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360."},
rotate_duplicates= { docs = "Whether or not to rotate the duplicates as they are copied."}, rotate_duplicates= { docs = "Whether or not to rotate the duplicates as they are copied. Defaults to true."},
use_original= { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false."}, use_original= { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false."},
}, },
tags = ["sketch"] tags = ["sketch"]
@ -1180,8 +1180,8 @@ async fn inner_pattern_circular_2d(
sketch_set: Vec<Sketch>, sketch_set: Vec<Sketch>,
instances: u32, instances: u32,
center: [TyF64; 2], center: [TyF64; 2],
arc_degrees: f64, arc_degrees: Option<f64>,
rotate_duplicates: bool, rotate_duplicates: Option<bool>,
use_original: Option<bool>, use_original: Option<bool>,
exec_state: &mut ExecState, exec_state: &mut ExecState,
args: Args, args: Args,
@ -1235,9 +1235,9 @@ pub async fn pattern_circular_3d(exec_state: &mut ExecState, args: Args) -> Resu
// The center about which to make the pattern. This is a 3D vector. // The center about which to make the pattern. This is a 3D vector.
let center: [TyF64; 3] = args.get_kw_arg_typed("center", &RuntimeType::point3d(), exec_state)?; let center: [TyF64; 3] = args.get_kw_arg_typed("center", &RuntimeType::point3d(), exec_state)?;
// The arc angle (in degrees) to place the repetitions. Must be greater than 0. // The arc angle (in degrees) to place the repetitions. Must be greater than 0.
let arc_degrees: TyF64 = args.get_kw_arg_typed("arcDegrees", &RuntimeType::degrees(), exec_state)?; let arc_degrees: Option<TyF64> = args.get_kw_arg_opt_typed("arcDegrees", &RuntimeType::degrees(), exec_state)?;
// Whether or not to rotate the duplicates as they are copied. // Whether or not to rotate the duplicates as they are copied.
let rotate_duplicates: bool = args.get_kw_arg("rotateDuplicates")?; let rotate_duplicates: Option<bool> = args.get_kw_arg_opt("rotateDuplicates")?;
// If the target being patterned is itself a pattern, then, should you use the original solid, // If the target being patterned is itself a pattern, then, should you use the original solid,
// or the pattern? // or the pattern?
let use_original: Option<bool> = args.get_kw_arg_opt("useOriginal")?; let use_original: Option<bool> = args.get_kw_arg_opt("useOriginal")?;
@ -1247,7 +1247,7 @@ pub async fn pattern_circular_3d(exec_state: &mut ExecState, args: Args) -> Resu
instances, instances,
[axis[0].n, axis[1].n, axis[2].n], [axis[0].n, axis[1].n, axis[2].n],
center, center,
arc_degrees.n, arc_degrees.map(|x| x.n),
rotate_duplicates, rotate_duplicates,
use_original, use_original,
exec_state, exec_state,
@ -1285,8 +1285,8 @@ pub async fn pattern_circular_3d(exec_state: &mut ExecState, args: Args) -> Resu
instances = { docs = "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect."}, instances = { docs = "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect."},
axis = { docs = "The axis around which to make the pattern. This is a 3D vector"}, axis = { docs = "The axis around which to make the pattern. This is a 3D vector"},
center = { docs = "The center about which to make the pattern. This is a 3D vector."}, center = { docs = "The center about which to make the pattern. This is a 3D vector."},
arc_degrees = { docs = "The arc angle (in degrees) to place the repetitions. Must be greater than 0."}, arc_degrees = { docs = "The arc angle (in degrees) to place the repetitions. Must be greater than 0. Defaults to 360."},
rotate_duplicates = { docs = "Whether or not to rotate the duplicates as they are copied."}, rotate_duplicates = { docs = "Whether or not to rotate the duplicates as they are copied. Defaults to true."},
use_original = { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false."}, use_original = { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false."},
}, },
tags = ["solid"] tags = ["solid"]
@ -1297,8 +1297,8 @@ async fn inner_pattern_circular_3d(
instances: u32, instances: u32,
axis: [f64; 3], axis: [f64; 3],
center: [TyF64; 3], center: [TyF64; 3],
arc_degrees: f64, arc_degrees: Option<f64>,
rotate_duplicates: bool, rotate_duplicates: Option<bool>,
use_original: Option<bool>, use_original: Option<bool>,
exec_state: &mut ExecState, exec_state: &mut ExecState,
args: Args, args: Args,
@ -1382,8 +1382,8 @@ async fn pattern_circular(
z: LengthUnit(center[2]), z: LengthUnit(center[2]),
}, },
num_repetitions, num_repetitions,
arc_degrees: data.arc_degrees(), arc_degrees: data.arc_degrees().unwrap_or(360.0),
rotate_duplicates: data.rotate_duplicates(), rotate_duplicates: data.rotate_duplicates().unwrap_or(true),
}), }),
) )
.await?; .await?;