gum-jsx 1.6.1 → 1.6.2
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/docs/code/Arc.jsx +3 -3
- package/docs/code/Axis.jsx +1 -1
- package/docs/code/Element.jsx +5 -3
- package/docs/code/Line.jsx +8 -13
- package/docs/code/Math.jsx +9 -13
- package/docs/code/RoundedLine.jsx +7 -11
- package/docs/code/Shape.jsx +8 -14
- package/docs/code/Spline.jsx +5 -3
- package/docs/text/Arrays.md +1 -1
- package/docs/text/Math.md +1 -1
- package/gala/code/pendulum_physics.jsx +3 -3
- package/gala/code/spline_star.jsx +2 -2
- package/package.json +1 -1
- package/prompt/intro.md +2 -3
- package/skills/gum-jsx/SKILL.md +7 -6
- package/skills/gum-jsx/references/gala/pendulum_physics.md +3 -3
- package/skills/gum-jsx/references/gala/spline_star.md +2 -2
- package/skills/gum-jsx/references/geometry.md +30 -43
- package/skills/gum-jsx/references/plotting.md +1 -1
- package/skills/gum-jsx/references/utilities.md +11 -15
- package/src/elems/core.ts +1 -1
- package/src/elems/geometry.ts +2 -2
- package/src/lib/utils.ts +6 -6
package/docs/code/Arc.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// elliptical and circular arcs using start and end angles
|
|
2
2
|
<Group>
|
|
3
|
-
<Arc pos={[0.
|
|
4
|
-
<Arc pos={[0.
|
|
5
|
-
</Group>
|
|
3
|
+
<Arc pos={[0.3, 0.5]} size={[0.4, 0.3]} start={-45} end={210} stroke={blue} stroke-width={2} />
|
|
4
|
+
<Arc pos={[0.7, 0.5]} size={0.3} start={90} end={-150} stroke={red} stroke-width={2} />
|
|
5
|
+
</Group>
|
package/docs/code/Axis.jsx
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
const emoji = ['🗻', '🚀', '🐳', '🍉', '🍩']
|
|
3
3
|
const ticks = zip(linspace(0, 1, emoji.length), emoji)
|
|
4
4
|
return <Box padding={[0.5, 1]}>
|
|
5
|
-
<HAxis aspect={10} ticks={ticks} tick-side="outer" label-size={1} />
|
|
5
|
+
<HAxis aspect={10} ticks={ticks} tick-side="outer" label-size={1} label-offset={0.25} />
|
|
6
6
|
</Box>
|
package/docs/code/Element.jsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// draw a 2x1 rectangle in red with a blue square embedded within it
|
|
2
|
+
<Group aspect={2}>
|
|
3
|
+
<Rect stroke={red} />
|
|
4
|
+
<Square stroke={blue} />
|
|
5
|
+
</Group>
|
package/docs/code/Line.jsx
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
// draw a
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[0.3, 0.7],
|
|
10
|
-
[0.7, 0.7],
|
|
11
|
-
[0.7, 0.3],
|
|
12
|
-
]} />
|
|
13
|
-
</Group>
|
|
1
|
+
// draw a piecewise line spiraling outwards (with dots at vertices)
|
|
2
|
+
const spiral = linspace(0, 5, 25).map(t => polar(360 * t, t/5))
|
|
3
|
+
return <Box margin>
|
|
4
|
+
<Graph coord={[-1, -1, 1, 1]}>
|
|
5
|
+
<Line points={spiral} />
|
|
6
|
+
<Points points={spiral} point-size={0.03} />
|
|
7
|
+
</Graph>
|
|
8
|
+
</Box>
|
package/docs/code/Math.jsx
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
return polar([radius, -90 + 36 * i], center)
|
|
1
|
+
// embed a five point star in a circle. place red dots at its vertices.
|
|
2
|
+
const verts = linspace(0, 360, 10, false).map((t, i) => {
|
|
3
|
+
const radius = i % 2 == 0 ? 1 : 0.5
|
|
4
|
+
return polar(90 + t, radius)
|
|
6
5
|
})
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
{spokes.map(pos => <Line points={[center, pos]} stroke={red} stroke-width={1.5} />)}
|
|
13
|
-
{ring.map(pos => <Dot pos={pos} size={0.03} fill={blue} />)}
|
|
14
|
-
</Group>
|
|
6
|
+
return <Graph aspect coord={[-1, -1, 1, 1]}>
|
|
7
|
+
<Circle pos={[0, 0]} size={2} stroke={darkgray} />
|
|
8
|
+
<Shape points={verts} stroke={blue} stroke-width={2} />
|
|
9
|
+
{verts.map(pos => <Dot pos={pos} size={0.05} fill={red} />)}
|
|
10
|
+
</Graph>
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
// a city-block route in blue with rounded corners, with the underlying
|
|
2
2
|
// vertices marked as black dots to show how the corners are rounded
|
|
3
3
|
const points = [
|
|
4
|
-
[0.
|
|
5
|
-
[0.
|
|
6
|
-
[0.40, 0.80],
|
|
7
|
-
[0.70, 0.80],
|
|
8
|
-
[0.70, 0.50],
|
|
9
|
-
[0.90, 0.50],
|
|
4
|
+
[-0.8, 0.6], [-0.2, 0.6], [-0.2, -0.6],
|
|
5
|
+
[ 0.4, -0.6], [ 0.4, 0.0], [ 0.8, 0.0],
|
|
10
6
|
]
|
|
11
|
-
return <
|
|
12
|
-
<Line opacity={0.3}
|
|
13
|
-
<RoundedLine stroke={blue} stroke-width={2} radius={0.
|
|
14
|
-
<Points point-size={0.
|
|
15
|
-
</
|
|
7
|
+
return <Graph aspect padding>
|
|
8
|
+
<Line points={points} opacity={0.3} />
|
|
9
|
+
<RoundedLine points={points} stroke={blue} stroke-width={2} radius={0.1} />
|
|
10
|
+
<Points points={points} point-size={0.03} />
|
|
11
|
+
</Graph>
|
package/docs/code/Shape.jsx
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
// draw a
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[0.3, 0.3],
|
|
10
|
-
[0.7, 0.3],
|
|
11
|
-
[0.7, 0.7],
|
|
12
|
-
[0.3, 0.7]
|
|
13
|
-
]} />
|
|
14
|
-
</Group>
|
|
1
|
+
// draw a stop sign
|
|
2
|
+
const hexagon = linspace(0, 360, 8, false).map(t => polar(t))
|
|
3
|
+
return <Box fill="#bbb" rounded padding margin>
|
|
4
|
+
<Graph xlim={[-1, 1]} ylim={[-1, 1]} aspect={1}>
|
|
5
|
+
<Shape points={hexagon} fill="#CC0202" stroke={white} stroke_width={20} spin={180/8} />
|
|
6
|
+
<Text pos={[0, 0]} xsize={1.5} color={white} font-weight={bold}>STOP</Text>
|
|
7
|
+
</Graph>
|
|
8
|
+
</Box>
|
package/docs/code/Spline.jsx
CHANGED
|
@@ -7,7 +7,9 @@ const points = [
|
|
|
7
7
|
[0.50, 0.50],
|
|
8
8
|
]
|
|
9
9
|
return <Frame rounded margin>
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
<Group>
|
|
11
|
+
<Spline closed stroke={blue} fill={gray} points={points} />
|
|
12
|
+
<Shape stroke={red} points={points} />
|
|
13
|
+
<Points point-size={0.02} points={points} />
|
|
14
|
+
</Group>
|
|
13
15
|
</Frame>
|
package/docs/text/Arrays.md
CHANGED
|
@@ -16,7 +16,7 @@ There are a number of functions designed to make working with arrays easier. The
|
|
|
16
16
|
- `norm(arr, degree=1)` — compute the `degree`-norm of array `arr`
|
|
17
17
|
- `normalize(arr, degree=1)` — normalize array `arr` to have `degree`-norm one
|
|
18
18
|
- `range(i0, i1, step=1)` — generate an array of evenly spaced values from `i0` to `i1` with spacing `step`
|
|
19
|
-
- `linspace(x0, x1, n=
|
|
19
|
+
- `linspace(x0, x1, n, end=false)` — generate an array of `n` evenly spaced values between `x0` and `x1` (including `x1` if `end` is true)
|
|
20
20
|
- `enumerate(arr)` — pair each element of array `arr` with its index
|
|
21
21
|
- `repeat(x, n)` — repeat array `x` a total of `n` times
|
|
22
22
|
- `meshgrid(x, y)` — create a mesh grid from arrays `x` and `y`
|
package/docs/text/Math.md
CHANGED
|
@@ -27,6 +27,6 @@ Here we collect a variety of global mathematical functions and constants. You ca
|
|
|
27
27
|
- `round(x)` — the rounding function
|
|
28
28
|
- `clamp(x, lim=[0, 1])` — clamp `x` to the range `lim`
|
|
29
29
|
- `rescale(x, lim=[0, 1])` — linearly rescale `x` to the range `lim`
|
|
30
|
-
- `polar(
|
|
30
|
+
- `polar(angle, radius=1, center=[0, 0])` — convert polar coordinates (`angle` in degrees, `radius` scalar or size vector) to a 2D point around `center`
|
|
31
31
|
|
|
32
32
|
Angles use gum's usual screen-space convention: `0` points right and `90` points down.
|
|
@@ -18,9 +18,9 @@ const arcRad = 0.25
|
|
|
18
18
|
// Computed positions
|
|
19
19
|
const rodRot = 90 - rodAng
|
|
20
20
|
const eqnY = pivotY + rodLen
|
|
21
|
-
const [ bobX, bobY ] = polar(
|
|
22
|
-
const [ midX, midY ] = polar(
|
|
23
|
-
const [ tenX, tenY ] = polar(
|
|
21
|
+
const [ bobX, bobY ] = polar(rodRot, rodLen, [pivotX, pivotY])
|
|
22
|
+
const [ midX, midY ] = polar(rodRot, 0.50 * rodLen, [pivotX, pivotY])
|
|
23
|
+
const [ tenX, tenY ] = polar(rodRot, 0.75 * rodLen, [pivotX, pivotY])
|
|
24
24
|
|
|
25
25
|
return <Box margin={0.06}>
|
|
26
26
|
<VStack spacing={0.05}>
|
|
@@ -8,8 +8,8 @@ const theta0 = linspace(0, 2 * pi, n, false).map(t => t - pi / 2)
|
|
|
8
8
|
const theta1 = theta0.map(t => t + pi / n)
|
|
9
9
|
|
|
10
10
|
// get inner/outer point positions
|
|
11
|
-
const points0 = theta0.map(t => polar(
|
|
12
|
-
const points1 = theta1.map(t => polar(
|
|
11
|
+
const points0 = theta0.map(t => polar(t * r2d))
|
|
12
|
+
const points1 = theta1.map(t => polar(t * r2d, R))
|
|
13
13
|
const points = zip(points0, points1).flat()
|
|
14
14
|
|
|
15
15
|
// return full spline
|
package/package.json
CHANGED
package/prompt/intro.md
CHANGED
|
@@ -115,11 +115,10 @@ Without specifying `stack-size`, the `Text` element would be quite large (it has
|
|
|
115
115
|
Here are the handy array functions provided by the library. All of these mimic the behavior of their counterparts in Python and `numpy`. This can be useful for generating `Element` objects from arrays:
|
|
116
116
|
```typescript
|
|
117
117
|
function zip(...arrs: any[]): any[]
|
|
118
|
-
function range(
|
|
119
|
-
function linspace(
|
|
118
|
+
function range(ia: number, ib?: number, step?: number = 1): number[]
|
|
119
|
+
function linspace(x0: number, x1: number, num: number, end?: boolean = false): number[]
|
|
120
120
|
function enumerate(x: any[]): any[]
|
|
121
121
|
function repeat(x: any, n: number): any[]
|
|
122
|
-
function lingrid(xlim: range, ylim: range, N: number): number[][]
|
|
123
122
|
```
|
|
124
123
|
|
|
125
124
|
Some of the most commonly used mathematical constants are pre-defined in the global scope:
|
package/skills/gum-jsx/SKILL.md
CHANGED
|
@@ -120,11 +120,10 @@ Without specifying `stack-size`, the `Text` element would be quite large (it has
|
|
|
120
120
|
Here are the handy array functions provided by the library. All of these mimic the behavior of their counterparts in Python and `numpy`. This can be useful for generating `Element` objects from arrays:
|
|
121
121
|
```typescript
|
|
122
122
|
function zip(...arrs: any[]): any[]
|
|
123
|
-
function range(
|
|
124
|
-
function linspace(
|
|
123
|
+
function range(ia: number, ib?: number, step?: number = 1): number[]
|
|
124
|
+
function linspace(x0: number, x1: number, num: number, end?: boolean = false): number[]
|
|
125
125
|
function enumerate(x: any[]): any[]
|
|
126
126
|
function repeat(x: any, n: number): any[]
|
|
127
|
-
function lingrid(xlim: range, ylim: range, N: number): number[][]
|
|
128
127
|
```
|
|
129
128
|
|
|
130
129
|
Some of the most commonly used mathematical constants are pre-defined in the global scope:
|
|
@@ -188,12 +187,14 @@ Methods:
|
|
|
188
187
|
|
|
189
188
|
**Example**
|
|
190
189
|
|
|
191
|
-
Prompt:
|
|
190
|
+
Prompt: draw a 2x1 rectangle in red with a blue square embedded within it
|
|
192
191
|
|
|
193
192
|
Generated code:
|
|
194
193
|
```jsx
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
<Group aspect={2}>
|
|
195
|
+
<Rect stroke={red} />
|
|
196
|
+
<Square stroke={blue} />
|
|
197
|
+
</Group>
|
|
197
198
|
```
|
|
198
199
|
|
|
199
200
|
## Group
|
|
@@ -29,9 +29,9 @@ const arcRad = 0.25
|
|
|
29
29
|
// Computed positions
|
|
30
30
|
const rodRot = 90 - rodAng
|
|
31
31
|
const eqnY = pivotY + rodLen
|
|
32
|
-
const [ bobX, bobY ] = polar(
|
|
33
|
-
const [ midX, midY ] = polar(
|
|
34
|
-
const [ tenX, tenY ] = polar(
|
|
32
|
+
const [ bobX, bobY ] = polar(rodRot, rodLen, [pivotX, pivotY])
|
|
33
|
+
const [ midX, midY ] = polar(rodRot, 0.50 * rodLen, [pivotX, pivotY])
|
|
34
|
+
const [ tenX, tenY ] = polar(rodRot, 0.75 * rodLen, [pivotX, pivotY])
|
|
35
35
|
|
|
36
36
|
return <Box margin={0.06}>
|
|
37
37
|
<VStack spacing={0.05}>
|
|
@@ -19,8 +19,8 @@ const theta0 = linspace(0, 2 * pi, n, false).map(t => t - pi / 2)
|
|
|
19
19
|
const theta1 = theta0.map(t => t + pi / n)
|
|
20
20
|
|
|
21
21
|
// get inner/outer point positions
|
|
22
|
-
const points0 = theta0.map(t => polar(
|
|
23
|
-
const points1 = theta1.map(t => polar(
|
|
22
|
+
const points0 = theta0.map(t => polar(t * r2d))
|
|
23
|
+
const points1 = theta1.map(t => polar(t * r2d, R))
|
|
24
24
|
const points = zip(points0, points1).flat()
|
|
25
25
|
|
|
26
26
|
// return full spline
|
|
@@ -57,8 +57,8 @@ Prompt: elliptical and circular arcs using start and end angles
|
|
|
57
57
|
Generated code:
|
|
58
58
|
```jsx
|
|
59
59
|
<Group>
|
|
60
|
-
<Arc pos={[0.
|
|
61
|
-
<Arc pos={[0.
|
|
60
|
+
<Arc pos={[0.3, 0.5]} size={[0.4, 0.3]} start={-45} end={210} stroke={blue} stroke-width={2} />
|
|
61
|
+
<Arc pos={[0.7, 0.5]} size={0.3} start={90} end={-150} stroke={red} stroke-width={2} />
|
|
62
62
|
</Group>
|
|
63
63
|
```
|
|
64
64
|
|
|
@@ -77,22 +77,17 @@ Parameters:
|
|
|
77
77
|
|
|
78
78
|
**Example**
|
|
79
79
|
|
|
80
|
-
Prompt: draw a
|
|
80
|
+
Prompt: draw a piecewise line spiraling outwards (with dots at vertices)
|
|
81
81
|
|
|
82
82
|
Generated code:
|
|
83
83
|
```jsx
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
[0.3, 0.7],
|
|
92
|
-
[0.7, 0.7],
|
|
93
|
-
[0.7, 0.3],
|
|
94
|
-
]} />
|
|
95
|
-
</Group>
|
|
84
|
+
const spiral = linspace(0, 5, 25).map(t => polar(360 * t, t/5))
|
|
85
|
+
return <Box margin>
|
|
86
|
+
<Graph coord={[-1, -1, 1, 1]}>
|
|
87
|
+
<Line points={spiral} />
|
|
88
|
+
<Points points={spiral} point-size={0.03} />
|
|
89
|
+
</Graph>
|
|
90
|
+
</Box>
|
|
96
91
|
```
|
|
97
92
|
|
|
98
93
|
## Shape
|
|
@@ -108,23 +103,17 @@ Parameters:
|
|
|
108
103
|
|
|
109
104
|
**Example**
|
|
110
105
|
|
|
111
|
-
Prompt: draw a
|
|
106
|
+
Prompt: draw a stop sign
|
|
112
107
|
|
|
113
108
|
Generated code:
|
|
114
109
|
```jsx
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
[0
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
[0.3, 0.3],
|
|
123
|
-
[0.7, 0.3],
|
|
124
|
-
[0.7, 0.7],
|
|
125
|
-
[0.3, 0.7]
|
|
126
|
-
]} />
|
|
127
|
-
</Group>
|
|
110
|
+
const hexagon = linspace(0, 360, 8, false).map(t => polar(t))
|
|
111
|
+
return <Box fill="#bbb" rounded padding margin>
|
|
112
|
+
<Graph xlim={[-1, 1]} ylim={[-1, 1]} aspect={1}>
|
|
113
|
+
<Shape points={hexagon} fill="#CC0202" stroke={white} stroke_width={20} spin={180/8} />
|
|
114
|
+
<Text pos={[0, 0]} xsize={1.5} color={white} font-weight={bold}>STOP</Text>
|
|
115
|
+
</Graph>
|
|
116
|
+
</Box>
|
|
128
117
|
```
|
|
129
118
|
|
|
130
119
|
## Fill
|
|
@@ -187,9 +176,11 @@ const points = [
|
|
|
187
176
|
[0.50, 0.50],
|
|
188
177
|
]
|
|
189
178
|
return <Frame rounded margin>
|
|
190
|
-
<
|
|
191
|
-
|
|
192
|
-
|
|
179
|
+
<Group>
|
|
180
|
+
<Spline closed stroke={blue} fill={gray} points={points} />
|
|
181
|
+
<Shape stroke={red} points={points} />
|
|
182
|
+
<Points point-size={0.02} points={points} />
|
|
183
|
+
</Group>
|
|
193
184
|
</Frame>
|
|
194
185
|
```
|
|
195
186
|
|
|
@@ -253,16 +244,12 @@ Generated code:
|
|
|
253
244
|
```jsx
|
|
254
245
|
// vertices marked as black dots to show how the corners are rounded
|
|
255
246
|
const points = [
|
|
256
|
-
[0.
|
|
257
|
-
[0.
|
|
258
|
-
[0.40, 0.80],
|
|
259
|
-
[0.70, 0.80],
|
|
260
|
-
[0.70, 0.50],
|
|
261
|
-
[0.90, 0.50],
|
|
247
|
+
[-0.8, 0.6], [-0.2, 0.6], [-0.2, -0.6],
|
|
248
|
+
[ 0.4, -0.6], [ 0.4, 0.0], [ 0.8, 0.0],
|
|
262
249
|
]
|
|
263
|
-
return <
|
|
264
|
-
<Line opacity={0.3}
|
|
265
|
-
<RoundedLine stroke={blue} stroke-width={2} radius={0.
|
|
266
|
-
<Points point-size={0.
|
|
267
|
-
</
|
|
250
|
+
return <Graph aspect padding>
|
|
251
|
+
<Line points={points} opacity={0.3} />
|
|
252
|
+
<RoundedLine points={points} stroke={blue} stroke-width={2} radius={0.1} />
|
|
253
|
+
<Points points={points} point-size={0.03} />
|
|
254
|
+
</Graph>
|
|
268
255
|
```
|
|
@@ -115,7 +115,7 @@ Generated code:
|
|
|
115
115
|
const emoji = ['🗻', '🚀', '🐳', '🍉', '🍩']
|
|
116
116
|
const ticks = zip(linspace(0, 1, emoji.length), emoji)
|
|
117
117
|
return <Box padding={[0.5, 1]}>
|
|
118
|
-
<HAxis aspect={10} ticks={ticks} tick-side="outer" label-size={1} />
|
|
118
|
+
<HAxis aspect={10} ticks={ticks} tick-side="outer" label-size={1} label-offset={0.25} />
|
|
119
119
|
</Box>
|
|
120
120
|
```
|
|
121
121
|
|
|
@@ -29,29 +29,25 @@ Here we collect a variety of global mathematical functions and constants. You ca
|
|
|
29
29
|
- `round(x)` — the rounding function
|
|
30
30
|
- `clamp(x, lim=[0, 1])` — clamp `x` to the range `lim`
|
|
31
31
|
- `rescale(x, lim=[0, 1])` — linearly rescale `x` to the range `lim`
|
|
32
|
-
- `polar(
|
|
32
|
+
- `polar(angle, radius=1, center=[0, 0])` — convert polar coordinates (`angle` in degrees, `radius` scalar or size vector) to a 2D point around `center`
|
|
33
33
|
|
|
34
34
|
Angles use gum's usual screen-space convention: `0` points right and `90` points down.
|
|
35
35
|
|
|
36
36
|
**Example**
|
|
37
37
|
|
|
38
|
-
Prompt:
|
|
38
|
+
Prompt: embed a five point star in a circle. place red dots at its vertices.
|
|
39
39
|
|
|
40
40
|
Generated code:
|
|
41
41
|
```jsx
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return polar([radius, -90 + 36 * i], center)
|
|
42
|
+
const verts = linspace(0, 360, 10, false).map((t, i) => {
|
|
43
|
+
const radius = i % 2 == 0 ? 1 : 0.5
|
|
44
|
+
return polar(90 + t, radius)
|
|
46
45
|
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
{spokes.map(pos => <Line points={[center, pos]} stroke={red} stroke-width={1.5} />)}
|
|
53
|
-
{ring.map(pos => <Dot pos={pos} size={0.03} fill={blue} />)}
|
|
54
|
-
</Group>
|
|
46
|
+
return <Graph aspect coord={[-1, -1, 1, 1]}>
|
|
47
|
+
<Circle pos={[0, 0]} size={2} stroke={darkgray} />
|
|
48
|
+
<Shape points={verts} stroke={blue} stroke-width={2} />
|
|
49
|
+
{verts.map(pos => <Dot pos={pos} size={0.05} fill={red} />)}
|
|
50
|
+
</Graph>
|
|
55
51
|
```
|
|
56
52
|
|
|
57
53
|
## Arrays
|
|
@@ -72,7 +68,7 @@ There are a number of functions designed to make working with arrays easier. The
|
|
|
72
68
|
- `norm(arr, degree=1)` — compute the `degree`-norm of array `arr`
|
|
73
69
|
- `normalize(arr, degree=1)` — normalize array `arr` to have `degree`-norm one
|
|
74
70
|
- `range(i0, i1, step=1)` — generate an array of evenly spaced values from `i0` to `i1` with spacing `step`
|
|
75
|
-
- `linspace(x0, x1, n=
|
|
71
|
+
- `linspace(x0, x1, n, end=false)` — generate an array of `n` evenly spaced values between `x0` and `x1` (including `x1` if `end` is true)
|
|
76
72
|
- `enumerate(arr)` — pair each element of array `arr` with its index
|
|
77
73
|
- `repeat(x, n)` — repeat array `x` a total of `n` times
|
|
78
74
|
- `meshgrid(x, y)` — create a mesh grid from arrays `x` and `y`
|
package/src/elems/core.ts
CHANGED
|
@@ -118,7 +118,7 @@ function adjust_rotate(rotate: number, prect: Rect, coord: Rect): number {
|
|
|
118
118
|
const csize = rect_size(coord)
|
|
119
119
|
const psize = rect_size(prect)
|
|
120
120
|
const proj = div2(psize, csize)
|
|
121
|
-
const vec = polar(
|
|
121
|
+
const vec = polar(rotate, proj)
|
|
122
122
|
return vector_angle(vec)
|
|
123
123
|
}
|
|
124
124
|
|
package/src/elems/geometry.ts
CHANGED
|
@@ -191,7 +191,7 @@ class Ray extends Line {
|
|
|
191
191
|
const [ rx, ry ] = ensure_vector(size, 2)
|
|
192
192
|
const points: Point[] = [
|
|
193
193
|
[ x, y ],
|
|
194
|
-
polar(
|
|
194
|
+
polar(theta, [ rx, ry ], [ x, y ])
|
|
195
195
|
]
|
|
196
196
|
super({ points, ...attr })
|
|
197
197
|
this.args = args
|
|
@@ -719,7 +719,7 @@ class Arc extends Path {
|
|
|
719
719
|
if (start == null || end == null) throw new Error('Must provide `start` and `end` angles')
|
|
720
720
|
const [ theta0, theta1 ] = upright_limits([ start, end ])
|
|
721
721
|
const large = (theta1 - theta0) > 180
|
|
722
|
-
const [ point0, point1 ] = [ theta0, theta1 ].map(t => polar(
|
|
722
|
+
const [ point0, point1 ] = [ theta0, theta1 ].map(t => polar(t, 0.5, [0.5, 0.5]))
|
|
723
723
|
const children = [ new MoveCmd(point0), new ArcCmd(point1, 0.5, true, large) ]
|
|
724
724
|
super({ children, upright, ...attr })
|
|
725
725
|
this.args = args
|
package/src/lib/utils.ts
CHANGED
|
@@ -223,11 +223,11 @@ function range(ia: number, ib?: number, step: number = 1): number[] {
|
|
|
223
223
|
return [...Array(n).keys()].map(i => i0 + step * i)
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
function linspace(x0: number, x1: number,
|
|
227
|
-
if (end &&
|
|
228
|
-
const
|
|
229
|
-
const step = (x1 - x0) / (
|
|
230
|
-
const values = [...Array(
|
|
226
|
+
function linspace(x0: number, x1: number, num: number, end: boolean = true): number[] {
|
|
227
|
+
if (end && num == 1) return [ 0.5 * (x0 + x1) ]
|
|
228
|
+
const num1 = end ? num : num + 1
|
|
229
|
+
const step = (x1 - x0) / (num1 - 1)
|
|
230
|
+
const values = [...Array(num1).keys()].map(i => x0 + step * i)
|
|
231
231
|
return end ? values : values.slice(0, -1)
|
|
232
232
|
}
|
|
233
233
|
|
|
@@ -799,7 +799,7 @@ function angle_direc(angle: Angle): Point {
|
|
|
799
799
|
return [ cos(d2r * angle), sin(d2r * angle) ]
|
|
800
800
|
}
|
|
801
801
|
|
|
802
|
-
function polar(
|
|
802
|
+
function polar(angle: number, radius: number | Size = 1, center?: Point): Point {
|
|
803
803
|
const offset = mul2(radius, angle_direc(angle))
|
|
804
804
|
return center ? add2(center, offset) : offset
|
|
805
805
|
}
|