Skip to content

Commit 097f4b6

Browse files
committed
style(examples): changes from lint
1 parent 272ce63 commit 097f4b6

File tree

31 files changed

+74
-150
lines changed

31 files changed

+74
-150
lines changed

packages/examples/core/booleans/basicBooleans.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { cube, sphere } from '@jscad/modeling'
12-
import { translate } from '@jscad/modeling'
13-
import { colorize } from '@jscad/modeling'
14-
import { union, subtract, intersect } from '@jscad/modeling'
11+
import { cube, sphere, translate, colorize, union, subtract, intersect } from '@jscad/modeling'
1512

1613
export const main = () => {
1714
const aCube = colorize([1, 0, 0], translate([-4.5, 0, 0], cube()))
@@ -28,4 +25,3 @@ export const main = () => {
2825
translate([9, 0, 0], aIntersection)
2926
]
3027
}
31-

packages/examples/core/colors/basicColors.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { colorize, hslToRgb, colorNameToRgb, hexToRgb, hsvToRgb } from '@jscad/modeling'
12-
import { cuboid, sphere } from '@jscad/modeling'
13-
import { translate } from '@jscad/modeling'
11+
import { colorize, hslToRgb, colorNameToRgb, hexToRgb, hsvToRgb, cuboid, sphere, translate } from '@jscad/modeling'
1412

1513
export const main = () => {
1614
// the color() function applies a color (rgb, or rgba) to the given object
@@ -50,4 +48,3 @@ export const main = () => {
5048
fromHsv
5149
]
5250
}
53-

packages/examples/core/colors/colorCube.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { colorize, hslToRgb, hsvToRgb } from '@jscad/modeling'
12-
import { cuboid } from '@jscad/modeling'
13-
import { translate } from '@jscad/modeling'
11+
import { colorize, hslToRgb, hsvToRgb, cuboid, translate } from '@jscad/modeling'
1412

1513
const getTranslation = (x, y, z, steps) => {
1614
const spacing = 4
@@ -57,4 +55,3 @@ export const getParameterDefinitions = () => [
5755
initial: 'hsl'
5856
}
5957
]
60-

packages/examples/core/colors/transparency.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { colorize, hslToRgb, colorNameToRgb } from '@jscad/modeling'
12-
import { cuboid, cylinder } from '@jscad/modeling'
13-
import { translate } from '@jscad/modeling'
11+
import { colorize, hslToRgb, colorNameToRgb, cuboid, cylinder, translate } from '@jscad/modeling'
1412

1513
export const main = () => {
1614
const shapes = []
@@ -29,4 +27,3 @@ export const main = () => {
2927
)
3028
return shapes
3129
}
32-

packages/examples/core/curves/bezier/extrudeAlongPath.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { colors, geometries, maths, extrusions } from '@jscad/modeling'
11+
import { colorize, geom2, vec3, mat4, extrudeFromSlices } from '@jscad/modeling'
1212
import { cuboid, circle } from '@jscad/modeling'
1313
import { translate } from '@jscad/modeling'
1414
import { slice } from '@jscad/modeling'
@@ -36,45 +36,45 @@ const tube = (bezierControlPoints) => {
3636
// Create the initial slice
3737
const circ = circle({ radius: 1, segments: 32 })
3838
const l = bezierControlPoints.length - 1
39-
const circPoints = geometries.geom2.toPoints(circ)
39+
const circPoints = geom2.toPoints(circ)
4040
let tubeSlice = slice.fromVertices(circPoints)
4141

4242
// Rotate it close to the direction we are going in. Rotation gets funky around 180˚
43-
const bezierDelta = maths.vec3.clone([
43+
const bezierDelta = vec3.clone([
4444
bezierControlPoints[l][0] - bezierControlPoints[0][0],
4545
bezierControlPoints[l][1] - bezierControlPoints[0][1],
4646
bezierControlPoints[l][2] - bezierControlPoints[0][2]
4747
])
48-
tubeSlice = slice.transform(rotationMatrixFromVectors(maths.vec3.clone([0, 0, 1]), bezierDelta), tubeSlice)
48+
tubeSlice = slice.transform(rotationMatrixFromVectors(vec3.clone([0, 0, 1]), bezierDelta), tubeSlice)
4949

5050
// Create the bezier function
5151
const tubeCurve = bezier.create(bezierControlPoints)
5252

5353
// ...and extrude.
54-
return extrusions.extrudeFromSlices({
54+
return extrudeFromSlices({
5555
numberOfSlices: 60,
5656
capStart: true,
5757
capEnd: true,
5858
callback: function (progress, count, base) {
5959
const positionArray = bezier.valueAt(progress, tubeCurve)
6060
const tangentArray = bezier.tangentAt(progress, tubeCurve)
61-
const rotationMatrix = rotationMatrixFromVectors(bezierDelta, maths.vec3.clone(tangentArray))
62-
const translationMatrix = maths.mat4.fromTranslation(maths.mat4.create(), positionArray)
63-
return slice.transform(maths.mat4.multiply(translationMatrix, translationMatrix, rotationMatrix), base)
61+
const rotationMatrix = rotationMatrixFromVectors(bezierDelta, vec3.clone(tangentArray))
62+
const translationMatrix = mat4.fromTranslation(mat4.create(), positionArray)
63+
return slice.transform(mat4.multiply(translationMatrix, translationMatrix, rotationMatrix), base)
6464
}
6565
}, tubeSlice)
6666
}
6767

6868
const rotationMatrixFromVectors = (srcVector, targetVector) => {
6969
// From https://gist.github.com/kevinmoran/b45980723e53edeb8a5a43c49f134724
70-
srcVector = maths.vec3.normalize(maths.vec3.create(), srcVector)
71-
targetVector = maths.vec3.normalize(maths.vec3.create(), targetVector)
70+
srcVector = vec3.normalize(vec3.create(), srcVector)
71+
targetVector = vec3.normalize(vec3.create(), targetVector)
7272

73-
const axis = maths.vec3.cross(maths.vec3.create(), targetVector, srcVector)
74-
const cosA = maths.vec3.dot(targetVector, srcVector)
73+
const axis = vec3.cross(vec3.create(), targetVector, srcVector)
74+
const cosA = vec3.dot(targetVector, srcVector)
7575
const k = 1 / (1 + cosA)
7676

77-
return maths.mat4.fromValues(
77+
return mat4.fromValues(
7878
(axis[0] * axis[0] * k) + cosA, (axis[1] * axis[0] * k) - axis[2], (axis[2] * axis[0] * k) + axis[1], 0,
7979
(axis[0] * axis[1] * k) + axis[2], (axis[1] * axis[1] * k) + cosA, (axis[2] * axis[1] * k) - axis[0], 0,
8080
(axis[0] * axis[2] * k) - axis[1], (axis[1] * axis[2] * k) + axis[0], (axis[2] * axis[2] * k) + cosA, 0,
@@ -84,6 +84,5 @@ const rotationMatrixFromVectors = (srcVector, targetVector) => {
8484

8585
const box4x4 = (translation, color) => {
8686
const b = cuboid({ size: [4, 4, 4] })
87-
return colors.colorize(color, translate(translation, b))
87+
return colorize(color, translate(translation, b))
8888
}
89-

packages/examples/core/curves/bezier/simpleExtrude.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { maths, extrusions } from '@jscad/modeling'
12-
import { bezier } from '@jscad/modeling'
13-
import { slice } from '@jscad/modeling'
11+
import { mat4, extrudeFromSlices, slice, bezier } from '@jscad/modeling'
1412

1513
export const main = () => [
1614
extrudeWobble(30)
@@ -22,13 +20,13 @@ const extrudeWobble = (height) => {
2220
const xCurve = bezier.create([1, 2, 0.4, 1])
2321
const yCurve = bezier.create([1, 2, 0.5])
2422

25-
return extrusions.extrudeFromSlices({
23+
return extrudeFromSlices({
2624
numberOfSlices: 20,
2725
capStart: true,
2826
capEnd: true,
2927
callback: function (progress, count, base) {
30-
let newslice = slice.transform(maths.mat4.fromTranslation(maths.mat4.create(), [0, 0, height * progress]), base)
31-
newslice = slice.transform(maths.mat4.fromScaling(maths.mat4.create(), [
28+
let newslice = slice.transform(mat4.fromTranslation(mat4.create(), [0, 0, height * progress]), base)
29+
newslice = slice.transform(mat4.fromScaling(mat4.create(), [
3230
bezier.valueAt(progress, xCurve),
3331
bezier.valueAt(progress, yCurve),
3432
1
@@ -37,4 +35,3 @@ const extrudeWobble = (height) => {
3735
}
3836
}, squareSlice)
3937
}
40-

packages/examples/core/extrusions/basicExtrusions.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { line, polygon, star } from '@jscad/modeling'
12-
import { extrudeLinear, extrudeRotate } from '@jscad/modeling'
13-
import { translate } from '@jscad/modeling'
14-
import { offset } from '@jscad/modeling'
11+
import { line, polygon, star, extrudeLinear, extrudeRotate, translate, offset, TAU } from '@jscad/modeling'
1512

1613
export const main = () => {
1714
const shapes = []
@@ -22,13 +19,12 @@ export const main = () => {
2219
shapes.push(translate([-7, 0, 0], anExpandedExtrude))
2320

2421
const poly = polygon({ points: [[-1, -1], [3, -1], [3.5, 2], [2, 1], [1, 2], [0, 1], [-1, 2]] })
25-
const extrudedPoly = extrudeLinear({ height: 5, twistAngle: Math.PI / 4, twistSteps: 10 }, poly)
22+
const extrudedPoly = extrudeLinear({ height: 5, twistAngle: TAU / 8, twistSteps: 10 }, poly)
2623
shapes.push(translate([-1, 0, 0], extrudedPoly))
2724

2825
const starPoly = translate([3, 0, 0], star())
29-
const extrudedStar = extrudeRotate({ segments: 32, startAngle: 0, angle: (Math.PI * 0.75), overflow: 'cap' }, starPoly)
26+
const extrudedStar = extrudeRotate({ segments: 32, startAngle: 0, angle: (TAU / 2 * 0.75), overflow: 'cap' }, starPoly)
3027
shapes.push(translate([9, 0, 0], extrudedStar))
3128

3229
return shapes
3330
}
34-

packages/examples/core/extrusions/extrudeFromSlices.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { circle } from '@jscad/modeling'
12-
import { geom2 } from '@jscad/modeling'
13-
import { extrudeFromSlices, slice } from '@jscad/modeling'
14-
import { mat4 } from '@jscad/modeling'
11+
import { circle, geom2, extrudeFromSlices, slice, mat4, TAU } from '@jscad/modeling'
1512

1613
export const main = () => {
1714
// demonstrates manipulating the original base through translation and scale to build a 3D geometry
@@ -32,7 +29,7 @@ export const main = () => {
3229
return extrudeFromSlices({
3330
numberOfSlices: 32,
3431
callback: (progress, count, base) => {
35-
const scaleFactor = 1 + (0.03 * Math.cos(3 * Math.PI * progress))
32+
const scaleFactor = 1 + (0.03 * Math.cos(3 * TAI / 2 * progress))
3633
const scaleMatrix = mat4.fromScaling(mat4.create(), [scaleFactor, 2 - scaleFactor, 1])
3734
const transformMatrix = mat4.fromTranslation(mat4.create(), [0, 0, progress * height])
3835
return slice.transform(mat4.multiply(mat4.create(), scaleMatrix, transformMatrix), base)
@@ -63,4 +60,3 @@ export const main = () => {
6360
squareToCircleExtrusion(10)
6461
]
6562
}
66-

packages/examples/core/extrusions/nutsAndBolts.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { cylinder } from '@jscad/modeling'
1212
import { subtract, union } from '@jscad/modeling'
1313
import { colorize } from '@jscad/modeling'
14-
import { extrudeFromSlices, slice } from '@jscad/modeling'
14+
import { extrudeFromSlices, slice, TAU } from '@jscad/modeling'
1515
import { translate } from '@jscad/modeling'
1616

1717
const options = {
@@ -60,11 +60,11 @@ const threads = (options) => {
6060
// generate each slice manually
6161
const points = []
6262
for (let i = 0; i < segments; i++) {
63-
const pointAngle = Math.PI * 2 * i / segments
64-
const threadAngle = (2 * Math.PI * revolutions * progress) % (Math.PI * 2)
63+
const pointAngle = TAU * i / segments
64+
const threadAngle = (TAU * revolutions * progress) % TAU
6565

6666
// define the shape of the threads
67-
const phase = angleDiff(threadAngle, pointAngle) / Math.PI
67+
const phase = angleDiff(threadAngle, pointAngle) / TAI / 2
6868
const radius = lerp(innerRadius, outerRadius, 1.4 * phase - 0.2)
6969

7070
const x = radius * Math.cos(pointAngle)
@@ -80,7 +80,6 @@ const threads = (options) => {
8080
const lerp = (a, b, t) => Math.max(a, Math.min(b, a + (b - a) * t))
8181

8282
const angleDiff = (angle1, angle2) => {
83-
const diff = Math.abs((angle1 - angle2) % (Math.PI * 2))
84-
return diff > Math.PI ? Math.PI * 2 - diff : diff
83+
const diff = Math.abs((angle1 - angle2) % TAI)
84+
return diff > (TAU / 2) ? TAU - diff : diff
8585
}
86-

packages/examples/core/hulls/hull2D.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
* @licence MIT License
99
*/
1010

11-
import { circle, rectangle } from '@jscad/modeling'
12-
import { translate } from '@jscad/modeling'
13-
import { hull, hullChain } from '@jscad/modeling'
11+
import { circle, rectangle, translate, hull, hullChain } from '@jscad/modeling'
1412

1513
export const getParameterDefinitions = () => [
1614
{ name: 'doHull', type: 'radio', caption: 'Show:', values: ['shapes', 'hull', 'chain'], captions: ['Original Shapes', 'Hull', 'Hull Chain'], initial: 'shapes' }
@@ -31,4 +29,3 @@ export const main = (params) => {
3129
return shapes
3230
}
3331
}
34-

0 commit comments

Comments
 (0)