diff --git a/docs/kcl/std.json b/docs/kcl/std.json index e7857eb91..a50cf7a4e 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -18090,6 +18090,1463 @@ "unpublished": false, "deprecated": false }, + { + "name": "circle", + "summary": "Sketch a circle on the given plane", + "description": "", + "tags": [], + "args": [ + { + "name": "plane", + "type": "SketchData", + "schema": { + "description": "Data for start sketch on. You can start a sketch on a plane or an extrude group.", + "anyOf": [ + { + "description": "Data for a plane.", + "oneOf": [ + { + "description": "The XY plane.", + "type": "string", + "enum": [ + "XY" + ] + }, + { + "description": "The opposite side of the XY plane.", + "type": "string", + "enum": [ + "-XY" + ] + }, + { + "description": "The XZ plane.", + "type": "string", + "enum": [ + "XZ" + ] + }, + { + "description": "The opposite side of the XZ plane.", + "type": "string", + "enum": [ + "-XZ" + ] + }, + { + "description": "The YZ plane.", + "type": "string", + "enum": [ + "YZ" + ] + }, + { + "description": "The opposite side of the YZ plane.", + "type": "string", + "enum": [ + "-YZ" + ] + }, + { + "description": "A defined plane.", + "type": "object", + "required": [ + "plane" + ], + "properties": { + "plane": { + "type": "object", + "required": [ + "origin", + "x_axis", + "y_axis", + "z_axis" + ], + "properties": { + "origin": { + "description": "Origin of the plane.", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "x_axis": { + "description": "What should the plane’s X axis be?", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "y_axis": { + "description": "What should the plane’s Y axis be?", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "z_axis": { + "description": "The z-axis (normal).", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + } + } + } + }, + "additionalProperties": false + } + ] + }, + { + "description": "An extrude group is a collection of extrude surfaces.", + "type": "object", + "required": [ + "__meta", + "height", + "id", + "position", + "rotation", + "value", + "xAxis", + "yAxis", + "zAxis" + ], + "properties": { + "__meta": { + "description": "Metadata.", + "type": "array", + "items": { + "description": "Metadata.", + "type": "object", + "required": [ + "sourceRange" + ], + "properties": { + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + } + }, + "endCapId": { + "description": "The id of the extrusion end cap", + "type": "string", + "format": "uuid", + "nullable": true + }, + "height": { + "description": "The height of the extrude group.", + "type": "number", + "format": "double" + }, + "id": { + "description": "The id of the extrude group.", + "type": "string", + "format": "uuid" + }, + "position": { + "description": "The position of the extrude group.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 3, + "minItems": 3 + }, + "rotation": { + "description": "The rotation of the extrude group.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 4, + "minItems": 4 + }, + "startCapId": { + "description": "The id of the extrusion start cap", + "type": "string", + "format": "uuid", + "nullable": true + }, + "value": { + "description": "The extrude surfaces.", + "type": "array", + "items": { + "description": "An extrude surface.", + "oneOf": [ + { + "description": "An extrude plane.", + "type": "object", + "required": [ + "faceId", + "id", + "name", + "position", + "rotation", + "sourceRange", + "type" + ], + "properties": { + "faceId": { + "description": "The face id for the extrude plane.", + "type": "string", + "format": "uuid" + }, + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "name": { + "description": "The name.", + "type": "string" + }, + "position": { + "description": "The position.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 3, + "minItems": 3 + }, + "rotation": { + "description": "The rotation.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 4, + "minItems": 4 + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "extrudePlane" + ] + } + } + }, + { + "description": "An extruded arc.", + "type": "object", + "required": [ + "faceId", + "id", + "name", + "position", + "rotation", + "sourceRange", + "type" + ], + "properties": { + "faceId": { + "description": "The face id for the extrude plane.", + "type": "string", + "format": "uuid" + }, + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "name": { + "description": "The name.", + "type": "string" + }, + "position": { + "description": "The position.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 3, + "minItems": 3 + }, + "rotation": { + "description": "The rotation.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 4, + "minItems": 4 + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "extrudeArc" + ] + } + } + } + ] + } + }, + "xAxis": { + "description": "The x-axis of the extrude group base plane in the 3D space", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "yAxis": { + "description": "The y-axis of the extrude group base plane in the 3D space", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "zAxis": { + "description": "The z-axis of the extrude group base plane in the 3D space", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + } + } + } + ] + }, + "required": true + }, + { + "name": "center", + "type": "[number, number]", + "schema": { + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "required": true + }, + { + "name": "radius", + "type": "number", + "schema": { + "type": "number", + "format": "double" + }, + "required": true + } + ], + "returnValue": { + "name": "SketchGroup", + "type": "SketchGroup", + "schema": { + "description": "A sketch group is a collection of paths.", + "type": "object", + "required": [ + "__meta", + "id", + "on", + "position", + "rotation", + "start", + "value", + "xAxis", + "yAxis", + "zAxis" + ], + "properties": { + "__meta": { + "description": "Metadata.", + "type": "array", + "items": { + "description": "Metadata.", + "type": "object", + "required": [ + "sourceRange" + ], + "properties": { + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + } + }, + "entityId": { + "description": "The plane id or face id of the sketch group.", + "type": "string", + "format": "uuid", + "nullable": true + }, + "id": { + "description": "The id of the sketch group.", + "type": "string", + "format": "uuid" + }, + "on": { + "description": "What the sketch is on (can be a plane or a face).", + "oneOf": [ + { + "description": "A plane.", + "type": "object", + "required": [ + "__meta", + "id", + "origin", + "type", + "value", + "xAxis", + "yAxis", + "zAxis" + ], + "properties": { + "__meta": { + "type": "array", + "items": { + "description": "Metadata.", + "type": "object", + "required": [ + "sourceRange" + ], + "properties": { + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + } + }, + "id": { + "description": "The id of the plane.", + "type": "string", + "format": "uuid" + }, + "origin": { + "description": "Origin of the plane.", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "type": { + "type": "string", + "enum": [ + "plane" + ] + }, + "value": { + "description": "Type for a plane.", + "oneOf": [ + { + "type": "string", + "enum": [ + "XY", + "XZ", + "YZ" + ] + }, + { + "description": "A custom plane.", + "type": "string", + "enum": [ + "Custom" + ] + } + ] + }, + "xAxis": { + "description": "What should the plane’s X axis be?", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "yAxis": { + "description": "What should the plane’s Y axis be?", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "zAxis": { + "description": "The z-axis (normal).", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + } + } + }, + { + "description": "A face.", + "type": "object", + "required": [ + "__meta", + "id", + "sketchGroupId", + "type", + "value", + "xAxis", + "yAxis", + "zAxis" + ], + "properties": { + "__meta": { + "type": "array", + "items": { + "description": "Metadata.", + "type": "object", + "required": [ + "sourceRange" + ], + "properties": { + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + } + }, + "id": { + "description": "The id of the face.", + "type": "string", + "format": "uuid" + }, + "sketchGroupId": { + "description": "The original sketch group id of the object we are sketching on.", + "type": "string", + "format": "uuid" + }, + "type": { + "type": "string", + "enum": [ + "face" + ] + }, + "value": { + "description": "The tag of the face.", + "type": "string" + }, + "xAxis": { + "description": "What should the face’s X axis be?", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "yAxis": { + "description": "What should the face’s Y axis be?", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "zAxis": { + "description": "The z-axis (normal).", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + } + } + } + ] + }, + "position": { + "description": "The position of the sketch group.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 3, + "minItems": 3 + }, + "rotation": { + "description": "The rotation of the sketch group base plane.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 4, + "minItems": 4 + }, + "start": { + "description": "The starting path.", + "type": "object", + "required": [ + "__geoMeta", + "from", + "name", + "to" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "value": { + "description": "The paths in the sketch group.", + "type": "array", + "items": { + "description": "A path.", + "oneOf": [ + { + "description": "A path that goes to a point.", + "type": "object", + "required": [ + "__geoMeta", + "from", + "name", + "to", + "type" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "ToPoint" + ] + } + } + }, + { + "description": "A arc that is tangential to the last path segment that goes to a point", + "type": "object", + "required": [ + "__geoMeta", + "ccw", + "center", + "from", + "name", + "to", + "type" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "ccw": { + "description": "arc's direction", + "type": "boolean" + }, + "center": { + "description": "the arc's center", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "TangentialArcTo" + ] + } + } + }, + { + "description": "A arc that is tangential to the last path segment", + "type": "object", + "required": [ + "__geoMeta", + "from", + "name", + "to", + "type" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "TangentialArc" + ] + } + } + }, + { + "description": "A path that is horizontal.", + "type": "object", + "required": [ + "__geoMeta", + "from", + "name", + "to", + "type", + "x" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "Horizontal" + ] + }, + "x": { + "description": "The x coordinate.", + "type": "number", + "format": "double" + } + } + }, + { + "description": "An angled line to.", + "type": "object", + "required": [ + "__geoMeta", + "from", + "name", + "to", + "type" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "AngledLineTo" + ] + }, + "x": { + "description": "The x coordinate.", + "type": "number", + "format": "double", + "nullable": true + }, + "y": { + "description": "The y coordinate.", + "type": "number", + "format": "double", + "nullable": true + } + } + }, + { + "description": "A base path.", + "type": "object", + "required": [ + "__geoMeta", + "from", + "name", + "to", + "type" + ], + "properties": { + "__geoMeta": { + "description": "Metadata.", + "type": "object", + "required": [ + "id", + "sourceRange" + ], + "properties": { + "id": { + "description": "The id of the geometry.", + "type": "string", + "format": "uuid" + }, + "sourceRange": { + "description": "The source range.", + "type": "array", + "items": { + "type": "integer", + "format": "uint", + "minimum": 0.0 + }, + "maxItems": 2, + "minItems": 2 + } + } + }, + "from": { + "description": "The from point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "name": { + "description": "The name of the path.", + "type": "string" + }, + "to": { + "description": "The to point.", + "type": "array", + "items": { + "type": "number", + "format": "double" + }, + "maxItems": 2, + "minItems": 2 + }, + "type": { + "type": "string", + "enum": [ + "Base" + ] + } + } + } + ] + } + }, + "xAxis": { + "description": "The x-axis of the sketch group base plane in the 3D space", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "yAxis": { + "description": "The y-axis of the sketch group base plane in the 3D space", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + }, + "zAxis": { + "description": "The z-axis of the sketch group base plane in the 3D space", + "type": "object", + "required": [ + "x", + "y", + "z" + ], + "properties": { + "x": { + "type": "number", + "format": "double" + }, + "y": { + "type": "number", + "format": "double" + }, + "z": { + "type": "number", + "format": "double" + } + } + } + } + }, + "required": true + }, + "unpublished": false, + "deprecated": false + }, { "name": "close", "summary": "Close the current sketch.", diff --git a/docs/kcl/std.md b/docs/kcl/std.md index 674753d63..5306c5449 100644 --- a/docs/kcl/std.md +++ b/docs/kcl/std.md @@ -20,6 +20,7 @@ * [`atan`](#atan) * [`bezierCurve`](#bezierCurve) * [`ceil`](#ceil) + * [`circle`](#circle) * [`close`](#close) * [`cos`](#cos) * [`e`](#e) @@ -3438,6 +3439,290 @@ ceil(num: number) -> number +### circle + +Sketch a circle on the given plane + + + +``` +circle(plane: SketchData, center: [number, number], radius: number) -> SketchGroup +``` + +#### Arguments + +* `plane`: `SketchData` - Data for start sketch on. You can start a sketch on a plane or an extrude group. +``` +"XY" | +"-XY" | +"XZ" | +"-XZ" | +"YZ" | +"-YZ" | +{ + plane: { + // Origin of the plane. + origin: { + x: number, + y: number, + z: number, +}, + // What should the plane’s X axis be? + x_axis: { + x: number, + y: number, + z: number, +}, + // What should the plane’s Y axis be? + y_axis: { + x: number, + y: number, + z: number, +}, + // The z-axis (normal). + z_axis: { + x: number, + y: number, + z: number, +}, +}, +} | +{ + // The id of the extrusion end cap + endCapId: uuid, + // The height of the extrude group. + height: number, + // The id of the extrude group. + id: uuid, + // The position of the extrude group. + position: [number, number, number], + // The rotation of the extrude group. + rotation: [number, number, number, number], + // The id of the extrusion start cap + startCapId: uuid, + // The extrude surfaces. + value: [{ + // The face id for the extrude plane. + faceId: uuid, + // The id of the geometry. + id: uuid, + // The name. + name: string, + // The position. + position: [number, number, number], + // The rotation. + rotation: [number, number, number, number], + // The source range. + sourceRange: [number, number], + type: "extrudePlane", +} | +{ + // The face id for the extrude plane. + faceId: uuid, + // The id of the geometry. + id: uuid, + // The name. + name: string, + // The position. + position: [number, number, number], + // The rotation. + rotation: [number, number, number, number], + // The source range. + sourceRange: [number, number], + type: "extrudeArc", +}], + // The x-axis of the extrude group base plane in the 3D space + xAxis: { + x: number, + y: number, + z: number, +}, + // The y-axis of the extrude group base plane in the 3D space + yAxis: { + x: number, + y: number, + z: number, +}, + // The z-axis of the extrude group base plane in the 3D space + zAxis: { + x: number, + y: number, + z: number, +}, +} +``` +* `center`: `[number, number]` +* `radius`: `number` + +#### Returns + +* `SketchGroup` - A sketch group is a collection of paths. +``` +{ + // The plane id or face id of the sketch group. + entityId: uuid, + // The id of the sketch group. + id: uuid, + // What the sketch is on (can be a plane or a face). + on: { + // The id of the plane. + id: uuid, + // Origin of the plane. + origin: { + x: number, + y: number, + z: number, +}, + type: "plane", + // Type for a plane. + value: "XY" | "XZ" | "YZ" | "Custom", + // What should the plane’s X axis be? + xAxis: { + x: number, + y: number, + z: number, +}, + // What should the plane’s Y axis be? + yAxis: { + x: number, + y: number, + z: number, +}, + // The z-axis (normal). + zAxis: { + x: number, + y: number, + z: number, +}, +} | +{ + // The id of the face. + id: uuid, + // The original sketch group id of the object we are sketching on. + sketchGroupId: uuid, + type: "face", + // The tag of the face. + value: string, + // What should the face’s X axis be? + xAxis: { + x: number, + y: number, + z: number, +}, + // What should the face’s Y axis be? + yAxis: { + x: number, + y: number, + z: number, +}, + // The z-axis (normal). + zAxis: { + x: number, + y: number, + z: number, +}, +}, + // The position of the sketch group. + position: [number, number, number], + // The rotation of the sketch group base plane. + rotation: [number, number, number, number], + // The starting path. + start: { + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], +}, + // The paths in the sketch group. + value: [{ + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], + type: "ToPoint", +} | +{ + // arc's direction + ccw: string, + // the arc's center + center: [number, number], + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], + type: "TangentialArcTo", +} | +{ + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], + type: "TangentialArc", +} | +{ + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], + type: "Horizontal", + // The x coordinate. + x: number, +} | +{ + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], + type: "AngledLineTo", + // The x coordinate. + x: number, + // The y coordinate. + y: number, +} | +{ + // The from point. + from: [number, number], + // The name of the path. + name: string, + // The to point. + to: [number, number], + type: "Base", +}], + // The x-axis of the sketch group base plane in the 3D space + xAxis: { + x: number, + y: number, + z: number, +}, + // The y-axis of the sketch group base plane in the 3D space + yAxis: { + x: number, + y: number, + z: number, +}, + // The z-axis of the sketch group base plane in the 3D space + zAxis: { + x: number, + y: number, + z: number, +}, +} +``` + + + ### close Close the current sketch. diff --git a/src/wasm-lib/kcl/src/lsp/kcl/mod.rs b/src/wasm-lib/kcl/src/lsp/kcl/mod.rs index c8e4e939b..9d8de041a 100644 --- a/src/wasm-lib/kcl/src/lsp/kcl/mod.rs +++ b/src/wasm-lib/kcl/src/lsp/kcl/mod.rs @@ -636,8 +636,9 @@ impl LanguageServer for Backend { /// Get completions from our stdlib. pub fn get_completions_from_stdlib(stdlib: &crate::std::StdLib) -> Result> { let mut completions = HashMap::new(); + let combined = stdlib.combined(); - for internal_fn in stdlib.fns.values() { + for internal_fn in combined.values() { completions.insert(internal_fn.name(), internal_fn.to_completion_item()); } @@ -652,8 +653,9 @@ pub fn get_completions_from_stdlib(stdlib: &crate::std::StdLib) -> Result Result> { let mut signatures = HashMap::new(); + let combined = stdlib.combined(); - for internal_fn in stdlib.fns.values() { + for internal_fn in combined.values() { signatures.insert(internal_fn.name(), internal_fn.to_signature_help()); } diff --git a/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__au.snap b/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__au.snap index e828dab5c..9b9d64178 100644 --- a/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__au.snap +++ b/src/wasm-lib/kcl/src/parser/snapshots/kcl_lib__parser__parser_impl__snapshot_tests__au.snap @@ -4,18 +4,18 @@ expression: actual --- { "start": 0, - "end": 90, + "end": 74, "body": [ { "type": "VariableDeclaration", "type": "VariableDeclaration", "start": 0, - "end": 74, + "end": 58, "declarations": [ { "type": "VariableDeclarator", "start": 6, - "end": 74, + "end": 58, "id": { "type": "Identifier", "start": 6, @@ -26,47 +26,47 @@ expression: actual "type": "PipeExpression", "type": "PipeExpression", "start": 17, - "end": 74, + "end": 58, "body": [ { "type": "CallExpression", "type": "CallExpression", "start": 17, - "end": 56, + "end": 40, "callee": { "type": "Identifier", "start": 17, - "end": 39, - "name": "unstable_stdlib_circle" + "end": 23, + "name": "circle" }, "arguments": [ { "type": "Literal", "type": "Literal", - "start": 40, - "end": 44, + "start": 24, + "end": 28, "value": "XY", "raw": "'XY'" }, { "type": "ArrayExpression", "type": "ArrayExpression", - "start": 46, - "end": 51, + "start": 30, + "end": 35, "elements": [ { "type": "Literal", "type": "Literal", - "start": 47, - "end": 48, + "start": 31, + "end": 32, "value": 0, "raw": "0" }, { "type": "Literal", "type": "Literal", - "start": 49, - "end": 50, + "start": 33, + "end": 34, "value": 0, "raw": "0" } @@ -75,8 +75,8 @@ expression: actual { "type": "Literal", "type": "Literal", - "start": 53, - "end": 55, + "start": 37, + "end": 39, "value": 22, "raw": "22" } @@ -86,28 +86,28 @@ expression: actual { "type": "CallExpression", "type": "CallExpression", - "start": 60, - "end": 74, + "start": 44, + "end": 58, "callee": { "type": "Identifier", - "start": 60, - "end": 67, + "start": 44, + "end": 51, "name": "extrude" }, "arguments": [ { "type": "Literal", "type": "Literal", - "start": 68, - "end": 70, + "start": 52, + "end": 54, "value": 14, "raw": "14" }, { "type": "PipeSubstitution", "type": "PipeSubstitution", - "start": 72, - "end": 73 + "start": 56, + "end": 57 } ], "optional": false @@ -125,25 +125,25 @@ expression: actual { "type": "ExpressionStatement", "type": "ExpressionStatement", - "start": 75, - "end": 89, + "start": 59, + "end": 73, "expression": { "type": "CallExpression", "type": "CallExpression", - "start": 75, - "end": 89, + "start": 59, + "end": 73, "callee": { "type": "Identifier", - "start": 75, - "end": 79, + "start": 59, + "end": 63, "name": "show" }, "arguments": [ { "type": "Identifier", "type": "Identifier", - "start": 80, - "end": 88, + "start": 64, + "end": 72, "name": "cylinder" } ], diff --git a/src/wasm-lib/kcl/src/std/kcl_stdlib.rs b/src/wasm-lib/kcl/src/std/kcl_stdlib.rs index 0eee747cf..a2b8cb755 100644 --- a/src/wasm-lib/kcl/src/std/kcl_stdlib.rs +++ b/src/wasm-lib/kcl/src/std/kcl_stdlib.rs @@ -11,6 +11,9 @@ pub trait KclStdLibFn: StdLibFn { fn kcl_clone_box(&self) -> Box; fn function(&self) -> &FunctionExpression; fn program(&self) -> &Program; + fn std_lib(&self) -> Box { + self.clone_box() + } } impl ts_rs::TS for dyn KclStdLibFn { diff --git a/src/wasm-lib/kcl/src/std/mod.rs b/src/wasm-lib/kcl/src/std/mod.rs index 082924497..9c05ef9b6 100644 --- a/src/wasm-lib/kcl/src/std/mod.rs +++ b/src/wasm-lib/kcl/src/std/mod.rs @@ -133,6 +133,15 @@ impl StdLib { Self { fns, kcl_fns } } + // Get the combined hashmaps. + pub fn combined(&self) -> HashMap> { + let mut combined = self.fns.clone(); + for (k, v) in self.kcl_fns.clone() { + combined.insert(k, v.std_lib()); + } + combined + } + pub fn get(&self, name: &str) -> Option> { self.fns.get(name).cloned() } @@ -789,6 +798,7 @@ mod tests { #[test] fn test_generate_stdlib_markdown_docs() { let stdlib = StdLib::new(); + let combined = stdlib.combined(); let mut buf = String::new(); buf.push_str("\n\n"); @@ -800,8 +810,8 @@ mod tests { buf.push_str("* [Functions](#functions)\n"); - for key in stdlib.fns.keys().sorted() { - let internal_fn = stdlib.fns.get(key).unwrap(); + for key in combined.keys().sorted() { + let internal_fn = combined.get(key).unwrap(); if internal_fn.unpublished() || internal_fn.deprecated() { continue; } @@ -813,8 +823,8 @@ mod tests { buf.push_str("## Functions\n\n"); - for key in stdlib.fns.keys().sorted() { - let internal_fn = stdlib.fns.get(key).unwrap(); + for key in combined.keys().sorted() { + let internal_fn = combined.get(key).unwrap(); if internal_fn.unpublished() { continue; } @@ -874,11 +884,12 @@ mod tests { #[test] fn test_generate_stdlib_json_schema() { let stdlib = StdLib::new(); + let combined = stdlib.combined(); let mut json_data = vec![]; - for key in stdlib.fns.keys().sorted() { - let internal_fn = stdlib.fns.get(key).unwrap(); + for key in combined.keys().sorted() { + let internal_fn = combined.get(key).unwrap(); json_data.push(internal_fn.to_json().unwrap()); } expectorate::assert_contents( diff --git a/src/wasm-lib/kcl/src/std/shapes.rs b/src/wasm-lib/kcl/src/std/shapes.rs index 8bafb0cc5..192c61fc6 100644 --- a/src/wasm-lib/kcl/src/std/shapes.rs +++ b/src/wasm-lib/kcl/src/std/shapes.rs @@ -48,7 +48,7 @@ impl std::fmt::Debug for Circle { /// TODO: Parse the KCL in a macro and generate these impl StdLibFn for Circle { fn name(&self) -> String { - "unstable_stdlib_circle".to_owned() + "circle".to_owned() } fn summary(&self) -> String { @@ -64,15 +64,56 @@ impl StdLibFn for Circle { } fn args(&self) -> Vec { - Vec::new() // TODO + let mut settings = schemars::gen::SchemaSettings::openapi3(); + settings.inline_subschemas = true; + let mut generator = schemars::gen::SchemaGenerator::new(settings); + let mut args = Vec::new(); + for parameter in &self.function.params { + match parameter.identifier.name.as_str() { + "plane" => { + args.push(crate::docs::StdLibFnArg { + name: parameter.identifier.name.to_owned(), + type_: "SketchData".to_string(), + schema: ::json_schema(&mut generator), + required: true, + }); + } + "center" => { + args.push(crate::docs::StdLibFnArg { + name: parameter.identifier.name.to_owned(), + type_: "[number, number]".to_string(), + schema: <[f64; 2]>::json_schema(&mut generator), + required: true, + }); + } + "radius" => { + args.push(crate::docs::StdLibFnArg { + name: parameter.identifier.name.to_owned(), + type_: "number".to_string(), + schema: ::json_schema(&mut generator), + required: true, + }); + } + _ => panic!("Unknown parameter: {:?}", parameter.identifier.name), + } + } + args } fn return_value(&self) -> Option { - None + let mut settings = schemars::gen::SchemaSettings::openapi3(); + settings.inline_subschemas = true; + let mut generator = schemars::gen::SchemaGenerator::new(settings); + Some(crate::docs::StdLibFnArg { + name: "SketchGroup".to_owned(), + type_: "SketchGroup".to_string(), + schema: ::json_schema(&mut generator), + required: true, + }) } fn unpublished(&self) -> bool { - true + false } fn deprecated(&self) -> bool { diff --git a/src/wasm-lib/tests/executor/inputs/cylinder.kcl b/src/wasm-lib/tests/executor/inputs/cylinder.kcl index 42f3eee28..e7f93ff12 100644 --- a/src/wasm-lib/tests/executor/inputs/cylinder.kcl +++ b/src/wasm-lib/tests/executor/inputs/cylinder.kcl @@ -1,2 +1,2 @@ -const cylinder = unstable_stdlib_circle('XY', [0,0], 22) |> extrude(14, %) +const cylinder = circle('XY', [0,0], 22) |> extrude(14, %) show(cylinder) diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index 8d6f68dca..20ead275e 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -602,23 +602,14 @@ const part004 = startSketchOn('YZ') #[tokio::test(flavor = "multi_thread")] async fn serial_test_holes() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt(pos, %) - |> arc({angle_end: 360, angle_start: 0, radius: radius}, %) - |> close(%) - - return sg -} - -const square = startSketchOn('XY') + let code = r#"const square = startSketchOn('XY') |> startProfileAt([0, 0], %) |> line([0, 10], %) |> line([10, 0], %) |> line([0, -10], %) |> close(%) - |> hole(circle([2, 2], .5), %) - |> hole(circle([2, 8], .5), %) + |> hole(circle('XY', [2, 2], .5), %) + |> hole(circle('XY', [2, 8], .5), %) |> extrude(2, %) "#; @@ -631,7 +622,7 @@ const square = startSketchOn('XY') #[tokio::test(flavor = "multi_thread")] async fn optional_params() { let code = r#" - fn circle = (pos, radius, tag?) => { + fn other_circle = (pos, radius, tag?) => { const sg = startSketchOn('XY') |> startProfileAt(pos, %) |> arc({angle_end: 360, angle_start: 0, radius: radius}, %) @@ -640,7 +631,7 @@ async fn optional_params() { return sg } -const thing = circle([2, 2], 20) +const thing = other_circle([2, 2], 20) "#; let result = execute_and_snapshot(code, kittycad::types::UnitLength::Mm) .await @@ -650,19 +641,7 @@ const thing = circle([2, 2], 20) #[tokio::test(flavor = "multi_thread")] async fn serial_test_rounded_with_holes() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -fn tarc = (to, sketchGroup, tag?) => { + let code = r#"fn tarc = (to, sketchGroup, tag?) => { return tangentialArcTo(to, sketchGroup, tag) } @@ -685,10 +664,10 @@ const holeRadius = 1 const holeIndex = 6 const part = roundedRectangle([0, 0], 20, 20, 4) - |> hole(circle([-holeIndex, holeIndex], holeRadius), %) - |> hole(circle([holeIndex, holeIndex], holeRadius), %) - |> hole(circle([-holeIndex, -holeIndex], holeRadius), %) - |> hole(circle([holeIndex, -holeIndex], holeRadius), %) + |> hole(circle('XY', [-holeIndex, holeIndex], holeRadius), %) + |> hole(circle('XY', [holeIndex, holeIndex], holeRadius), %) + |> hole(circle('XY', [-holeIndex, -holeIndex], holeRadius), %) + |> hole(circle('XY', [holeIndex, -holeIndex], holeRadius), %) |> extrude(2, %) "#; @@ -700,19 +679,7 @@ const part = roundedRectangle([0, 0], 20, 20, 4) #[tokio::test(flavor = "multi_thread")] async fn serial_test_top_level_expression() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -circle([0,0], 22) |> extrude(14, %)"#; + let code = r#"circle('XY', [0,0], 22) |> extrude(14, %)"#; let result = execute_and_snapshot(code, kittycad::types::UnitLength::Mm) .await @@ -722,19 +689,7 @@ circle([0,0], 22) |> extrude(14, %)"#; #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_linear_basic() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = circle([0,0], 2) + let code = r#"const part = circle('XY', [0,0], 2) |> patternLinear({axis: [0,1], repetitions: 12, distance: 2}, %) "#; @@ -746,19 +701,7 @@ const part = circle([0,0], 2) #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_linear_basic_3d() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = startSketchOn('XY') + let code = r#"const part = startSketchOn('XY') |> startProfileAt([0, 0], %) |> line([0,1], %) |> line([1, 0], %) @@ -776,19 +719,7 @@ const part = startSketchOn('XY') #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_linear_basic_negative_distance() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = circle([0,0], 2) + let code = r#"const part = circle('XY', [0,0], 2) |> patternLinear({axis: [0,1], repetitions: 12, distance: -2}, %) "#; @@ -804,19 +735,7 @@ const part = circle([0,0], 2) #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_linear_basic_negative_axis() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = circle([0,0], 2) + let code = r#"const part = circle('XY', [0,0], 2) |> patternLinear({axis: [0,-1], repetitions: 12, distance: 2}, %) "#; @@ -832,19 +751,7 @@ const part = circle([0,0], 2) #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_linear_basic_holes() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const circles = circle([5, 5], 1) + let code = r#"const circles = circle('XY', [5, 5], 1) |> patternLinear({axis: [1,1], repetitions: 12, distance: 3}, %) const rectangle = startSketchOn('XY') @@ -865,19 +772,7 @@ const rectangle = startSketchOn('XY') #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_circular_basic_2d() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = circle([0,0], 2) + let code = r#"const part = circle('XY', [0,0], 2) |> patternCircular({axis: [0,1], center: [20, 20, 20], repetitions: 12, arcDegrees: 210, rotateDuplicates: true}, %) "#; @@ -889,19 +784,7 @@ const part = circle([0,0], 2) #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_circular_basic_3d() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = startSketchOn('XY') + let code = r#"const part = startSketchOn('XY') |> startProfileAt([0, 0], %) |> line([0,1], %) |> line([1, 0], %) @@ -919,19 +802,7 @@ const part = startSketchOn('XY') #[tokio::test(flavor = "multi_thread")] async fn serial_test_patterns_circular_3d_tilted_axis() { - let code = r#"fn circle = (pos, radius) => { - const sg = startSketchOn('XY') - |> startProfileAt([pos[0] + radius, pos[1]], %) - |> arc({ - angle_end: 360, - angle_start: 0, - radius: radius - }, %) - |> close(%) - return sg -} - -const part = startSketchOn('XY') + let code = r#"const part = startSketchOn('XY') |> startProfileAt([0, 0], %) |> line([0,1], %) |> line([1, 0], %) diff --git a/src/wasm-lib/tests/executor/outputs/holes.png b/src/wasm-lib/tests/executor/outputs/holes.png index 75cd2820f..684a73baf 100644 Binary files a/src/wasm-lib/tests/executor/outputs/holes.png and b/src/wasm-lib/tests/executor/outputs/holes.png differ