Files
modeling-app/rust
Adam Chalmers 4f4c44e7c7 KCL: Getter for axes of planes (#7662)
## Goal

Currently, there's no way in KCL to get fields of a plane, e.g. the underlying X axis, Y axis or origin.

This would be useful for geometry calculations in KCL. It would help KCL users write transformations between planes for rotating geometry.

For example, this enables

```kcl
export fn crossProduct(@vectors) {
  a = vectors[0]
  b = vectors[1]
  x = a[1] * b[2] - (a[2] * b[1])
  y = a[2] * b[0] - (a[0] * b[2])
  z = a[0] * b[1] - (a[1] * b[0])
  return [x, y, z]
}

export fn normalOf(@plane) {
  return crossProduct([plane.xAxis, plane.yAxis])
}
```

## Implementation

My goal was just to enable a simple getter for planes, like `myPlane.xAxis` and yAxis and origins. That's nearly what happened, except I discovered that there's two ways to represent a plane: either `KclValue::Plane` or `KclValue::Object` with the right fields.

No matter which format your plane is represented as, it should behave consistently when you get its properties. Those properties should be returned as `[number; 3]` because that is how KCL represents points.

Unfortunately we actually require planes-as-objects to be defined with axes like `myPlane = { xAxis = { x = 1, y = 0, z = 0 }, ...}`, but that's a mistake in my opinion. So if you do use that representation of a plane, it should still return a [number; 3]. This required some futzing around so that we let you access object fields .x and .y as [0] and [1], which is weird, but whatever, I think it's good.

This PR is tested via planestuff.kcl which has a Rust unit test.

Part of the hole efforts, see https://github.com/KittyCAD/modeling-app/discussions/7543
2025-07-02 16:24:26 +00:00
..
2025-03-13 23:38:41 -07:00
2025-07-01 15:15:35 -04:00
2025-07-01 15:15:35 -04:00
2025-07-01 15:15:35 -04:00
2025-07-01 15:15:35 -04:00
2025-07-01 15:15:35 -04:00
2025-07-01 15:15:35 -04:00
2025-03-04 22:21:12 -08:00

Rust Crates

Releasing

  1. Make sure your working directory is this directory.
  2. Bump the versions of the crates:
    just bump-kcl-crate-versions 
    
  3. Commit the changes:
    git add .
    git commit -m "Bump versions"
    
  4. Push the changes and get your PR approved.
  5. Publish the crates:
    just publish-kcl {version}
    
    • This will publish the relevant crates and push a new tag with the prefix kcl-. DO NOT SET THE PREFIX TO kcl- when you run the command. The just command will do that for you.
    • The tag will then trigger the release of kcl-python-bindings and kcl-language-server.