@jscad/modeling 2.9.4 → 2.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/jscad-modeling.min.js +125 -128
- package/package.json +2 -2
- package/src/colors/colorize.d.ts +6 -5
- package/src/geometries/geom2/type.d.ts +3 -2
- package/src/geometries/geom3/type.d.ts +3 -2
- package/src/geometries/path2/type.d.ts +3 -2
- package/src/geometries/poly3/measureBoundingSphere.d.ts +2 -2
- package/src/geometries/poly3/measureBoundingSphere.js +46 -8
- package/src/geometries/poly3/measureBoundingSphere.test.js +16 -26
- package/src/geometries/poly3/type.d.ts +3 -2
- package/src/geometries/types.d.ts +4 -2
- package/src/maths/mat4/fromRotation.js +9 -7
- package/src/maths/mat4/fromTaitBryanRotation.js +8 -6
- package/src/maths/mat4/fromXRotation.js +4 -2
- package/src/maths/mat4/fromYRotation.js +4 -2
- package/src/maths/mat4/fromZRotation.js +4 -2
- package/src/maths/mat4/rotate.js +9 -5
- package/src/maths/mat4/rotateX.js +4 -2
- package/src/maths/mat4/rotateY.js +4 -2
- package/src/maths/mat4/rotateZ.js +4 -2
- package/src/maths/mat4/translate.test.js +2 -3
- package/src/maths/utils/index.d.ts +1 -0
- package/src/maths/utils/index.js +2 -0
- package/src/{utils → maths/utils}/trigonometry.d.ts +0 -0
- package/src/{utils → maths/utils}/trigonometry.js +1 -1
- package/src/{utils → maths/utils}/trigonometry.test.js +0 -0
- package/src/maths/vec2/distance.js +1 -1
- package/src/maths/vec2/fromAngleRadians.js +4 -2
- package/src/maths/vec2/length.js +1 -1
- package/src/maths/vec2/length.test.js +0 -10
- package/src/maths/vec3/angle.js +2 -2
- package/src/maths/vec3/angle.test.js +0 -12
- package/src/maths/vec3/distance.js +1 -1
- package/src/maths/vec3/length.js +1 -1
- package/src/maths/vec3/length.test.js +0 -10
- package/src/operations/booleans/trees/PolygonTreeNode.js +2 -2
- package/src/operations/extrusions/extrudeRotate.test.js +42 -42
- package/src/operations/extrusions/project.test.js +2 -2
- package/src/operations/extrusions/slice/repair.js +1 -1
- package/src/primitives/circle.test.js +7 -0
- package/src/primitives/cylinderElliptic.js +4 -2
- package/src/primitives/cylinderElliptic.test.js +7 -1
- package/src/primitives/ellipse.js +1 -1
- package/src/primitives/ellipse.test.js +7 -0
- package/src/primitives/ellipsoid.js +1 -1
- package/src/primitives/geodesicSphere.js +3 -2
- package/src/primitives/roundedCuboid.js +4 -2
- package/src/primitives/roundedCylinder.js +1 -1
- package/src/primitives/torus.test.js +7 -3
- package/src/utils/index.d.ts +0 -1
- package/src/utils/index.js +1 -3
- package/src/maths/mat4/constants.d.ts +0 -1
- package/src/maths/mat4/constants.js +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/modeling",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.5",
|
|
4
4
|
"description": "Constructive Solid Geometry (CSG) Library for JSCAD",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"nyc": "15.1.0",
|
|
62
62
|
"uglifyify": "5.0.2"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "225b034db0d94f748992da72b269833954a2e212"
|
|
65
65
|
}
|
package/src/colors/colorize.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import { RGB, RGBA } from './types'
|
|
|
5
5
|
|
|
6
6
|
export default colorize
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
declare function colorize<T>(color: RGB | RGBA, object: T): T & Colored
|
|
8
|
+
// Single Geom3 returns Colored Geom3
|
|
9
|
+
declare function colorize<T extends Geometry>(color: RGB | RGBA, object: T): T & Colored
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
declare function colorize<T>(color: RGB | RGBA, ...objects: RecursiveArray<T>): Array<T & Colored>
|
|
13
|
-
|
|
11
|
+
// List of Geom3 returns list of Colored Geom3
|
|
12
|
+
declare function colorize<T extends Geometry>(color: RGB | RGBA, ...objects: RecursiveArray<T>): Array<T & Colored>
|
|
13
|
+
// List of mixed geometries returns list of colored geometries
|
|
14
|
+
declare function colorize(color: RGB | RGBA, ...objects: RecursiveArray<Geometry>): Array<Geometry & Colored>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Vec2 from '../../maths/vec2/type'
|
|
2
2
|
import Mat4 from '../../maths/mat4/type'
|
|
3
|
-
import {
|
|
3
|
+
import { Color } from '../types'
|
|
4
4
|
|
|
5
5
|
export default Geom2
|
|
6
6
|
|
|
7
|
-
declare interface Geom2
|
|
7
|
+
declare interface Geom2 {
|
|
8
8
|
sides: Array<[Vec2, Vec2]>
|
|
9
9
|
transforms: Mat4
|
|
10
|
+
color?: Color
|
|
10
11
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Poly3 from '../poly3/type'
|
|
2
2
|
import Mat4 from '../../maths/mat4/type'
|
|
3
|
-
import {
|
|
3
|
+
import { Color } from '../types'
|
|
4
4
|
|
|
5
5
|
export default Geom3
|
|
6
6
|
|
|
7
|
-
declare interface Geom3
|
|
7
|
+
declare interface Geom3 {
|
|
8
8
|
polygons: Array<Poly3>
|
|
9
9
|
transforms: Mat4
|
|
10
|
+
color?: Color
|
|
10
11
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import Vec2 from '../../maths/vec2/type'
|
|
2
2
|
import Mat4 from '../../maths/mat4/type'
|
|
3
|
-
import {
|
|
3
|
+
import { Color } from '../types'
|
|
4
4
|
|
|
5
5
|
export default Path2
|
|
6
6
|
|
|
7
|
-
declare interface Path2
|
|
7
|
+
declare interface Path2 {
|
|
8
8
|
points: Array<Vec2>
|
|
9
9
|
isClosed: boolean
|
|
10
10
|
transforms: Mat4
|
|
11
|
+
color?: Color
|
|
11
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Poly3 from './type'
|
|
2
|
-
import
|
|
2
|
+
import Vec4 from '../../maths/vec4/type'
|
|
3
3
|
|
|
4
4
|
export default measureBoundingSphere
|
|
5
5
|
|
|
6
|
-
declare function measureBoundingSphere(polygon: Poly3):
|
|
6
|
+
declare function measureBoundingSphere(polygon: Poly3): Vec4
|
|
@@ -1,19 +1,57 @@
|
|
|
1
1
|
const vec3 = require('../../maths/vec3')
|
|
2
|
-
const
|
|
2
|
+
const vec4 = require('../../maths/vec4')
|
|
3
|
+
|
|
4
|
+
const cache = new WeakMap()
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Measure the bounding sphere of the given polygon.
|
|
6
8
|
* @param {poly3} polygon - the polygon to measure
|
|
7
|
-
* @returns {
|
|
9
|
+
* @returns {vec4} the computed bounding sphere; center point (3D) and radius
|
|
8
10
|
* @alias module:modeling/geometries/poly3.measureBoundingSphere
|
|
9
11
|
*/
|
|
10
12
|
const measureBoundingSphere = (polygon) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
13
|
+
let boundingSphere = cache.get(polygon)
|
|
14
|
+
if (boundingSphere) return boundingSphere
|
|
15
|
+
|
|
16
|
+
const vertices = polygon.vertices
|
|
17
|
+
const out = vec4.create()
|
|
18
|
+
|
|
19
|
+
if (vertices.length === 0) {
|
|
20
|
+
out[0] = 0
|
|
21
|
+
out[1] = 0
|
|
22
|
+
out[2] = 0
|
|
23
|
+
out[3] = 0
|
|
24
|
+
return out
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// keep a list of min/max vertices by axis
|
|
28
|
+
let minx = vertices[0]
|
|
29
|
+
let miny = minx
|
|
30
|
+
let minz = minx
|
|
31
|
+
let maxx = minx
|
|
32
|
+
let maxy = minx
|
|
33
|
+
let maxz = minx
|
|
34
|
+
|
|
35
|
+
vertices.forEach((v) => {
|
|
36
|
+
if (minx[0] > v[0]) minx = v
|
|
37
|
+
if (miny[1] > v[1]) miny = v
|
|
38
|
+
if (minz[2] > v[2]) minz = v
|
|
39
|
+
if (maxx[0] < v[0]) maxx = v
|
|
40
|
+
if (maxy[1] < v[1]) maxy = v
|
|
41
|
+
if (maxz[2] < v[2]) maxz = v
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
out[0] = (minx[0] + maxx[0]) * 0.5 // center of sphere
|
|
45
|
+
out[1] = (miny[1] + maxy[1]) * 0.5
|
|
46
|
+
out[2] = (minz[2] + maxz[2]) * 0.5
|
|
47
|
+
const x = out[0] - maxx[0]
|
|
48
|
+
const y = out[1] - maxy[1]
|
|
49
|
+
const z = out[2] - maxz[2]
|
|
50
|
+
out[3] = Math.sqrt(x * x + y * y + z * z) // radius of sphere
|
|
51
|
+
|
|
52
|
+
cache.set(polygon, out)
|
|
53
|
+
|
|
54
|
+
return out
|
|
17
55
|
}
|
|
18
56
|
|
|
19
57
|
module.exports = measureBoundingSphere
|
|
@@ -3,28 +3,23 @@ const { measureBoundingSphere, create, fromPoints, transform } = require('./inde
|
|
|
3
3
|
|
|
4
4
|
const mat4 = require('../../maths/mat4')
|
|
5
5
|
|
|
6
|
-
const { compareVectors, nearlyEqual } = require('../../../test/helpers/index')
|
|
7
|
-
|
|
8
6
|
test('poly3: measureBoundingSphere() should return correct values', (t) => {
|
|
9
7
|
let ply1 = create()
|
|
10
|
-
let exp1 = [
|
|
8
|
+
let exp1 = [0, 0, 0, 0]
|
|
11
9
|
let ret1 = measureBoundingSphere(ply1)
|
|
12
|
-
t.
|
|
13
|
-
nearlyEqual(t, ret1[1], exp1[1], Number.EPSILON)
|
|
10
|
+
t.deepEqual(ret1, exp1)
|
|
14
11
|
|
|
15
12
|
// simple triangle
|
|
16
13
|
let ply2 = fromPoints([[0, 0, 0], [0, 10, 0], [0, 10, 10]])
|
|
17
|
-
let exp2 = [
|
|
14
|
+
let exp2 = [0, 5, 5, 7.0710678118654755]
|
|
18
15
|
let ret2 = measureBoundingSphere(ply2)
|
|
19
|
-
t.
|
|
20
|
-
nearlyEqual(t, ret2[1], exp2[1], Number.EPSILON)
|
|
16
|
+
t.deepEqual(ret2, exp2)
|
|
21
17
|
|
|
22
18
|
// simple square
|
|
23
19
|
let ply3 = fromPoints([[0, 0, 0], [0, 10, 0], [0, 10, 10], [0, 0, 10]])
|
|
24
|
-
let exp3 = [
|
|
20
|
+
let exp3 = [0, 5, 5, 7.0710678118654755]
|
|
25
21
|
let ret3 = measureBoundingSphere(ply3)
|
|
26
|
-
t.
|
|
27
|
-
nearlyEqual(t, ret3[1], exp3[1], Number.EPSILON)
|
|
22
|
+
t.deepEqual(ret3, exp3)
|
|
28
23
|
|
|
29
24
|
// V-shape
|
|
30
25
|
const points = [
|
|
@@ -40,10 +35,9 @@ test('poly3: measureBoundingSphere() should return correct values', (t) => {
|
|
|
40
35
|
[0, 3, 3]
|
|
41
36
|
]
|
|
42
37
|
let ply4 = fromPoints(points)
|
|
43
|
-
let exp4 = [
|
|
38
|
+
let exp4 = [0, 4.5, 3, 4.6097722286464435]
|
|
44
39
|
let ret4 = measureBoundingSphere(ply4)
|
|
45
|
-
t.
|
|
46
|
-
nearlyEqual(t, ret4[1], exp4[1], Number.EPSILON)
|
|
40
|
+
t.deepEqual(ret4, exp4)
|
|
47
41
|
|
|
48
42
|
// rotated to various angles
|
|
49
43
|
const rotation = mat4.fromZRotation(mat4.create(), (45 * 0.017453292519943295))
|
|
@@ -55,16 +49,12 @@ test('poly3: measureBoundingSphere() should return correct values', (t) => {
|
|
|
55
49
|
ret2 = measureBoundingSphere(ply2)
|
|
56
50
|
ret3 = measureBoundingSphere(ply3)
|
|
57
51
|
ret4 = measureBoundingSphere(ply4)
|
|
58
|
-
exp1 = [
|
|
59
|
-
t.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
t.
|
|
66
|
-
nearlyEqual(t, ret3[1], exp3[1], Number.EPSILON)
|
|
67
|
-
exp4 = [[-3.181980515339464, 3.1819805153394642, 3], 4.6097722286464435]
|
|
68
|
-
t.true(compareVectors(ret4[0], exp4[0]))
|
|
69
|
-
nearlyEqual(t, ret4[1], exp4[1], Number.EPSILON)
|
|
52
|
+
exp1 = [0, 0, 0, 0]
|
|
53
|
+
t.deepEqual(ret1, exp1)
|
|
54
|
+
exp2 = [-3.5355339059327373, 3.5355339059327378, 5, 7.0710678118654755]
|
|
55
|
+
t.deepEqual(ret2, exp2)
|
|
56
|
+
exp3 = [-3.5355339059327373, 3.5355339059327378, 5, 7.0710678118654755]
|
|
57
|
+
t.deepEqual(ret3, exp3)
|
|
58
|
+
exp4 = [-3.181980515339464, 3.1819805153394642, 3, 4.6097722286464435]
|
|
59
|
+
t.deepEqual(ret4, exp4)
|
|
70
60
|
})
|
|
@@ -8,8 +8,10 @@ import { RGB, RGBA } from '../colors'
|
|
|
8
8
|
// see https://github.com/jscad/OpenJSCAD.org/pull/726#issuecomment-724575265
|
|
9
9
|
export type Geometry = Geom2 | Geom3 | Poly3 | Path2
|
|
10
10
|
|
|
11
|
-
export type
|
|
12
|
-
|
|
11
|
+
export type Color = RGB | RGBA
|
|
12
|
+
|
|
13
|
+
export interface Colored {
|
|
14
|
+
color: Color
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export { default as Geom2 } from './geom2/type'
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { EPS } = require('../constants')
|
|
2
|
+
|
|
3
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
4
|
|
|
3
|
-
const
|
|
5
|
+
const identity = require('./identity')
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Creates a matrix from a given angle around a given axis
|
|
@@ -19,20 +21,20 @@ const { EPSILON } = require('./constants')
|
|
|
19
21
|
*/
|
|
20
22
|
const fromRotation = (out, rad, axis) => {
|
|
21
23
|
let [x, y, z] = axis
|
|
22
|
-
|
|
24
|
+
const lengthSquared = x * x + y * y + z * z
|
|
23
25
|
|
|
24
|
-
if (Math.abs(
|
|
26
|
+
if (Math.abs(lengthSquared) < EPS) {
|
|
25
27
|
// axis is 0,0,0 or almost
|
|
26
28
|
return identity(out)
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
len = 1 /
|
|
31
|
+
const len = 1 / Math.sqrt(lengthSquared)
|
|
30
32
|
x *= len
|
|
31
33
|
y *= len
|
|
32
34
|
z *= len
|
|
33
35
|
|
|
34
|
-
const s =
|
|
35
|
-
const c =
|
|
36
|
+
const s = sin(rad)
|
|
37
|
+
const c = cos(rad)
|
|
36
38
|
const t = 1 - c
|
|
37
39
|
|
|
38
40
|
// Perform rotation-specific matrix multiplication
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Creates a matrix from the given Tait–Bryan angles.
|
|
3
5
|
*
|
|
@@ -15,12 +17,12 @@
|
|
|
15
17
|
*/
|
|
16
18
|
const fromTaitBryanRotation = (out, yaw, pitch, roll) => {
|
|
17
19
|
// precompute sines and cosines of Euler angles
|
|
18
|
-
const sy =
|
|
19
|
-
const cy =
|
|
20
|
-
const sp =
|
|
21
|
-
const cp =
|
|
22
|
-
const sr =
|
|
23
|
-
const cr =
|
|
20
|
+
const sy = sin(yaw)
|
|
21
|
+
const cy = cos(yaw)
|
|
22
|
+
const sp = sin(pitch)
|
|
23
|
+
const cp = cos(pitch)
|
|
24
|
+
const sr = sin(roll)
|
|
25
|
+
const cr = cos(roll)
|
|
24
26
|
|
|
25
27
|
// create and populate rotation matrix
|
|
26
28
|
// left-hand-rule rotation
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Creates a matrix from the given angle around the X axis.
|
|
3
5
|
* This is equivalent to (but much faster than):
|
|
@@ -13,8 +15,8 @@
|
|
|
13
15
|
* let matrix = fromXRotation(create(), Math.PI / 2)
|
|
14
16
|
*/
|
|
15
17
|
const fromXRotation = (out, radians) => {
|
|
16
|
-
const s =
|
|
17
|
-
const c =
|
|
18
|
+
const s = sin(radians)
|
|
19
|
+
const c = cos(radians)
|
|
18
20
|
|
|
19
21
|
// Perform axis-specific matrix multiplication
|
|
20
22
|
out[0] = 1
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Creates a matrix from the given angle around the Y axis.
|
|
3
5
|
* This is equivalent to (but much faster than):
|
|
@@ -13,8 +15,8 @@
|
|
|
13
15
|
* let matrix = fromYRotation(create(), Math.PI / 2)
|
|
14
16
|
*/
|
|
15
17
|
const fromYRotation = (out, radians) => {
|
|
16
|
-
const s =
|
|
17
|
-
const c =
|
|
18
|
+
const s = sin(radians)
|
|
19
|
+
const c = cos(radians)
|
|
18
20
|
|
|
19
21
|
// Perform axis-specific matrix multiplication
|
|
20
22
|
out[0] = c
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Creates a matrix from the given angle around the Z axis.
|
|
3
5
|
* This is equivalent to (but much faster than):
|
|
@@ -13,8 +15,8 @@
|
|
|
13
15
|
* let matrix = fromZRotation(create(), Math.PI / 2)
|
|
14
16
|
*/
|
|
15
17
|
const fromZRotation = (out, radians) => {
|
|
16
|
-
const s =
|
|
17
|
-
const c =
|
|
18
|
+
const s = sin(radians)
|
|
19
|
+
const c = cos(radians)
|
|
18
20
|
|
|
19
21
|
// Perform axis-specific matrix multiplication
|
|
20
22
|
out[0] = c
|
package/src/maths/mat4/rotate.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const { EPS } = require('../constants')
|
|
2
|
+
|
|
3
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
4
|
+
|
|
1
5
|
const copy = require('./copy')
|
|
2
6
|
|
|
3
7
|
/**
|
|
@@ -12,20 +16,20 @@ const copy = require('./copy')
|
|
|
12
16
|
*/
|
|
13
17
|
const rotate = (out, matrix, radians, axis) => {
|
|
14
18
|
let [x, y, z] = axis
|
|
15
|
-
|
|
19
|
+
const lengthSquared = x * x + y * y + z * z
|
|
16
20
|
|
|
17
|
-
if (Math.abs(
|
|
21
|
+
if (Math.abs(lengthSquared) < EPS) {
|
|
18
22
|
// axis is 0,0,0 or almost
|
|
19
23
|
return copy(out, matrix)
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
len = 1 /
|
|
26
|
+
const len = 1 / Math.sqrt(lengthSquared)
|
|
23
27
|
x *= len
|
|
24
28
|
y *= len
|
|
25
29
|
z *= len
|
|
26
30
|
|
|
27
|
-
const s =
|
|
28
|
-
const c =
|
|
31
|
+
const s = sin(radians)
|
|
32
|
+
const c = cos(radians)
|
|
29
33
|
const t = 1 - c
|
|
30
34
|
|
|
31
35
|
const a00 = matrix[0]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Rotates a matrix by the given angle around the X axis.
|
|
3
5
|
*
|
|
@@ -8,8 +10,8 @@
|
|
|
8
10
|
* @alias module:modeling/maths/mat4.rotateX
|
|
9
11
|
*/
|
|
10
12
|
const rotateX = (out, matrix, radians) => {
|
|
11
|
-
const s =
|
|
12
|
-
const c =
|
|
13
|
+
const s = sin(radians)
|
|
14
|
+
const c = cos(radians)
|
|
13
15
|
const a10 = matrix[4]
|
|
14
16
|
const a11 = matrix[5]
|
|
15
17
|
const a12 = matrix[6]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Rotates a matrix by the given angle around the Y axis.
|
|
3
5
|
*
|
|
@@ -8,8 +10,8 @@
|
|
|
8
10
|
* @alias module:modeling/maths/mat4.rotateY
|
|
9
11
|
*/
|
|
10
12
|
const rotateY = (out, matrix, radians) => {
|
|
11
|
-
const s =
|
|
12
|
-
const c =
|
|
13
|
+
const s = sin(radians)
|
|
14
|
+
const c = cos(radians)
|
|
13
15
|
const a00 = matrix[0]
|
|
14
16
|
const a01 = matrix[1]
|
|
15
17
|
const a02 = matrix[2]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Rotates a matrix by the given angle around the Z axis.
|
|
3
5
|
*
|
|
@@ -8,8 +10,8 @@
|
|
|
8
10
|
* @alias module:modeling/maths/mat4.rotateZ
|
|
9
11
|
*/
|
|
10
12
|
const rotateZ = (out, matrix, radians) => {
|
|
11
|
-
const s =
|
|
12
|
-
const c =
|
|
13
|
+
const s = sin(radians)
|
|
14
|
+
const c = cos(radians)
|
|
13
15
|
const a00 = matrix[0]
|
|
14
16
|
const a01 = matrix[1]
|
|
15
17
|
const a02 = matrix[2]
|
|
@@ -52,10 +52,9 @@ test('mat4: translate() called with three parameters should update a mat4 with c
|
|
|
52
52
|
t.true(compareVectors(obs4, [1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 5, 0, 2, 9, 30, 1]))
|
|
53
53
|
t.true(compareVectors(ret4, [1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 5, 0, 2, 9, 30, 1]))
|
|
54
54
|
|
|
55
|
-
const r = (90 * 0.017453292519943295)
|
|
56
55
|
const rotateZMatrix = [
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
0, -1, 0, 0,
|
|
57
|
+
1, 0, 0, 0,
|
|
59
58
|
0, 0, 1, 0,
|
|
60
59
|
0, 0, 0, 1
|
|
61
60
|
]
|
|
@@ -3,5 +3,6 @@ export { default as area } from './area'
|
|
|
3
3
|
export { default as interpolateBetween2DPointsForY } from './interpolateBetween2DPointsForY'
|
|
4
4
|
export { default as intersect } from './intersect'
|
|
5
5
|
export { default as solve2Linear } from './solve2Linear'
|
|
6
|
+
export { sin, cos } from './trigonometry'
|
|
6
7
|
|
|
7
8
|
export as namespace utils
|
package/src/maths/utils/index.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
aboutEqualNormals: require('./aboutEqualNormals'),
|
|
9
9
|
area: require('./area'),
|
|
10
|
+
cos: require('./trigonometry').cos,
|
|
10
11
|
interpolateBetween2DPointsForY: require('./interpolateBetween2DPointsForY'),
|
|
11
12
|
intersect: require('./intersect'),
|
|
13
|
+
sin: require('./trigonometry').sin,
|
|
12
14
|
solve2Linear: require('./solve2Linear')
|
|
13
15
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { sin, cos } = require('../utils/trigonometry')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Create a new vector in the direction of the given angle.
|
|
3
5
|
*
|
|
@@ -7,8 +9,8 @@
|
|
|
7
9
|
* @alias module:modeling/maths/vec2.fromAngleRadians
|
|
8
10
|
*/
|
|
9
11
|
const fromAngleRadians = (out, radians) => {
|
|
10
|
-
out[0] =
|
|
11
|
-
out[1] =
|
|
12
|
+
out[0] = cos(radians)
|
|
13
|
+
out[1] = sin(radians)
|
|
12
14
|
return out
|
|
13
15
|
}
|
|
14
16
|
|
package/src/maths/vec2/length.js
CHANGED
|
@@ -25,15 +25,5 @@ test('vec2: length() should return correct values', (t) => {
|
|
|
25
25
|
const length5 = length(vec5)
|
|
26
26
|
nearlyEqual(t, length5, 2.23606, EPS)
|
|
27
27
|
|
|
28
|
-
// huge vector
|
|
29
|
-
const vec6 = fromValues(1e200, 1e200)
|
|
30
|
-
const length6 = length(vec6)
|
|
31
|
-
nearlyEqual(t, length6, Math.SQRT2 * 1e200, EPS)
|
|
32
|
-
|
|
33
|
-
// tiny vector
|
|
34
|
-
const vec7 = fromValues(1e-200, 1e-200)
|
|
35
|
-
const length7 = length(vec7)
|
|
36
|
-
nearlyEqual(t, length7, Math.SQRT2 * 1e-200, EPS)
|
|
37
|
-
|
|
38
28
|
t.true(true)
|
|
39
29
|
})
|
package/src/maths/vec3/angle.js
CHANGED
|
@@ -15,8 +15,8 @@ const angle = (a, b) => {
|
|
|
15
15
|
const bx = b[0]
|
|
16
16
|
const by = b[1]
|
|
17
17
|
const bz = b[2]
|
|
18
|
-
const mag1 = Math.
|
|
19
|
-
const mag2 = Math.
|
|
18
|
+
const mag1 = Math.sqrt(ax * ax + ay * ay + az * az)
|
|
19
|
+
const mag2 = Math.sqrt(bx * bx + by * by + bz * bz)
|
|
20
20
|
const mag = mag1 * mag2
|
|
21
21
|
const cosine = mag && dot(a, b) / mag
|
|
22
22
|
return Math.acos(Math.min(Math.max(cosine, -1), 1))
|
|
@@ -30,17 +30,5 @@ test('vec3: angle() should return correct values', (t) => {
|
|
|
30
30
|
const angle5 = angle(vec5a, vec5b)
|
|
31
31
|
nearlyEqual(t, angle5, 0.785398, EPS)
|
|
32
32
|
|
|
33
|
-
// tiny values
|
|
34
|
-
const vec6a = fromValues(1, 0, 0)
|
|
35
|
-
const vec6b = fromValues(1e-200, 1e-200, 0)
|
|
36
|
-
const angle6 = angle(vec6a, vec6b)
|
|
37
|
-
nearlyEqual(t, angle6, 0.785398, EPS)
|
|
38
|
-
|
|
39
|
-
// huge values
|
|
40
|
-
const vec7a = fromValues(1, 0, 0)
|
|
41
|
-
const vec7b = fromValues(1e200, 1e200, 0)
|
|
42
|
-
const angle7 = angle(vec7a, vec7b)
|
|
43
|
-
nearlyEqual(t, angle7, 0.785398, EPS)
|
|
44
|
-
|
|
45
33
|
t.true(true)
|
|
46
34
|
})
|
package/src/maths/vec3/length.js
CHANGED
|
@@ -41,15 +41,5 @@ test('vec3: length() should return correct values', (t) => {
|
|
|
41
41
|
const length9 = length(vec9)
|
|
42
42
|
nearlyEqual(t, length9, 3.74165, EPS)
|
|
43
43
|
|
|
44
|
-
// huge vector
|
|
45
|
-
const vec10 = fromValues(1e200, 0, 1e200)
|
|
46
|
-
const length10 = length(vec10)
|
|
47
|
-
nearlyEqual(t, length10, Math.SQRT2 * 1e200, EPS)
|
|
48
|
-
|
|
49
|
-
// tiny vector
|
|
50
|
-
const vec11 = fromValues(1e-200, 0, 1e-200)
|
|
51
|
-
const length11 = length(vec11)
|
|
52
|
-
nearlyEqual(t, length11, Math.SQRT2 * 1e-200, EPS)
|
|
53
|
-
|
|
54
44
|
t.true(true)
|
|
55
45
|
})
|
|
@@ -132,8 +132,8 @@ class PolygonTreeNode {
|
|
|
132
132
|
const polygon = this.polygon
|
|
133
133
|
if (polygon) {
|
|
134
134
|
const bound = poly3.measureBoundingSphere(polygon)
|
|
135
|
-
const sphereradius = bound[
|
|
136
|
-
const spherecenter = bound
|
|
135
|
+
const sphereradius = bound[3] + EPS // ensure radius is LARGER then polygon
|
|
136
|
+
const spherecenter = bound
|
|
137
137
|
const d = vec3.dot(splane, spherecenter) - splane[3]
|
|
138
138
|
if (d > sphereradius) {
|
|
139
139
|
frontnodes.push(this)
|