UNPKG

jakke-graphics-ts

Version:

My common graphics utils for building my aec apps.

54 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Vertex3dWrapped = void 0; class Vertex3dWrapped { constructor(v) { this.x = v.x; this.y = v.y; this.z = v.z; } getHash() { const x = Math.round(this.x * Vertex3dWrapped.PRECISION); const y = Math.round(this.y * Vertex3dWrapped.PRECISION); const z = Math.round(this.z * Vertex3dWrapped.PRECISION); return `${x},${y},${z}`; } add(v) { return new Vertex3dWrapped({ x: this.x + v.x, y: this.y + v.y, z: this.z + v.z }); } subtract(v) { return new Vertex3dWrapped({ x: this.x - v.x, y: this.y - v.y, z: this.z - v.z }); } dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z; } cross(v) { return new Vertex3dWrapped({ x: this.y * v.z - this.z * v.y, y: this.z * v.x - this.x * v.z, z: this.x * v.y - this.y * v.x }); } normalized() { const length = this.getLength(); return new Vertex3dWrapped({ x: this.x / length, y: this.y / length, z: this.z / length }); } getLength() { return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2)); } multiply(t) { return new Vertex3dWrapped({ x: this.x * t, y: this.y * t, z: this.z * t }); } toObject() { return { x: this.x, y: this.y, z: this.z }; } equals(v) { return this.getHash() === v.getHash(); } clone() { return new Vertex3dWrapped({ x: this.x, y: this.y, z: this.z }); } } exports.Vertex3dWrapped = Vertex3dWrapped; Vertex3dWrapped.PRECISION = 1e6; //# sourceMappingURL=vertex3d.js.map