Skip to content

Commit

Permalink
Add support for pointAt in curves
Browse files Browse the repository at this point in the history
  • Loading branch information
sgenoud committed Oct 18, 2024
1 parent 6d44718 commit 4c667bc
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions packages/replicad/src/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,53 +563,35 @@ export abstract class _1DShape<Type extends TopoDS_Shape> extends Shape<Type> {
}

get startPoint(): Vector {
const curve = this.curve;
const outval = curve.startPoint;
curve.delete();
return outval;
return this.curve.startPoint;
}

get endPoint(): Vector {
const curve = this.curve;
const outval = curve.endPoint;
curve.delete();
return outval;
return this.curve.endPoint;
}

tangentAt(position = 0): Vector {
const curve = this.curve;
const tangent = curve.tangentAt(position);
curve.delete();
return tangent;
return this.curve.tangentAt(position);
}

get isClosed(): boolean {
const curve = this.curve;
const isClosed = curve.isClosed;
curve.delete();
pointAt(position = 0): Vector {
return this.curve.pointAt(position);
}

return isClosed;
get isClosed(): boolean {
return this.curve.isClosed;
}

get isPeriodic(): boolean {
const curve = this.curve;
const isPeriodic = curve.isPeriodic;
curve.delete();
return isPeriodic;
return this.curve.isPeriodic;
}

get period(): number {
const curve = this.curve;
const period = curve.period;
curve.delete();
return period;
return this.curve.period;
}

get geomType(): CurveType {
const curve = this.curve;
const type = curve.curveType;
curve.delete();
return type;
return this.curve.curveType;
}

get length(): number {
Expand Down Expand Up @@ -652,11 +634,19 @@ export class Curve extends WrappingObj<CurveLike> {
return new Vector(umax);
}

tangentAt(position: number): Vector {
let pos = position;
if (!position) {
pos = (this.wrapped.LastParameter() - this.wrapped.FirstParameter()) / 2;
}
protected _mapParameter(position: number): number {
const firstParam = this.wrapped.FirstParameter();
const lastParam = this.wrapped.LastParameter();

return firstParam + (lastParam - firstParam) * position;
}

pointAt(position = 0.5): Vector {
return new Vector(this.wrapped.Value(this._mapParameter(position)));
}

tangentAt(position = 0.5): Vector {
const pos = this._mapParameter(position);

const tmp = new this.oc.gp_Pnt_1();
const res = new this.oc.gp_Vec_1();
Expand Down

0 comments on commit 4c667bc

Please sign in to comment.