Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Sketch.value to Sketch.paths #4272

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,328 changes: 664 additions & 664 deletions docs/kcl/std.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/kcl/types/Sketch.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ A sketch is a collection of paths.

| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes. | No |
| `value` |`[` [`Path`](/docs/kcl/types/Path) `]`| The paths in the sketch. | No |
| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes). | No |
| `paths` |`[` [`Path`](/docs/kcl/types/Path) `]`| The paths in the sketch. | No |
| `on` |[`SketchSurface`](/docs/kcl/types/SketchSurface)| What the sketch is on (can be a plane or a face). | No |
| `start` |[`BasePath`](/docs/kcl/types/BasePath)| The starting path. | No |
| `tags` |`object`| Tag identifiers that have been declared in this sketch. | No |
Expand Down
4 changes: 2 additions & 2 deletions docs/kcl/types/SketchSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ A sketch is a collection of paths.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `type` |enum: `sketch`| | No |
| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes. | No |
| `value` |`[` [`Path`](/docs/kcl/types/Path) `]`| The paths in the sketch. | No |
| `id` |`string`| The id of the sketch (this will change when the engine's reference to it changes). | No |
| `paths` |`[` [`Path`](/docs/kcl/types/Path) `]`| The paths in the sketch. | No |
| `on` |[`SketchSurface`](/docs/kcl/types/SketchSurface)| What the sketch is on (can be a plane or a face). | No |
| `start` |[`BasePath`](/docs/kcl/types/BasePath)| The starting path. | No |
| `tags` |`object`| Tag identifiers that have been declared in this sketch. | No |
Expand Down
34 changes: 17 additions & 17 deletions src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export class SceneEntities {
if (err(sketch)) return Promise.reject(sketch)
if (!sketch) return Promise.reject('sketch not found')

if (!isArray(sketch?.value))
if (!isArray(sketch?.paths))
return {
truncatedAst,
programMemoryOverride,
Expand Down Expand Up @@ -435,7 +435,7 @@ export class SceneEntities {
maybeModdedAst,
sketch.start.__geoMeta.sourceRange
)
if (sketch?.value?.[0]?.type !== 'Circle') {
if (sketch?.paths?.[0]?.type !== 'Circle') {
const _profileStart = createProfileStartHandle({
from: sketch.start.from,
id: sketch.start.__geoMeta.id,
Expand All @@ -451,16 +451,16 @@ export class SceneEntities {
this.activeSegments[JSON.stringify(segPathToNode)] = _profileStart
}
const callbacks: (() => SegmentOverlayPayload | null)[] = []
sketch.value.forEach((segment, index) => {
sketch.paths.forEach((segment, index) => {
let segPathToNode = getNodePathFromSourceRange(
maybeModdedAst,
segment.__geoMeta.sourceRange
)
if (
draftExpressionsIndices &&
(sketch.value[index - 1] || sketch.start)
(sketch.paths[index - 1] || sketch.start)
) {
const previousSegment = sketch.value[index - 1] || sketch.start
const previousSegment = sketch.paths[index - 1] || sketch.start
const previousSegmentPathToNode = getNodePathFromSourceRange(
maybeModdedAst,
previousSegment.__geoMeta.sourceRange
Expand Down Expand Up @@ -511,7 +511,7 @@ export class SceneEntities {
to: segment.to,
}
const result = initSegment({
prevSegment: sketch.value[index - 1],
prevSegment: sketch.paths[index - 1],
callExpName,
input,
id: segment.__geoMeta.id,
Expand Down Expand Up @@ -610,9 +610,9 @@ export class SceneEntities {
variableDeclarationName
)
if (err(sg)) return Promise.reject(sg)
const lastSeg = sg?.value?.slice(-1)[0] || sg.start
const lastSeg = sg?.paths?.slice(-1)[0] || sg.start

const index = sg.value.length // because we've added a new segment that's not in the memory yet, no need for `-1`
const index = sg.paths.length // because we've added a new segment that's not in the memory yet, no need for `-1`
const mod = addNewSketchLn({
node: _ast,
programMemory: kclManager.programMemory,
Expand Down Expand Up @@ -654,7 +654,7 @@ export class SceneEntities {

let modifiedAst
if (profileStart) {
const lastSegment = sketch.value.slice(-1)[0]
const lastSegment = sketch.paths.slice(-1)[0]
modifiedAst = addCallExpressionsToPipe({
node: kclManager.ast,
programMemory: kclManager.programMemory,
Expand Down Expand Up @@ -686,7 +686,7 @@ export class SceneEntities {
})
if (trap(modifiedAst)) return Promise.reject(modifiedAst)
} else if (intersection2d) {
const lastSegment = sketch.value.slice(-1)[0]
const lastSegment = sketch.paths.slice(-1)[0]
const tmp = addNewSketchLn({
node: kclManager.ast,
programMemory: kclManager.programMemory,
Expand Down Expand Up @@ -817,7 +817,7 @@ export class SceneEntities {
variableDeclarationName
)
if (err(sketch)) return Promise.reject(sketch)
const sgPaths = sketch.value
const sgPaths = sketch.paths
const orthoFactor = orthoScale(sceneInfra.camControls.camera)

this.updateSegment(sketch.start, 0, 0, _ast, orthoFactor, sketch)
Expand Down Expand Up @@ -868,7 +868,7 @@ export class SceneEntities {
variableDeclarationName
)
if (err(sketch)) return
const sgPaths = sketch.value
const sgPaths = sketch.paths
const orthoFactor = orthoScale(sceneInfra.camControls.camera)

// Update the starting segment of the THREEjs scene
Expand Down Expand Up @@ -985,7 +985,7 @@ export class SceneEntities {
variableDeclarationName
)
if (err(sketch)) return
const sgPaths = sketch.value
const sgPaths = sketch.paths
const orthoFactor = orthoScale(sceneInfra.camControls.camera)

this.updateSegment(sketch.start, 0, 0, _ast, orthoFactor, sketch)
Expand Down Expand Up @@ -1105,7 +1105,7 @@ export class SceneEntities {

const pipeIndex = pathToNode[pathToNodeIndex + 1][0] as number
if (addingNewSegmentStatus === 'nothing') {
const prevSegment = sketch.value[pipeIndex - 2]
const prevSegment = sketch.paths[pipeIndex - 2]
const mod = addNewSketchLn({
node: kclManager.ast,
programMemory: kclManager.programMemory,
Expand Down Expand Up @@ -1345,7 +1345,7 @@ export class SceneEntities {
}
if (!sketch) return

const sgPaths = sketch.value
const sgPaths = sketch.paths
const orthoFactor = orthoScale(sceneInfra.camControls.camera)

this.updateSegment(
Expand Down Expand Up @@ -1393,7 +1393,7 @@ export class SceneEntities {
modifiedAst,
segment.__geoMeta.sourceRange
)
const sgPaths = sketch.value
const sgPaths = sketch.paths
const originalPathToNodeStr = JSON.stringify(segPathToNode)
segPathToNode[1][0] = varDecIndex
const pathToNodeStr = JSON.stringify(segPathToNode)
Expand Down Expand Up @@ -1701,7 +1701,7 @@ function prepareTruncatedMemoryAndAst(
variableDeclarationName
)
if (err(sg)) return sg
const lastSeg = sg?.value.slice(-1)[0]
const lastSeg = sg?.paths.slice(-1)[0]
if (draftSegment) {
// truncatedAst needs to setup with another segment at the end
let newSegment
Expand Down
4 changes: 2 additions & 2 deletions src/clientSideScene/segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { err } from 'lib/trap'

interface CreateSegmentArgs {
input: SegmentInputs
prevSegment: Sketch['value'][number]
prevSegment: Sketch['paths'][number]
id: string
pathToNode: PathToNode
isDraftSegment?: boolean
Expand All @@ -72,7 +72,7 @@ interface CreateSegmentArgs {

interface UpdateSegmentArgs {
input: SegmentInputs
prevSegment: Sketch['value'][number]
prevSegment: Sketch['paths'][number]
group: Group
sceneInfra: SceneInfra
scale?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const processMemory = (programMemory: ProgramMemory) => {
return rest
})
} else if (!err(sg)) {
processedMemory[key] = sg.value.map(({ __geoMeta, ...rest }: Path) => {
processedMemory[key] = sg.paths.map(({ __geoMeta, ...rest }: Path) => {
return rest
})
} else if ((val.type as any) === 'Function') {
Expand Down
8 changes: 4 additions & 4 deletions src/lang/artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const mySketch001 = startSketchOn('XY')
sourceRange: [46, 71],
},
},
value: [
paths: [
{
type: 'ToPoint',
tag: null,
Expand Down Expand Up @@ -96,7 +96,7 @@ const mySketch001 = startSketchOn('XY')
on: expect.any(Object),
start: expect.any(Object),
type: 'Sketch',
value: [
paths: [
{
type: 'ToPoint',
from: [0, 0],
Expand Down Expand Up @@ -202,7 +202,7 @@ const sk2 = startSketchOn('XY')
info: expect.any(Object),
},
},
value: [
paths: [
{
type: 'ToPoint',
from: [0, 0],
Expand Down Expand Up @@ -294,7 +294,7 @@ const sk2 = startSketchOn('XY')
info: expect.any(Object),
},
},
value: [
paths: [
{
type: 'ToPoint',
from: [0, 0],
Expand Down
12 changes: 6 additions & 6 deletions src/lang/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const newVar = myVar + 1`
`
const mem = await exe(code)
// geo is three js buffer geometry and is very bloated to have in tests
const minusGeo = mem.get('mySketch')?.value?.value
const minusGeo = mem.get('mySketch')?.value?.paths
expect(minusGeo).toEqual([
{
type: 'ToPoint',
Expand Down Expand Up @@ -175,7 +175,7 @@ const newVar = myVar + 1`
info: expect.any(Object),
},
},
value: [
paths: [
{
type: 'ToPoint',
to: [1, 1],
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('testing math operators', () => {
const mem = await exe(code)
const sketch = sketchFromKclValue(mem.get('part001'), 'part001')
// result of `-legLen(5, min(3, 999))` should be -4
const yVal = (sketch as Sketch).value?.[0]?.to?.[1]
const yVal = (sketch as Sketch).paths?.[0]?.to?.[1]
expect(yVal).toBe(-4)
})
it('test that % substitution feeds down CallExp->ArrExp->UnaryExp->CallExp', async () => {
Expand All @@ -385,8 +385,8 @@ describe('testing math operators', () => {
const mem = await exe(code)
const sketch = sketchFromKclValue(mem.get('part001'), 'part001')
// expect -legLen(segLen('seg01'), myVar) to equal -4 setting the y value back to 0
expect((sketch as Sketch).value?.[1]?.from).toEqual([3, 4])
expect((sketch as Sketch).value?.[1]?.to).toEqual([6, 0])
expect((sketch as Sketch).paths?.[1]?.from).toEqual([3, 4])
expect((sketch as Sketch).paths?.[1]?.to).toEqual([6, 0])
const removedUnaryExp = code.replace(
`-legLen(segLen(seg01), myVar)`,
`legLen(segLen(seg01), myVar)`
Expand All @@ -398,7 +398,7 @@ describe('testing math operators', () => {
)

// without the minus sign, the y value should be 8
expect((removedUnaryExpMemSketch as Sketch).value?.[1]?.to).toEqual([6, 8])
expect((removedUnaryExpMemSketch as Sketch).paths?.[1]?.to).toEqual([6, 8])
})
it('with nested callExpression and binaryExpression', async () => {
const code = 'const myVar = 2 + min(100, -1 + legLen(5, 3))'
Expand Down
2 changes: 1 addition & 1 deletion src/lang/queryAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ export function isLinesParallelAndConstrained(
constraintType === 'angle' || constraintLevel === 'full'

// get the previous segment
const prevSegment = sg.value[secondaryIndex - 1]
const prevSegment = sg.paths[secondaryIndex - 1]
const prevSourceRange = prevSegment.__geoMeta.sourceRange

const isParallelAndConstrained =
Expand Down
4 changes: 2 additions & 2 deletions src/lang/std/sketch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ARC_SEGMENT_ERR = new Error('Invalid input, expected "arc-segment"')
export type Coords2d = [number, number]

export function getCoordsFromPaths(skGroup: Sketch, index = 0): Coords2d {
const currentPath = skGroup?.value?.[index]
const currentPath = skGroup?.paths?.[index]
if (!currentPath && skGroup?.start) {
return skGroup.start.to
} else if (!currentPath) {
Expand Down Expand Up @@ -1704,7 +1704,7 @@ export const angledLineThatIntersects: SketchLineHelper = {
varName
)
if (err(sketch)) return sketch
const intersectPath = sketch.value.find(
const intersectPath = sketch.paths.find(
({ tag }: Path) => tag && tag.value === intersectTagName
)
let offset = 0
Expand Down
8 changes: 4 additions & 4 deletions src/lang/std/sketchConstraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getSketchSegmentFromPathToNode(
pathToNode: PathToNode
):
| {
segment: Sketch['value'][number]
segment: Sketch['paths'][number]
index: number
}
| Error {
Expand All @@ -39,15 +39,15 @@ export function getSketchSegmentFromSourceRange(
[rangeStart, rangeEnd]: SourceRange
):
| {
segment: Sketch['value'][number]
segment: Sketch['paths'][number]
index: number
}
| Error {
const lineIndex = sketch.value.findIndex(
const lineIndex = sketch.paths.findIndex(
({ __geoMeta: { sourceRange } }: Path) =>
sourceRange[0] <= rangeStart && sourceRange[1] >= rangeEnd
)
const line = sketch.value[lineIndex]
const line = sketch.paths[lineIndex]
if (line) {
return {
segment: line,
Expand Down
2 changes: 1 addition & 1 deletion src/lang/std/sketchcombos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ export function transformAstSketchLines({
if (err(_segment)) return _segment
referencedSegment = _segment.segment
} else {
referencedSegment = sketch.value.find(
referencedSegment = sketch.paths.find(
(path) => path.tag?.value === _referencedSegmentName
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/wasm-lib/kcl/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,10 +1137,10 @@ pub struct TagEngineInfo {
#[ts(export)]
#[serde(tag = "type", rename_all = "camelCase")]
pub struct Sketch {
/// The id of the sketch (this will change when the engine's reference to it changes.
/// The id of the sketch (this will change when the engine's reference to it changes).
pub id: uuid::Uuid,
/// The paths in the sketch.
pub value: Vec<Path>,
pub paths: Vec<Path>,
/// What the sketch is on (can be a plane or a face).
pub on: SketchSurface,
/// The starting path.
Expand Down Expand Up @@ -1215,7 +1215,7 @@ impl Sketch {

/// Get the path most recently sketched.
pub(crate) fn latest_path(&self) -> Option<&Path> {
self.value.last()
self.paths.last()
}

/// The "pen" is an imaginary pen drawing the path.
Expand Down
6 changes: 3 additions & 3 deletions src/wasm-lib/kcl/src/std/extrude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ pub(crate) async fn do_post_extrude(
)
.await?;

if sketch.value.is_empty() {
if sketch.paths.is_empty() {
return Err(KclError::Type(KclErrorDetails {
message: "Expected a non-empty sketch".to_string(),
source_ranges: vec![args.source_range],
}));
}

let edge_id = sketch.value.iter().find_map(|segment| match segment {
let edge_id = sketch.paths.iter().find_map(|segment| match segment {
Path::ToPoint { base } | Path::Circle { base, .. } => Some(base.geo_meta.id),
_ => None,
});
Expand Down Expand Up @@ -229,7 +229,7 @@ pub(crate) async fn do_post_extrude(
} = analyze_faces(exec_state, &args, face_infos);
// Iterate over the sketch.value array and add face_id to GeoMeta
let new_value = sketch
.value
.paths
.iter()
.flat_map(|path| {
if let Some(Some(actual_face_id)) = face_id_map.get(&path.get_base().geo_meta.id) {
Expand Down
Loading
Loading