Skip to content

Commit

Permalink
✨ feat: Added numerous curve APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed May 28, 2024
1 parent c1be0e6 commit 47768af
Show file tree
Hide file tree
Showing 13 changed files with 588 additions and 34 deletions.
67 changes: 63 additions & 4 deletions packages/chili-core/src/shape/curve.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,79 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license.

import { Plane, XYZ } from "../math";
import { Plane, Ray, XYZ } from "../math";
import { CurveType } from "./shape";

export enum Continuity {
C0,
G1,
C1,
G2,
C2,
C3,
CN,
}

export interface ICurve {
get curveType(): CurveType;
parameter(point: XYZ): number;
firstParameter(): number;
lastParameter(): number;
point(parameter: number): XYZ;
project(point: XYZ): XYZ[];
value(parameter: number): XYZ;
isCN(n: number): boolean;
d0(u: number): XYZ;
d1(u: number): { point: XYZ; vec: XYZ };
d2(u: number): { point: XYZ; vec1: XYZ; vec2: XYZ };
d3(u: number): { point: XYZ; vec1: XYZ; vec2: XYZ; vec3: XYZ };
dn(u: number, n: number): XYZ;
reversed(): ICurve;
nearestPoint(point: XYZ): XYZ;
isClosed(): boolean;
period(): number;
isPeriodic(): boolean;
continutity(): Continuity;
}

export interface ILine extends ICurve {
direction: XYZ;
}

export interface IConic extends ICurve {
plane: Plane;
axis: XYZ;
xAxis: XYZ;
yAxis: XYZ;
eccentricity(): number;
}

export interface ICircle extends IConic {
center: XYZ;
radius: number;
}

export interface IEllipse extends IConic {
area(): number;
center: XYZ;
get focus1(): XYZ;
get focus2(): XYZ;
majorRadius: number;
minorRadius: number;
}

export interface IHyperbola extends IConic {
focal(): number;
location: XYZ;
get focus1(): XYZ;
get focus2(): XYZ;
majorRadius: number;
minorRadius: number;
}

export interface IParabola extends IConic {
focal(): number;
get focus(): XYZ;
get directrix(): XYZ;
}

export interface IBoundedCurve extends ICurve {
startPoint(): XYZ;
endPoint(): XYZ;
Expand All @@ -50,6 +92,18 @@ export interface IBezierCurve extends IBoundedCurve {
poles(): XYZ[];
}

export interface IBSplineCurve extends IBoundedCurve {
degree(): number;
nbKnots(): number;
knot(index: number): number;
setKnot(index: number, value: number): void;
nbPoles(): number;
pole(index: number): XYZ;
poles(): XYZ[];
weight(index: number): number;
setWeight(index: number, value: number): void;
}

export interface ITrimmedCurve extends IBoundedCurve {
basisCurve(): ICurve;
}
Expand All @@ -60,10 +114,15 @@ export interface IOffsetCurve extends ICurve {
direction(): XYZ;
}

export interface IComplexCurve {
nbCurves(): number;
curve(index: number): ICurve;
}

export namespace ICurve {
export function isConic(curve: ICurve): curve is IConic {
let conic = curve as IConic;
return conic.plane !== undefined;
return conic.axis !== undefined;
}

export function isCircle(curve: ICurve): curve is ICircle {
Expand Down
6 changes: 5 additions & 1 deletion packages/chili-core/src/shape/shape.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license.

import { Result } from "../foundation";
import { Matrix4, Ray, XYZ } from "../math";
import { Matrix4, Plane, Ray, XYZ } from "../math";
import { ITrimmedCurve } from "./curve";
import { IShapeMeshData } from "./meshData";
import { ShapeType } from "./shapeType";
Expand Down Expand Up @@ -61,6 +61,10 @@ export interface IShape {
findAncestor(ancestorType: ShapeType, fromShape: IShape): IShape[];
findSubShapes(subshapeType: ShapeType): IShape[];
iterSubShapes(shapeType: ShapeType, unique: boolean): IterableIterator<IShape>;
section(shape: IShape | Plane): IShape;
split(edges: (IEdge | IWire)[]): IShape;
splitWithFace(onFace: IFace, edges: IEdge | IWire): IShape;
splitWithEdge(onEdge: IEdge, edge: IEdge): IShape;
}

export interface IVertex extends IShape {}
Expand Down
8 changes: 4 additions & 4 deletions packages/chili-geo/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class GeoUtils {

private static curveNormal = (curve: ICurve) => {
if (ICurve.isConic(curve)) {
return curve.plane.normal;
return curve.axis;
}
let vec = curve.dn(0, 1);
if (vec.isParallelTo(XYZ.unitX)) return XYZ.unitZ;
Expand All @@ -42,13 +42,13 @@ export class GeoUtils {

static findNextEdge(wire: IWire, edge: IEdge): Result<IEdge> {
let curve = edge.asCurve();
let point = curve.point(curve.lastParameter());
let point = curve.value(curve.lastParameter());
for (const e of wire.iterSubShapes(ShapeType.Edge, true)) {
if (e.isEqual(edge)) continue;
let testCurve = (e as IEdge).asCurve();
if (
point.distanceTo(testCurve.point(testCurve.firstParameter())) < Precision.Distance ||
point.distanceTo(testCurve.point(testCurve.lastParameter())) < Precision.Distance
point.distanceTo(testCurve.value(testCurve.firstParameter())) < Precision.Distance ||
point.distanceTo(testCurve.value(testCurve.lastParameter())) < Precision.Distance
) {
return Result.ok(e as IEdge);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/chili-occ/occ-wasm/build_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mainBuild:
- symbol: BRepPrimAPI_MakeTorus
- symbol: BRepTools
- symbol: BRepTools_ReShape
- symbol: BRepTools_Quilt
- symbol: ChFi3d_FilletShape
- symbol: ChFiDS_ChamfMode
- symbol: Convert_ParameterisationType
Expand All @@ -94,6 +95,9 @@ mainBuild:
- symbol: Geom_Conic
- symbol: Geom_CylindricalSurface
- symbol: Geom_ElementarySurface
- symbol: Geom_Ellipse
- symbol: Geom_Hyperbola
- symbol: Geom_Parabola
- symbol: GeomFill_Trihedron
- symbol: Geom_Geometry
- symbol: Geom_Line
Expand Down Expand Up @@ -160,6 +164,7 @@ mainBuild:
- symbol: MoniTool_TypedValue
- symbol: NCollection_BaseList
- symbol: NCollection_BaseMap
- symbol: NCollection_BaseSequence
- symbol: Poly_Array1OfTriangle
- symbol: Poly_Connect
- symbol: Poly_PolygonOnTriangulation
Expand Down Expand Up @@ -209,6 +214,7 @@ mainBuild:
- symbol: TopoDS_Vertex
- symbol: TopoDS_Wire
- symbol: TopTools_ListOfShape
- symbol: TopTools_SequenceOfShape
- symbol: TopTools_IndexedMapOfShape
- symbol: TopTools_IndexedDataMapOfShapeListOfShape
- symbol: XSControl_Reader
Expand Down
Loading

0 comments on commit 47768af

Please sign in to comment.