jsketcher/web/app/brep/geom/curves/invertedCurve.js
2020-05-19 01:48:19 -07:00

56 lines
949 B
JavaScript

import * as vec from 'math/vec';
export default class InvertedCurve {
constructor(curve) {
this.curve = curve;
let [uMin, uMax] = this.curve.domain();
this.uMin = uMin;
this.uMax = uMax;
}
wrapParam(u) {
return this.uMax - (u - this.uMin);
}
domain() {
return this.curve.domain();
}
degree() {
return this.curve.degree();
}
transform(tr) {
return new InvertedCurve(this.curve.transform(tr));
}
point(u) {
return this.curve.point(this.wrapParam(u));
}
param(point) {
return this.wrapParam(this.curve.param(point));
}
eval(u, num) {
let res = this.curve.eval(this.wrapParam(u), num);
if (res.length > 1) {
vec._negate(res[1])
}
return res;
}
knots() {
return this.curve.knots();
}
invert() {
return this.curve;
}
split(u) {
return this.curve.split(this.wrapParam(u)).map(c => new InvertedCurve(c)).reverse();
}
}