fix typescript type errors, unit vectors

This commit is contained in:
Val Erastov 2022-08-14 23:07:56 -07:00
parent dbacfa633b
commit 9c5f146d41
3 changed files with 13 additions and 6 deletions

View file

@ -114,7 +114,7 @@ function readSurface(s, faceInverted, effectivelyInverted, face) {
surface._mirrored = !s.direct;
} else if (s.TYPE === 'PLANE') {
let normal = new Vector().set3(s.normal);
let normal = new Vector().set3(s.normal).asUnitVector();
let plane = new Plane(normal, normal.dot(new Vector().set3(s.origin)));
if (effectivelyInverted) {
plane = plane.invert();

View file

@ -1,5 +1,5 @@
import {Point} from '../point';
import Vector from 'math/vector';
import Vector, {UnitVector} from 'math/vector';
import {Plane} from '../impl/plane';
import BrepCurve from '../curves/brepCurve';
import {intersectNurbs} from './nurbsSurface';
@ -55,13 +55,12 @@ export class BrepSurface {
return normal;
}
normalUV(u: number, v: number): Vector {
normalUV(u: number, v: number): UnitVector {
let normal = pt(this.impl.normal(u, v));
if (this.inverted) {
normal._negate();
}
normal._normalize();
return normal;
return normal._normalize();
}
normalInMiddle(): Vector {

View file

@ -1,5 +1,6 @@
import {clamp} from "math/commons";
import {XYZ} from "math/xyz";
import {areEqual, TOLERANCE_SQ} from "math/equality";
export default class Vector implements XYZ {
@ -182,7 +183,14 @@ export default class Vector implements XYZ {
const sinA = clamp(this.cross(vecB).length(), -1, 1);
return Math.atan2(sinA, cosA);
}
asUnitVector(): UnitVector {
if (areEqual(this.lengthSquared(), 1, TOLERANCE_SQ)) {
console.error("not unit vector is treated as unit");
}
return this as any as UnitVector;
}
static fromData(arr: [number, number, number]): Vector {
return new Vector().set3(arr);
}