Skip to content
Draft
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to the `opengeometry` package are in this file. The format f
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package follows
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Revolve accepts an optional signed `angle` in radians for exact capped partial turns.
Line-and-arc profiles retain analytic plane, cylinder, cone, sphere and torus faces.
Omitting the angle preserves the existing full-turn behavior.

## [3.0.1] - 2026-11-17

Some booleans that threw in 3.0.0 now build, and some refused pairs throw a different error.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Floorkit, a toolkit for building design, is one application built on OpenGeometr
| Area | What 3.0 has |
| --- | --- |
| **Primitives** | Wires: rectangle, circle, polyline (open or closed), line-and-arc profile, arc, regular polygon, slot, rounded rectangle. Solids: cuboid, cylinder, cylinder sector, sphere, cone or frustum, ring torus, planar polyhedron, slot prism, rounded box, pipe segment, polysolid wall along a path of straight legs and tangent arcs. Each can be placed on any plane. |
| **Operations** | Extrude a closed wire into a solid, with holes. Sweep a profile along an open or closed path of lines and arcs, each arc an exact bend, capped into a solid, open-ended into a sheet, or closed into a ring. Revolve a closed line-and-arc profile a full turn about an axis in its plane. Shell a solid into a hollow one with walls of one thickness. Union, subtract and intersect, with one to a hundred tool solids in one call. |
| **Operations** | Extrude a closed wire into a solid, with holes. Sweep a profile along an open or closed path of lines and arcs, each arc an exact bend, capped into a solid, open-ended into a sheet, or closed into a ring. Revolve a closed line-and-arc profile a full or partial turn about an axis in its plane. Shell a solid into a hollow one with walls of one thickness. Union, subtract and intersect, with one to a hundred tool solids in one call. |
| **Parametric edits** | `rebuild` gives an existing body new parameters in place. `mirror` rebuilds a body as its reflection across a plane. |
| **Assemblies** | Assemblies with parent and child placement; translate, rotate, scale and place; independent copies and shared instances. |
| **History** | Marks with rollback and release; transactions, with a dry-run option. |
Expand Down Expand Up @@ -152,7 +152,7 @@ This is a compact reference for writing OpenGeometry 3.0 code, by hand or with a
| `Wire` | `new Wire(kind, params, options?)`. `OG_PRIMITIVE_RECTANGLE` `{ width, breadth }`, `OG_PRIMITIVE_CIRCLE` `{ radius }`, `OG_PRIMITIVE_POLYLINE` `{ points, closed? }`, `OG_PRIMITIVE_REGULAR_POLYGON` `{ sides, radius }` (3 to 1024 corners on a circle about the `plane` origin, the first on the x direction), `OG_PRIMITIVE_SLOT` `{ length, width }` (the outline of `OG_PRIMITIVE_SLOT_PRISM`), `OG_PRIMITIVE_ROUNDED_RECTANGLE` `{ width, breadth, radius }` (a rectangle with rounded corners; `radius` below half the width and half the breadth). |
| Profile wire | `new Wire(OG_PRIMITIVE_PROFILE, { start, segments, closed }, options?)`. Points are `[u, v]` in `plane`; a segment is `{ to }` for a line or `{ to, arc: { center, counterClockwise } }` for an arc. A closed profile is an extrude profile or hole. |
| Arc wire | `new Wire(OG_PRIMITIVE_ARC, { radius, startAngle, sweepAngle }, options?)`. Angles in radians from the `plane` x direction, centred on the `plane` origin; the sweep is nonzero and less than one turn. |
| `Solid` | `new Solid(kind, params, options?)`. `OG_PRIMITIVE_CUBOID` `{ width, height, depth }`, `OG_PRIMITIVE_CYLINDER` `{ radius, height }`, `OG_PRIMITIVE_CYLINDER_SECTOR` `{ radius, height, startAngle, sweepAngle }` (radians from the `plane` x direction, counter-clockwise seen from the side the normal points to; sweep nonzero and less than one turn), `OG_PRIMITIVE_POLYHEDRON` `{ points, faces }` (planar faces as rings of point indices, counter-clockwise seen from outside), `OG_PRIMITIVE_SPHERE` `{ radius }` (centred on the `plane` origin), `OG_PRIMITIVE_CONE` `{ radiusBottom, radiusTop, height }` (standing on the `plane`; one radius may be zero, equal radii make a cylinder), `OG_PRIMITIVE_TORUS` `{ majorRadius, minorRadius }` (lying on the `plane`; minor below major), `OG_OPERATION_EXTRUDE` `{ profile, holes?, distance }`, `OG_OPERATION_SWEEP` `{ profile, path, caps? }`, `OG_OPERATION_REVOLVE` `{ profile, axis? }` (a full turn about `axis` `{ point: [u, v], direction: [du, dv] }` in the profile's `[u, v]`, by default its v axis), `OG_PRIMITIVE_SLOT_PRISM` `{ length, width, height }` (a stadium standing on the `plane`, centred on its origin; `length` between the arc centres along the x direction), `OG_PRIMITIVE_ROUNDED_BOX` `{ width, height, depth, radius }` (a cuboid with its four upright edges rounded; `radius` below half the width and half the depth), `OG_PRIMITIVE_PIPE_SEGMENT` `{ outerRadius, innerRadius, height, startAngle, sweepAngle }` (a ring sector placed and angled like the cylinder sector), `OG_PRIMITIVE_POLYSOLID` `{ path, width, height, justify? }` (a wall of constant width along `path`, a `{ start, segments, closed }` of straight legs and tangent arcs in the `plane`'s `[u, v]`, standing on the `plane` and rising along its normal; `justify` is `'centre'` (default), `'left'` or `'right'` of the path direction); `profile`, `holes` and `path` are wires. |
| `Solid` | `new Solid(kind, params, options?)`. `OG_PRIMITIVE_CUBOID` `{ width, height, depth }`, `OG_PRIMITIVE_CYLINDER` `{ radius, height }`, `OG_PRIMITIVE_CYLINDER_SECTOR` `{ radius, height, startAngle, sweepAngle }` (radians from the `plane` x direction, counter-clockwise seen from the side the normal points to; sweep nonzero and less than one turn), `OG_PRIMITIVE_POLYHEDRON` `{ points, faces }` (planar faces as rings of point indices, counter-clockwise seen from outside), `OG_PRIMITIVE_SPHERE` `{ radius }` (centred on the `plane` origin), `OG_PRIMITIVE_CONE` `{ radiusBottom, radiusTop, height }` (standing on the `plane`; one radius may be zero, equal radii make a cylinder), `OG_PRIMITIVE_TORUS` `{ majorRadius, minorRadius }` (lying on the `plane`; minor below major), `OG_OPERATION_EXTRUDE` `{ profile, holes?, distance }`, `OG_OPERATION_SWEEP` `{ profile, path, caps? }`, `OG_OPERATION_REVOLVE` `{ profile, axis?, angle? }` (`angle` is signed radians with magnitude up to one turn, defaults to `2 * Math.PI`, and follows the right-hand rule about `axis` `{ point: [u, v], direction: [du, dv] }` in the profile's `[u, v]`, by default its v axis), `OG_PRIMITIVE_SLOT_PRISM` `{ length, width, height }` (a stadium standing on the `plane`, centred on its origin; `length` between the arc centres along the x direction), `OG_PRIMITIVE_ROUNDED_BOX` `{ width, height, depth, radius }` (a cuboid with its four upright edges rounded; `radius` below half the width and half the depth), `OG_PRIMITIVE_PIPE_SEGMENT` `{ outerRadius, innerRadius, height, startAngle, sweepAngle }` (a ring sector placed and angled like the cylinder sector), `OG_PRIMITIVE_POLYSOLID` `{ path, width, height, justify? }` (a wall of constant width along `path`, a `{ start, segments, closed }` of straight legs and tangent arcs in the `plane`'s `[u, v]`, standing on the `plane` and rising along its normal; `justify` is `'centre'` (default), `'left'` or `'right'` of the path direction); `profile`, `holes` and `path` are wires. |
| `Sheet` | `new Sheet(OG_OPERATION_SWEEP, { profile, path, caps: false })`: an open-ended sweep, faces that enclose no volume. It shows its surface, from the front only, and its outline; `OpenGeometry.exportStep` refuses it. |
| Body options | `{ ogId?, parent?, appearance?, plane? }`. `plane` is `{ origin?, normal?, xDirection? }` and applies to primitives only; by default it is the ground plane through the origin, normal `[0, 1, 0]`, x direction `[1, 0, 0]`. |
| Booleans | `solid.operate(kind, { tools, instances? })` with `OG_OPERATION_SUBTRACT`, `OG_OPERATION_UNION` or `OG_OPERATION_INTERSECT`; `tools` is one to a hundred solids. |
Expand Down
2 changes: 1 addition & 1 deletion docs/opengeometry/api/constants.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Each helper returns its argument unchanged. It only gives the object a type, so
| `OG_PRIMITIVE_PARAMS_POLYSOLID` | `PolysolidParams` |
| `OG_OPERATION_PARAMS_EXTRUDE` | `{ profile, holes?, distance }` |
| `OG_OPERATION_PARAMS_SWEEP` | `{ profile, path, caps? }` |
| `OG_OPERATION_PARAMS_REVOLVE` | `{ profile, axis? }` |
| `OG_OPERATION_PARAMS_REVOLVE` | `{ profile, axis?, angle? }` |
| `OG_PRIMITIVE_PARAMS_SLOT_PRISM` | `SlotPrismParams` |
| `OG_PRIMITIVE_PARAMS_ROUNDED_BOX` | `RoundedBoxParams` |
| `OG_PRIMITIVE_PARAMS_PIPE_SEGMENT` | `PipeSegmentParams` |
Expand Down
2 changes: 1 addition & 1 deletion docs/opengeometry/api/solid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ console.log(base.getReport()?.report.operation);
| `OG_PRIMITIVE_POLYHEDRON` | `{ points, faces }` |
| `OG_OPERATION_EXTRUDE` | `{ profile, holes?, distance }` |
| `OG_OPERATION_SWEEP` | `{ profile, path, caps? }` |
| `OG_OPERATION_REVOLVE` | `{ profile, axis? }` |
| `OG_OPERATION_REVOLVE` | `{ profile, axis?, angle? }` |
| `OG_PRIMITIVE_SLOT_PRISM` | `{ length, width, height }` |
| `OG_PRIMITIVE_ROUNDED_BOX` | `{ width, height, depth, radius }` |
| `OG_PRIMITIVE_PIPE_SEGMENT` | `{ outerRadius, innerRadius, height, startAngle, sweepAngle }` |
Expand Down
10 changes: 7 additions & 3 deletions docs/opengeometry/guides/revolve.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
---
title: Revolve
description: Turn a closed line-and-arc profile a full turn about an axis in its plane.
description: Turn a closed line-and-arc profile a full or partial turn about an axis in its plane.
icon: rotate
---

`OG_OPERATION_REVOLVE` turns a closed profile a full turn into a solid. The parameters are `{ profile, axis? }`:
`OG_OPERATION_REVOLVE` turns a closed profile into a solid. The parameters are `{ profile, axis?, angle? }`:

- `angle`: signed radians, nonzero and at most one full turn in magnitude. The default is `2 * Math.PI`. Positive angles follow the right-hand rule about the axis direction; negative angles reverse it. Partial turns retain the start profile and add exact planar end caps.
- `profile`: a closed `OG_PRIMITIVE_PROFILE` wire.
- `axis`: `{ point: [u, v], direction: [du, dv] }` in the profile's own `[u, v]`. By default it is `{ point: [0, 0], direction: [0, 1] }`, the profile plane's v axis.

Each profile edge off the axis becomes one plane, cylinder, cone, sphere or ring torus face. An edge on the axis makes no face.

`OG_SUPPORTS_PARTIAL_REVOLVE` is `true` in SDK builds with this angle parameter. Older builds lack the flag. Pair the SDK with its matching WASM: an older kernel rejects an angle parameter instead of building a full turn.

## A bowl

On the default ground plane, the v axis runs along −Z, so the solid would lie on its side. Draw the profile on an upright plane instead, with u as the radius and v as the height. The bowl then stands upright about the Y axis:
Expand Down Expand Up @@ -57,9 +60,10 @@ These throw `InvalidParameter`:
- A profile that crosses the axis, touches it at a single point, or meets it along two separate stretches.
- An arc whose circle meets the axis.
- A zero `direction`.
- A zero, nonfinite or greater-than-one-turn `angle`.
- A partial angle whose start/end cap separation is below the kernel geometric accuracy. Such an angle is refused rather than rounded to zero or a full turn.

Not built:

- A partial turn. There is no sweep angle; every revolve is a full turn.
- A profile with holes. `OG_OPERATION_REVOLVE` takes no `holes`.
- The shell of a full-turn revolve throws `CoverageGap`.
2 changes: 1 addition & 1 deletion docs/opengeometry/what-is-opengeometry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ It also fits AI-assisted CAD. An assistant or an agent proposes the modelling st
| Area | What you get |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Primitives | Wires: rectangle, circle, polyline, line-and-arc profile, arc. Solids: cuboid, cylinder, cylinder sector, sphere, cone or frustum, ring torus, planar polyhedron. Each goes on any plane. |
| Operations | Extrude with holes. Sweep along lines and arcs into a solid, an open sheet or a closed ring. Revolve a full turn. Shell a solid. Union, subtract and intersect with one to a hundred tools. |
| Operations | Extrude with holes. Sweep along lines and arcs into a solid, an open sheet or a closed ring. Revolve a full or partial turn. Shell a solid. Union, subtract and intersect with one to a hundred tools. |
| Parametric edits | `rebuild` gives a body new parameters in place. `mirror` reflects a body across a plane. |
| Assemblies | Parent and child placement, translate, rotate, scale and place, independent copies and shared instances. |
| History | Marks with rollback and release, and transactions with a dry run. |
Expand Down
13 changes: 11 additions & 2 deletions main/opengeometry-three/src/constants/operations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const OG_OPERATION_EXTRUDE = 'Extrude' as const;
export const OG_OPERATION_SWEEP = 'Sweep' as const;
export const OG_OPERATION_REVOLVE = 'Revolve' as const;
export const OG_SUPPORTS_PARTIAL_REVOLVE = true as const;
export const OG_OPERATION_UNION = 'Union' as const;
export const OG_OPERATION_SUBTRACT = 'Subtract' as const;
export const OG_OPERATION_INTERSECT = 'Intersect' as const;
Expand All @@ -13,5 +14,13 @@ export const OG_OPERATION_PARAMS_SWEEP = (
value: { profile: { ogId: string }; path: { ogId: string }; caps?: boolean },
): { profile: { ogId: string }; path: { ogId: string }; caps?: boolean } => value;
export const OG_OPERATION_PARAMS_REVOLVE = (
value: { profile: { ogId: string }; axis?: { point: [number, number]; direction: [number, number] } },
): { profile: { ogId: string }; axis?: { point: [number, number]; direction: [number, number] } } => value;
value: {
profile: { ogId: string };
angle?: number;
axis?: { point: [number, number]; direction: [number, number] };
},
): {
profile: { ogId: string };
angle?: number;
axis?: { point: [number, number]; direction: [number, number] };
} => value;
47 changes: 47 additions & 0 deletions main/opengeometry-three/tests/node/revolve.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
import { test } from 'node:test';
import {
OpenGeometry, Solid, Wire, OG_OPERATION_PARAMS_REVOLVE, OG_OPERATION_REVOLVE, OG_PRIMITIVE_PROFILE,
OG_SUPPORTS_PARTIAL_REVOLVE,
} from '../../../dist/index.js';
import { boot, failsWith } from './support.mjs';

Expand Down Expand Up @@ -92,3 +93,49 @@ test('a revolve with holes is refused as InvalidParameter', async () => {
const hole = upright(polygon([[1.5, 0.5], [2.5, 0.5], [2.5, 1.5], [1.5, 1.5]]));
assert.throws(() => new Solid(OG_OPERATION_REVOLVE, { profile, holes: [hole] }), failsWith('InvalidParameter'));
});

test('signed partial revolutions retain exact rounded sides, caps and STEP topology', async () => {
await boot();
assert.equal(OG_SUPPORTS_PARTIAL_REVOLVE, true);
const profile = upright({
start: [1.025, 0],
segments: [
{ to: [1, 0] },
{ to: [0.99, -0.01], arc: { center: [1, -0.01], counterClockwise: true } },
{ to: [0.99, -0.03] },
{ to: [1, -0.04], arc: { center: [1, -0.03], counterClockwise: true } },
{ to: [1.025, -0.04] },
{ to: [1.025, 0] },
],
closed: true,
});
for (const degrees of [90, 270, 360, -90, -270, -360]) {
const angle = degrees * Math.PI / 180;
const part = new Solid(
OG_OPERATION_REVOLVE, OG_OPERATION_PARAMS_REVOLVE({ profile, angle }), { ogId: `round-${degrees}` },
);
const brep = part.getBrep();
assert.equal(brep.topology.faces.length, Math.abs(degrees) === 360 ? 6 : 8);
const { text, report } = await OpenGeometry.exportStep({ nodes: [part], unit: 'metre' });
assert.equal(report.solids, 1);
assert.equal(report.pcurvelessEdges, 0);
assert.equal(surfaces(text, 'TOROIDAL_SURFACE('), 2);
assert.equal(part.lastInfo.bodyType, 'Solid');
}
});

test('partial revolve sign chooses the intended side and rejected edits preserve the old solid', async () => {
await boot();
const profile = upright(polygon([[1, 0], [2, 0], [2, 1], [1, 1]]));
const quarter = new Solid(OG_OPERATION_REVOLVE, { profile, angle: Math.PI / 2 });
assert.equal(quarter.classifyPoint([1, -1, -0.5]), 'Inside');
assert.equal(quarter.classifyPoint([1, 1, -0.5]), 'Outside');
const negative = new Solid(OG_OPERATION_REVOLVE, { profile, angle: -Math.PI / 2 });
assert.equal(negative.classifyPoint([1, 1, -0.5]), 'Inside');
assert.equal(negative.classifyPoint([1, -1, -0.5]), 'Outside');
const old = quarter.getBrep();
for (const angle of [0, 2 * Math.PI + 0.1, -2 * Math.PI - 0.1, 1e-12, 2 * Math.PI - 1e-12]) {
assert.throws(() => quarter.rebuild(OG_OPERATION_REVOLVE, { profile, angle }), failsWith('InvalidParameter'));
assert.deepEqual(quarter.getBrep(), old);
}
});
23 changes: 17 additions & 6 deletions main/opengeometry/src/operations/creating/revolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ pub(crate) struct Axis {
pub(crate) fn build(
id: String,
profile: ProfileLoop,
axis: Axis,
mut axis: Axis,
angle: f64,
accuracy: Accuracy,
) -> Result<BrepEnvelope, OperationError> {
if !angle.is_finite() || angle == 0.0 || angle.abs() > std::f64::consts::TAU {
return Err(invalid(
"revolve angle must be nonzero, finite, and no greater than a full turn",
));
}
if angle < 0.0 {
axis.direction = scale(axis.direction, -1.0);
}
let g = accuracy.geometric;
let plane = profile_frame(&profile, g)?;
let frame = revolve_frame(&profile, plane, axis)?;
let profile_edges = edges(&profile, meridian(frame.origin, frame.x, frame.z));
primitives::revolved_profile(id, frame, profile_edges, accuracy).map_err(|error| match error {
GeometryError::InvalidGeometry(message)
| GeometryError::UnresolvedIntersection(message) => invalid(message),
other => other.into(),
})
primitives::partially_revolved_profile(id, frame, profile_edges, angle.abs(), accuracy).map_err(
|error| match error {
GeometryError::InvalidGeometry(message)
| GeometryError::UnresolvedIntersection(message) => invalid(message),
other => other.into(),
},
)
}

fn revolve_frame(
Expand Down
2 changes: 1 addition & 1 deletion main/opengeometry/src/primitives/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ pub use frustum::frustum;
pub use linear_extrusion::linear_extrusion;
pub use outlines::{ring_sector_outline, rounded_rectangle_outline, slot_outline};
pub use polysolid::{polysolid, PolysolidError, PolysolidJustify, PolysolidPath};
pub use revolved_profile::revolved_profile;
pub use revolved_profile::{partially_revolved_profile, revolved_profile};
pub use sphere::sphere;
pub use torus::torus;
3 changes: 3 additions & 0 deletions main/opengeometry/src/primitives/internal/revolved_profile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod partial;
pub use partial::partially_revolved_profile;

use crate::brep::{
boundary, plane_boundary, unit, uv_line, Accuracy, BrepEnvelope, Builder, CurveGeometry,
EdgeGeometry, Frame3, GeometryError, Orientation, Surface, SurfaceGeometry, Use,
Expand Down
Loading
Loading