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 CHANGED
@@ -1,5 +1,5 @@
1
1
  // elliptical and circular arcs using start and end angles
2
2
  <Group>
3
- <Arc pos={[0.32, 0.5]} size={[0.44, 0.32]} start={-45} end={210} stroke={blue} stroke-width={2} />
4
- <Arc pos={[0.72, 0.5]} size={0.32} start={90} end={-150} stroke={red} stroke-width={2} />
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>
@@ -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>
@@ -1,3 +1,5 @@
1
- // create a custom triangle element called `Tri` and use it to create a triangle with a gray fill
2
- const Tri = ({ pos0, pos1, pos2, ...attr }) => <Shape {...attr} points={[pos0, pos1, pos2]} />
3
- return <Tri pos0={[0.5, 0.1]} pos1={[0.9, 0.9]} pos2={[0.1, 0.9]} fill={gray} />
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>
@@ -1,13 +1,8 @@
1
- // draw a diagonal line in blue and a cup shaped line in red
2
- <Group>
3
- <Line stroke={blue} points={[
4
- [0.2, 0.2],
5
- [0.8, 0.8],
6
- ]} />
7
- <Line stroke={red} points={[
8
- [0.3, 0.3],
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>
@@ -1,14 +1,10 @@
1
- // use polar to place points around a circle
2
- const center = [0.5, 0.5]
3
- const ring = range(10).map(i => {
4
- const radius = i % 2 == 0 ? 0.32 : 0.16
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
- const spokes = range(5).map(i => polar([0.32, -90 + 72 * i], center))
8
-
9
- return <Group aspect={1}>
10
- <Circle pos={center} size={0.64} stroke={darkgray} />
11
- <Shape points={ring} stroke={blue} stroke-width={2} />
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.10, 0.20],
5
- [0.40, 0.20],
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 <Frame margin>
12
- <Line opacity={0.3} points={points} />
13
- <RoundedLine stroke={blue} stroke-width={2} radius={0.08} points={points} />
14
- <Points point-size={0.015} points={points} />
15
- </Frame>
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>
@@ -1,14 +1,8 @@
1
- // draw a blue triangle with a semi-transparent green square overlaid on top
2
- <Group>
3
- <Shape fill={blue} stroke={none} points={[
4
- [0.5, 0.2],
5
- [0.8, 0.8],
6
- [0.2, 0.8]
7
- ]} />
8
- <Shape fill={green} stroke={none} opacity={0.5} points={[
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>
@@ -7,7 +7,9 @@ const points = [
7
7
  [0.50, 0.50],
8
8
  ]
9
9
  return <Frame rounded margin>
10
- <Spline closed stroke={blue} fill={gray} points={points} />
11
- <Shape stroke={red} points={points} />
12
- <Points point-size={0.02} points={points} />
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>
@@ -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=50)` — generate an array of `n` evenly spaced values between `x0` and `x1`
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([radius, angle], center=[0, 0])` — convert polar coordinates to a 2D point
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([rodLen, rodRot], [pivotX, pivotY])
22
- const [ midX, midY ] = polar([0.50 * rodLen, rodRot], [pivotX, pivotY])
23
- const [ tenX, tenY ] = polar([0.75 * rodLen, rodRot], [pivotX, pivotY])
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([1, t * r2d]))
12
- const points1 = theta1.map(t => polar([R, t * r2d]))
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gum-jsx",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "Language for vector graphics generation.",
5
5
  "type": "module",
6
6
  "author": "Douglas Hanley",
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(start: number, end: number, step: number): number[]
119
- function linspace(start: number, end: number, num: number): number[]
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:
@@ -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(start: number, end: number, step: number): number[]
124
- function linspace(start: number, end: number, num: number): number[]
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: create a custom triangle element called `Tri` and use it to create a triangle with a gray fill
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
- const Tri = ({ pos0, pos1, pos2, ...attr }) => <Shape {...attr} points={[pos0, pos1, pos2]} />
196
- return <Tri pos0={[0.5, 0.1]} pos1={[0.9, 0.9]} pos2={[0.1, 0.9]} fill={gray} />
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([rodLen, rodRot], [pivotX, pivotY])
33
- const [ midX, midY ] = polar([0.50 * rodLen, rodRot], [pivotX, pivotY])
34
- const [ tenX, tenY ] = polar([0.75 * rodLen, rodRot], [pivotX, pivotY])
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([1, t * r2d]))
23
- const points1 = theta1.map(t => polar([R, t * r2d]))
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.32, 0.5]} size={[0.44, 0.32]} start={-45} end={210} stroke={blue} stroke-width={2} />
61
- <Arc pos={[0.72, 0.5]} size={0.32} start={90} end={-150} stroke={red} stroke-width={2} />
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 diagonal line in blue and a cup shaped line in red
80
+ Prompt: draw a piecewise line spiraling outwards (with dots at vertices)
81
81
 
82
82
  Generated code:
83
83
  ```jsx
84
- <Group>
85
- <Line stroke={blue} points={[
86
- [0.2, 0.2],
87
- [0.8, 0.8],
88
- ]} />
89
- <Line stroke={red} points={[
90
- [0.3, 0.3],
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 blue triangle with a semi-transparent green square overlaid on top
106
+ Prompt: draw a stop sign
112
107
 
113
108
  Generated code:
114
109
  ```jsx
115
- <Group>
116
- <Shape fill={blue} stroke={none} points={[
117
- [0.5, 0.2],
118
- [0.8, 0.8],
119
- [0.2, 0.8]
120
- ]} />
121
- <Shape fill={green} stroke={none} opacity={0.5} points={[
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
- <Spline closed stroke={blue} fill={gray} points={points} />
191
- <Shape stroke={red} points={points} />
192
- <Points point-size={0.02} points={points} />
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.10, 0.20],
257
- [0.40, 0.20],
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 <Frame margin>
264
- <Line opacity={0.3} points={points} />
265
- <RoundedLine stroke={blue} stroke-width={2} radius={0.08} points={points} />
266
- <Points point-size={0.015} points={points} />
267
- </Frame>
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([radius, angle], center=[0, 0])` — convert polar coordinates to a 2D point
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: use polar to place points around a circle
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 center = [0.5, 0.5]
43
- const ring = range(10).map(i => {
44
- const radius = i % 2 == 0 ? 0.32 : 0.16
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
- const spokes = range(5).map(i => polar([0.32, -90 + 72 * i], center))
48
-
49
- return <Group aspect={1}>
50
- <Circle pos={center} size={0.64} stroke={darkgray} />
51
- <Shape points={ring} stroke={blue} stroke-width={2} />
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=50)` — generate an array of `n` evenly spaced values between `x0` and `x1`
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([ proj, rotate ])
121
+ const vec = polar(rotate, proj)
122
122
  return vector_angle(vec)
123
123
  }
124
124
 
@@ -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([ [ rx, ry ], theta ], [ x, y ])
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([0.5, t], [0.5, 0.5]))
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, n: number, end: boolean = true): number[] {
227
- if (end && n == 1) return [ 0.5 * (x0 + x1) ]
228
- const n1 = end ? n : n + 1
229
- const step = (x1 - x0) / (n1 - 1)
230
- const values = [...Array(n1).keys()].map(i => x0 + step * i)
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([radius, angle]: Polar, center?: Point): Point {
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
  }