@shapediver/viewer.shared.math
Advanced tools
Comparing version 3.1.2 to 3.2.0
@@ -0,3 +1,3 @@ | ||
import { IPlane } from '../interfaces/IPlane'; | ||
import { mat4, vec3 } from 'gl-matrix'; | ||
import { IPlane } from '../interfaces/IPlane'; | ||
export declare class Plane implements IPlane { | ||
@@ -17,5 +17,5 @@ private _normal; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
reset(): void; | ||
setFromNormalAndCoplanarPoint(normal: vec3, point: vec3): IPlane; | ||
reset(): void; | ||
} | ||
//# sourceMappingURL=Plane.d.ts.map |
@@ -12,3 +12,3 @@ "use strict"; | ||
// #endregion Constructors (1) | ||
// #region Public Accessors (4) | ||
// #region Public Getters And Setters (4) | ||
get constant() { | ||
@@ -26,6 +26,9 @@ return this._constant; | ||
} | ||
// #endregion Public Accessors (4) | ||
// #region Public Methods (7) | ||
// #endregion Public Getters And Setters (4) | ||
// #region Public Methods (8) | ||
applyMatrix(matrix) { | ||
const normalMatrix = gl_matrix_1.mat3.transpose(gl_matrix_1.mat3.create(), gl_matrix_1.mat3.invert(gl_matrix_1.mat3.create(), gl_matrix_1.mat3.fromMat4(gl_matrix_1.mat3.create(), matrix))); | ||
let inverse = gl_matrix_1.mat3.invert(gl_matrix_1.mat3.create(), gl_matrix_1.mat3.fromMat4(gl_matrix_1.mat3.create(), matrix)); | ||
if (!inverse) | ||
inverse = gl_matrix_1.mat3.create(); | ||
const normalMatrix = gl_matrix_1.mat3.transpose(gl_matrix_1.mat3.create(), inverse); | ||
const p = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.clone(this.normal), gl_matrix_1.vec3.fromValues(this._constant, this._constant, this._constant)), matrix); | ||
@@ -63,2 +66,6 @@ this._normal = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformMat3(gl_matrix_1.vec3.create(), this._normal, normalMatrix)); | ||
} | ||
reset() { | ||
this._normal = gl_matrix_1.vec3.fromValues(1, 0, 0); | ||
this._constant = 0; | ||
} | ||
setFromNormalAndCoplanarPoint(normal, point) { | ||
@@ -69,8 +76,4 @@ gl_matrix_1.vec3.copy(this.normal, normal); | ||
} | ||
reset() { | ||
this._normal = gl_matrix_1.vec3.fromValues(1, 0, 0); | ||
this._constant = 0; | ||
} | ||
} | ||
exports.Plane = Plane; | ||
//# sourceMappingURL=Plane.js.map |
{ | ||
"name": "@shapediver/viewer.shared.math", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"description": "", | ||
@@ -42,6 +42,6 @@ "keywords": [], | ||
"dependencies": { | ||
"@shapediver/viewer.shared.services": "3.1.2", | ||
"@shapediver/viewer.shared.services": "3.2.0", | ||
"gl-matrix": "3.3.0" | ||
}, | ||
"gitHead": "b777b52622744784ca90b32c2008f24653e57c76" | ||
"gitHead": "36007f976342f0390133d7e5cecf4ebf79905c8a" | ||
} |
@@ -1,41 +0,41 @@ | ||
import { mat3, mat4, vec3 } from 'gl-matrix' | ||
import { IPlane } from '../interfaces/IPlane'; | ||
import { mat3, mat4, vec3 } from 'gl-matrix'; | ||
export class Plane implements IPlane { | ||
// #region Constructors (1) | ||
constructor(private _normal: vec3 = vec3.fromValues(1,0,0), private _constant: number = 0) {} | ||
constructor(private _normal: vec3 = vec3.fromValues(1, 0, 0), private _constant: number = 0) { } | ||
// #endregion Constructors (1) | ||
// #region Public Accessors (4) | ||
// #region Public Getters And Setters (4) | ||
public get constant(): number { | ||
return this._constant; | ||
} | ||
return this._constant; | ||
} | ||
public set constant(value: number) { | ||
this._constant = value; | ||
} | ||
this._constant = value; | ||
} | ||
public get normal(): vec3 { | ||
return this._normal; | ||
} | ||
return this._normal; | ||
} | ||
public set normal(value: vec3) { | ||
this._normal = value; | ||
} | ||
this._normal = value; | ||
} | ||
// #endregion Public Accessors (4) | ||
// #endregion Public Getters And Setters (4) | ||
// #region Public Methods (7) | ||
// #region Public Methods (8) | ||
public applyMatrix(matrix: mat4): IPlane { | ||
const normalMatrix = mat3.transpose(mat3.create(), mat3.invert(mat3.create(), mat3.fromMat4(mat3.create(), matrix))) | ||
const p = vec3.transformMat4(vec3.create(), vec3.multiply(vec3.create(), vec3.clone(this.normal), vec3.fromValues(this._constant, this._constant, this._constant)), matrix) | ||
let inverse = mat3.invert(mat3.create(), mat3.fromMat4(mat3.create(), matrix)); | ||
if (!inverse) inverse = mat3.create(); | ||
const normalMatrix = mat3.transpose(mat3.create(), inverse); | ||
const p = vec3.transformMat4(vec3.create(), vec3.multiply(vec3.create(), vec3.clone(this.normal), vec3.fromValues(this._constant, this._constant, this._constant)), matrix); | ||
this._normal = vec3.normalize(vec3.create(), vec3.transformMat3(vec3.create(), this._normal, normalMatrix)); | ||
this.constant = -vec3.dot(p, this._normal); | ||
return this; | ||
this.constant = -vec3.dot(p, this._normal); | ||
return this; | ||
} | ||
@@ -53,3 +53,3 @@ | ||
public containsPoint(point: vec3): boolean { | ||
return this.distanceToPoint(point) === 0; | ||
return this.distanceToPoint(point) === 0; | ||
} | ||
@@ -62,11 +62,11 @@ | ||
public intersect(origin: vec3, direction: vec3): number | null { | ||
const denominator = vec3.dot(this.normal, direction); | ||
if (denominator === 0) { | ||
// line is coplanar, return origin | ||
if (this.distanceToPoint( origin ) === 0) return 0; | ||
// Null is preferable to undefined since undefined means.... it is undefined | ||
return null; | ||
} | ||
const t = - (vec3.dot(origin, this.normal) + this.constant) / denominator; | ||
if ( t < 0 ) return null; | ||
const denominator = vec3.dot(this.normal, direction); | ||
if (denominator === 0) { | ||
// line is coplanar, return origin | ||
if (this.distanceToPoint(origin) === 0) return 0; | ||
// Null is preferable to undefined since undefined means.... it is undefined | ||
return null; | ||
} | ||
const t = - (vec3.dot(origin, this.normal) + this.constant) / denominator; | ||
if (t < 0) return null; | ||
@@ -76,14 +76,14 @@ return t; //vec3.add(vec3.create(), vec3.multiply(vec3.create(), direction, vec3.fromValues(t,t,t)), origin); | ||
public reset() { | ||
this._normal = vec3.fromValues(1, 0, 0); | ||
this._constant = 0; | ||
} | ||
public setFromNormalAndCoplanarPoint(normal: vec3, point: vec3): IPlane { | ||
vec3.copy(this.normal, normal); | ||
this.constant = -vec3.dot(point, this.normal); | ||
return this; | ||
this.constant = -vec3.dot(point, this.normal); | ||
return this; | ||
} | ||
public reset() { | ||
this._normal = vec3.fromValues(1,0,0); | ||
this._constant = 0; | ||
} | ||
// #endregion Public Methods (7) | ||
// #endregion Public Methods (8) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87319
1117
+ Added@shapediver/api.geometry-api-dto-v2@1.22.0(transitive)
+ Added@shapediver/sdk.geometry-api-sdk-v2@1.9.1(transitive)
+ Added@shapediver/viewer.shared.build-data@3.2.0(transitive)
+ Added@shapediver/viewer.shared.services@3.2.0(transitive)
- Removed@shapediver/api.geometry-api-dto-v2@1.15.1(transitive)
- Removed@shapediver/sdk.geometry-api-sdk-v2@1.8.2(transitive)
- Removed@shapediver/viewer.shared.build-data@3.1.2(transitive)
- Removed@shapediver/viewer.shared.services@3.1.2(transitive)