-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorus.js
52 lines (45 loc) · 1.06 KB
/
torus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict'
const PrimitiveTorus = require('primitive-torus')
const { Geometry } = require('axis3d')
module.exports = TorusGeometry
function TorusGeometry(opts) {
// ensure object
if (null == opts || 'object' != typeof opts) {
opts = {}
}
let {
majorSegments,
minorSegments,
majorRadius,
minorRadius,
arc
} = opts
// defaults
if (null == majorSegments ) { majorSegments = 32 }
if (null == minorSegments ) { minorSegments = 64 }
if (null == majorRadius ) { majorRadius = 1 }
if (null == minorRadius ) { minorRadius = 0.5 }
if (null == arc ) { arc = 2*Math.PI }
for (const k in opts) {
if (opts.hasOwnProperty(k) && 'number' != typeof opts[k]) {
throw new TypeError(
`Expecting '${k}' to be a number. Got ${typeof opts[k]}.`)
}
}
const torus = new Geometry({
complex: PrimitiveTorus({
majorSegments,
minorSegments,
majorRadius,
minorRadius,
arc
})
})
return Object.assign(torus, {
majorSegments,
minorSegments,
majorRadius,
minorRadius,
arc
})
}