Skip to content

Commit 6dc2952

Browse files
committed
perf(modeling): more perf changes to plane
1 parent 2bc163e commit 6dc2952

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

packages/modeling/src/maths/plane/fromNormalAndPoint.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ import * as vec3 from '../vec3/index.js'
1818
* @alias module:modeling/maths/plane.fromNormalAndPoint
1919
*/
2020
export const fromNormalAndPoint = (out, normal, point) => {
21-
const u = vec3.normalize(out, normal)
22-
const w = vec3.dot(point, u)
21+
// normalize to out
22+
vec3.normalize(out, normal)
23+
// calculate distance
24+
out[3] = vec3.dot(point, out)
2325

24-
out[0] = u[0]
25-
out[1] = u[1]
26-
out[2] = u[2]
27-
out[3] = w
2826
return out
2927
}

packages/modeling/src/maths/plane/fromPoints.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as vec3 from '../vec3/index.js'
22

3+
const ba = vec3.create()
4+
const ca = vec3.create()
5+
36
/**
47
* Create a plane from the given points.
58
*
69
* @param {Plane} out - receiving plane
7-
* @param {Array} vertices - points on the plane
10+
* @param {Array} vertices - list of points on the plane
811
* @returns {Plane} out
912
* @alias module:modeling/maths/plane.fromPoints
1013
*/
@@ -13,8 +16,6 @@ export const fromPoints = (out, ...vertices) => {
1316

1417
// Calculate normal vector for a single vertex
1518
// Inline to avoid allocations
16-
const ba = vec3.create()
17-
const ca = vec3.create()
1819
const vertexNormal = (index) => {
1920
const a = vertices[index]
2021
const b = vertices[(index + 1) % len]
@@ -37,7 +38,7 @@ export const fromPoints = (out, ...vertices) => {
3738
vertices.forEach((v, i) => {
3839
vec3.add(out, out, vertexNormal(i))
3940
})
40-
// renormalize normal vector
41+
// normalize sum
4142
vec3.normalize(out, out)
4243
}
4344
out[3] = vec3.dot(out, vertices[0])

packages/modeling/src/maths/plane/fromPointsRandom.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export const fromPointsRandom = (out, a, b, c) => {
3434
vec3.normalize(normal, normal)
3535

3636
// and distance
37-
const w = vec3.dot(normal, a)
38-
out[3] = w
37+
out[3] = vec3.dot(normal, a)
3938

4039
return out
4140
}

0 commit comments

Comments
 (0)