Skip to content

Commit 4eddd3b

Browse files
committed
Allow blocks to be called inline with child argument type
1 parent 17eff01 commit 4eddd3b

8 files changed

Lines changed: 553 additions & 317 deletions

File tree

Examples/Chessboard.shape

Lines changed: 88 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ShapeScript document
22

3-
detail 16
3+
detail 32
44

55
define white 1 0.8
66
define black 0.1
@@ -45,16 +45,14 @@ color white
4545
for 1 to 2 {
4646
for 1 to 8 {
4747
union {
48-
lathe {
49-
path {
50-
point 0 0.6
51-
point -0.05 0.6
52-
curve -0.12 0.2
53-
point -0.25 0.1
54-
point -0.25 0
55-
point -0.25 0
56-
point 0 0
57-
}
48+
lathe path {
49+
point 0 0.6
50+
point -0.05 0.6
51+
curve -0.12 0.2
52+
point -0.25 0.1
53+
point -0.25 0
54+
point -0.25 0
55+
point 0 0
5856
}
5957
translate 0 0.6
6058
sphere { size 0.25 }
@@ -71,21 +69,19 @@ for 1 to 2 {
7169
color black
7270
for 1 to 2 {
7371
difference {
74-
lathe {
75-
path {
76-
point 0 0.7
77-
curve -0.15 0.7
78-
point -0.15 0.8
79-
point -0.2 0.8
80-
point -0.2 0.8
81-
point -0.2 0.7
82-
point -0.15 0.6
83-
curve -0.2 0.2
84-
point -0.3 0.1
85-
point -0.3 0
86-
point -0.3 0
87-
point 0 0
88-
}
72+
lathe path {
73+
point 0 0.7
74+
curve -0.15 0.7
75+
point -0.15 0.8
76+
point -0.2 0.8
77+
point -0.2 0.8
78+
point -0.2 0.7
79+
point -0.15 0.6
80+
curve -0.2 0.2
81+
point -0.3 0.1
82+
point -0.3 0
83+
point -0.3 0
84+
point 0 0
8985
}
9086
translate 0 0.8
9187
cube { size 0.4 0.1 0.1 }
@@ -103,31 +99,27 @@ for 1 to 2 {
10399
color black
104100
for 1 to 2 {
105101
union {
106-
lathe {
107-
path {
108-
point 0 0.6
109-
point -0.2 0.3
110-
curve -0.15 0.2
111-
point -0.28 0.1
112-
point -0.28 0
113-
point 0 0
114-
}
102+
lathe path {
103+
point 0 0.6
104+
point -0.2 0.3
105+
curve -0.15 0.2
106+
point -0.28 0.1
107+
point -0.28 0
108+
point 0 0
115109
}
116110
translate 0.04 0.05 0
117111
scale 0.9 0.9 0.2
118-
extrude {
119-
path {
120-
point 0 1
121-
point -0.3 0.9
122-
point -0.3 0.8
123-
point -0.1 0.8
124-
curve -0.32 0.5
125-
point -0.2 0.3
126-
point 0.13 0.3
127-
curve 0.11 0.5
128-
point 0.22 0.9
129-
point 0 1
130-
}
112+
extrude path {
113+
point 0 1
114+
point -0.3 0.9
115+
point -0.3 0.8
116+
point -0.1 0.8
117+
curve -0.32 0.5
118+
point -0.2 0.3
119+
point 0.13 0.3
120+
curve 0.11 0.5
121+
point 0.22 0.9
122+
point 0 1
131123
}
132124
}
133125
translate 0 0 -7
@@ -142,23 +134,21 @@ for 1 to 2 {
142134
color black
143135
for 1 to 2 {
144136
difference {
145-
lathe {
146-
path {
147-
point 0 1
148-
point -0.05 0.98
149-
point -0.04 0.94
150-
curve -0.14 0.8
151-
point -0.09 0.65
152-
point -0.09 0.65
153-
point -0.2 0.6
154-
point -0.2 0.58
155-
point -0.1 0.58
156-
curve -0.18 0.2
157-
point -0.28 0.1
158-
point -0.28 0
159-
point -0.28 0
160-
point 0 0
161-
}
137+
lathe path {
138+
point 0 1
139+
point -0.05 0.98
140+
point -0.04 0.94
141+
curve -0.14 0.8
142+
point -0.09 0.65
143+
point -0.09 0.65
144+
point -0.2 0.6
145+
point -0.2 0.58
146+
point -0.1 0.58
147+
curve -0.18 0.2
148+
point -0.28 0.1
149+
point -0.28 0
150+
point -0.28 0
151+
point 0 0
162152
}
163153
translate -0.1 1
164154
rotate -0.1 0 0
@@ -176,22 +166,20 @@ translate 4 0 0
176166
color black
177167
for 1 to 2 {
178168
union {
179-
lathe {
180-
path {
181-
point 0 1.29
182-
point -0.06 1.27
183-
point -0.04 1.22
184-
point -0.2 1.17
185-
point -0.1 0.95
186-
point -0.2 0.9
187-
point -0.2 0.88
188-
point -0.1 0.88
189-
curve -0.2 0.25
190-
point -0.35 0.1
191-
point -0.35 0
192-
point -0.35 0
193-
point 0 0
194-
}
169+
lathe path {
170+
point 0 1.29
171+
point -0.06 1.27
172+
point -0.04 1.22
173+
point -0.2 1.17
174+
point -0.1 0.95
175+
point -0.2 0.9
176+
point -0.2 0.88
177+
point -0.1 0.88
178+
curve -0.2 0.25
179+
point -0.35 0.1
180+
point -0.35 0
181+
point -0.35 0
182+
point 0 0
195183
}
196184
translate 0 1.35
197185
cube { size 0.075 0.15 0.04 }
@@ -206,31 +194,27 @@ translate 1 0 14
206194
color black
207195
for 1 to 2 {
208196
union {
209-
lathe {
210-
path {
211-
point 0 1.19
212-
point -0.06 1.17
213-
point -0.04 1.12
214-
point -0.15 1.07
215-
point 0 0.9
216-
}
197+
lathe path {
198+
point 0 1.19
199+
point -0.06 1.17
200+
point -0.04 1.12
201+
point -0.15 1.07
202+
point 0 0.9
217203
}
218204
difference {
219-
lathe {
220-
path {
221-
point -0 0.9
222-
point -0.18 1.15
223-
point -0.2 1.1
224-
point -0.1 0.9
225-
point -0.19 0.85
226-
point -0.19 0.83
227-
point -0.09 0.83
228-
curve -0.19 0.2
229-
point -0.32 0.1
230-
point -0.32 0
231-
point -0.32 0
232-
point 0 0
233-
}
205+
lathe path {
206+
point -0 0.9
207+
point -0.18 1.15
208+
point -0.2 1.1
209+
point -0.1 0.9
210+
point -0.19 0.85
211+
point -0.19 0.83
212+
point -0.09 0.83
213+
curve -0.19 0.2
214+
point -0.32 0.1
215+
point -0.32 0
216+
point -0.32 0
217+
point 0 0
234218
}
235219
translate 0 1.15
236220
rotate 0 0 0.5

Examples/Train.shape

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,18 @@ union {
6262
}
6363
}
6464
color red
65-
extrude {
66-
path {
67-
point 1.95 0.5
68-
point -0.1 0.5
69-
point -0.1 0.2
70-
point 0 0.2
71-
point 0 0.4
72-
point 1.92 0.4
73-
point 2.05 0.34
74-
point 2.05 0.2
75-
point 2.15 0.2
76-
point 2.15 0.4
77-
point 1.95 0.5
78-
}
65+
extrude path {
66+
point 1.95 0.5
67+
point -0.1 0.5
68+
point -0.1 0.2
69+
point 0 0.2
70+
point 0 0.4
71+
point 1.92 0.4
72+
point 2.05 0.34
73+
point 2.05 0.2
74+
point 2.15 0.2
75+
point 2.15 0.4
76+
point 1.95 0.5
7977
}
8078
}
8179

Help/builders.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,28 @@ In the [paths](paths.md) section we looked at how to define custom shapes using
1010
The most basic shape builder is the `fill` command, which creates a filled polygon from a path. Using the pentagon path we defined earlier, we can use `fill` to create a solid pentagon:
1111

1212
```
13-
fill {
14-
path {
15-
for 0 to 5 {
16-
point 0 1
17-
rotate 2 / 5
18-
}
19-
}
13+
fill path {
14+
for 0 to 5 {
15+
point 0 1
16+
rotate 2 / 5
17+
}
2018
}
2119
```
2220

2321
![Filled Pentagon](images/filled-pentagon.png)
2422

2523
Unlike a path, a filled shape can have a color and texture, but it has zero thickness.
2624

27-
If a path contains multiple overlapping sub-paths, they will be filled using the [even-odd rule](https://en.wikipedia.org/wiki/Even–odd_rule). For example, the [overlapping circles](paths.md#nested-paths) example would be filled like this:
25+
If a path contains multiple overlapping sub-paths, they will be filled using the [even-odd rule](https://en.wikipedia.org/wiki/Even–odd_rule). For example, the [overlapping circles](paths.md#nested-paths) path would be filled like this:
26+
27+
```swift
28+
fill path {
29+
circle
30+
translate 0.5
31+
scale 0.5
32+
circle
33+
}
34+
```
2835

2936
![Even-odd Fill](images/even-odd-fill.png)
3037

@@ -49,20 +56,18 @@ path {
4956

5057
![Pawn outline](images/pawn-profile.png)
5158

52-
When nested inside a `lathe` command, the path creates a solid 3D model:
59+
When passed to the `lathe` command, the path creates a solid 3D model:
5360

5461
```swift
55-
lathe {
56-
path {
57-
curve 0 0.78
58-
curve -0.15 0.7
59-
curve -0.15 0.5
60-
point -0.07 0.45
61-
curve -0.12 0.2
62-
point -0.25 0.1
63-
point -0.25 0
64-
point 0 0
65-
}
62+
lathe path {
63+
curve 0 0.78
64+
curve -0.15 0.7
65+
curve -0.15 0.5
66+
point -0.07 0.45
67+
curve -0.12 0.2
68+
point -0.25 0.1
69+
point -0.25 0
70+
point 0 0
6671
}
6772
```
6873

Help/text.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ Text
44
The `text` command can be used to generate individual words, lines, or whole paragraphs of text. You use the `text` command as follows:
55

66
```swift
7-
text { "Hello World" }
7+
text "Hello World"
88
```
99

10-
To create multiline text, place each line of text on its own line within the file, surrounded by quotes:
10+
To create multiline text you can use the "\n" line-break sequence:
11+
12+
```swift
13+
text "The quick brown fox\njumps over the lazy dog"
14+
```
15+
16+
Or place each line of text on its own line within the file, surrounded by quotes:
1117

1218
```swift
1319
text {
@@ -28,9 +34,7 @@ To adjust the text font, you can use the `font` command. like `color` and other
2834

2935
```swift
3036
font "Zapfino"
31-
fill {
32-
text { "Hello World" }
33-
}
37+
fill text "Hello World"
3438
```
3539

3640
![Line](images/text-font.png)

ShapeScript/Geometry.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ public final class Geometry {
194194
}
195195
}
196196

197+
// TODO: Provide a better implementation not based on identity
198+
extension Geometry: Hashable {
199+
public func hash(into hasher: inout Hasher) {
200+
hasher.combine(ObjectIdentifier(self).hashValue)
201+
}
202+
203+
public static func == (lhs: Geometry, rhs: Geometry) -> Bool {
204+
lhs === rhs
205+
}
206+
}
207+
197208
public extension Geometry {
198209
var isEmpty: Bool {
199210
type.isEmpty && children.allSatisfy { $0.isEmpty }

0 commit comments

Comments
 (0)