Skip to content

Commit a784e45

Browse files
committed
Update for 1.6.0 release
1 parent 6d137b2 commit a784e45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+7730
-9
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Change Log
22

3+
## [1.6.0](https://github.com/nicklockwood/ShapeScript/releases/tag/1.6.0) (2022-12-27)
4+
5+
- Added hull command for creating convex hulls from points, paths or other meshes
6+
- Added mesh command for manually creating meshes from individual polygons
7+
- Added axisAligned property for controlling extrusion along paths
8+
- Added support for importing plain text files as a string and JSON files as a tuple
9+
- Added modulo operator for calculating remainder of division
10+
- Significantly overhauled type system to support lists, unions and objects
11+
- Improved static analysis, allowing type errors to be caught earlier
12+
- Improved handling of background property scope
13+
- The min and max functions are now variadic (accept any number of arguments)
14+
- Added split(), join() and trim() functions for working with strings
15+
- Added automatic conversion of strings to numbers or boolean values where applicable
16+
- Added string.lines, .words and .characters members
17+
- Added tuple.count, .last, .allButFirst and .allButLast members
18+
- Fixed member lookup on numeric literals
19+
- Fixed bug where material of imported shapes could not be overridden
20+
- Background and texture can now be cleared by setting them to an empty string
21+
- Logging geometry values to console now produces more useful output
22+
- Added proper logging for bounds and point values
23+
- Added fileTimedOut and circularImport errors
24+
- Refactored and improved error handling
25+
- Renamed ImportError to ProgramError
26+
- Raised minimum Euclid version to 0.6.6
27+
- Added Spirals example
28+
329
## [1.5.14](https://github.com/nicklockwood/ShapeScript/releases/tag/1.5.14) (2022-12-18)
430

531
- Added support for C-style block comments using /* ... */ syntax

ShapeScript.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ShapeScript",
3-
"version": "1.5.14",
3+
"version": "1.6.0",
44
"license": {
55
"type": "MIT",
66
"file": "LICENSE.md"
@@ -10,7 +10,7 @@
1010
"authors": "Nick Lockwood",
1111
"source": {
1212
"git": "https://github.com/nicklockwood/ShapeScript.git",
13-
"tag": "1.5.14"
13+
"tag": "1.6.0"
1414
},
1515
"source_files": ["ShapeScript", "LRUCache/Sources", "SVGPath/Sources"],
1616
"requires_arc": true,

ShapeScript.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@
11311131
"$(inherited)",
11321132
"@executable_path/../Frameworks",
11331133
);
1134-
MARKETING_VERSION = 1.5.14;
1134+
MARKETING_VERSION = 1.6.0;
11351135
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
11361136
PRODUCT_MODULE_NAME = Viewer;
11371137
PRODUCT_NAME = "ShapeScript Viewer";
@@ -1159,7 +1159,7 @@
11591159
"$(inherited)",
11601160
"@executable_path/../Frameworks",
11611161
);
1162-
MARKETING_VERSION = 1.5.14;
1162+
MARKETING_VERSION = 1.6.0;
11631163
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
11641164
PRODUCT_MODULE_NAME = Viewer;
11651165
PRODUCT_NAME = "ShapeScript Viewer";
@@ -1189,7 +1189,7 @@
11891189
"$(inherited)",
11901190
"@executable_path/Frameworks",
11911191
);
1192-
MARKETING_VERSION = 1.5.14;
1192+
MARKETING_VERSION = 1.6.0;
11931193
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
11941194
PRODUCT_MODULE_NAME = Viewer;
11951195
PRODUCT_NAME = ShapeScript;
@@ -1221,7 +1221,7 @@
12211221
"$(inherited)",
12221222
"@executable_path/Frameworks",
12231223
);
1224-
MARKETING_VERSION = 1.5.14;
1224+
MARKETING_VERSION = 1.6.0;
12251225
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
12261226
PRODUCT_MODULE_NAME = Viewer;
12271227
PRODUCT_NAME = ShapeScript;
@@ -1384,7 +1384,7 @@
13841384
"@executable_path/../Frameworks",
13851385
"@loader_path/Frameworks",
13861386
);
1387-
MARKETING_VERSION = 1.5.14;
1387+
MARKETING_VERSION = 1.6.0;
13881388
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptLib;
13891389
PRODUCT_NAME = ShapeScript;
13901390
SKIP_INSTALL = YES;
@@ -1415,7 +1415,7 @@
14151415
"@executable_path/../Frameworks",
14161416
"@loader_path/Frameworks",
14171417
);
1418-
MARKETING_VERSION = 1.5.14;
1418+
MARKETING_VERSION = 1.6.0;
14191419
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptLib;
14201420
PRODUCT_NAME = ShapeScript;
14211421
SKIP_INSTALL = YES;

ShapeScript/Interpreter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111

1212
// MARK: Public interface
1313

14-
public let version = "1.5.14"
14+
public let version = "1.6.0"
1515

1616
public protocol EvaluationDelegate: AnyObject {
1717
func resolveURL(for path: String) -> URL

docs/1.6.0/ios/blocks.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Blocks
2+
---
3+
4+
A block is a nested list of instructions, contained inside `{ ... }` braces. Some commands, such as [builders](builders.md) or [CSG operations](csg.md), accept a block parameter instead of a simple value like a number or [vector](literals.md#vectors-and-tuples).
5+
6+
Instructions inside a block are executed within the [scope](scope.md) of the command that invoked them. Typically that means that any transforms or material changes made inside the block will only apply to geometry created inside the same block. This also applies to any symbols that you define inside the block.
7+
8+
You can define your own blocks using the `define` command. Here is a block that creates a five-pointed star:
9+
10+
```swift
11+
define star {
12+
path {
13+
for 1 to 5 {
14+
point 0 -0.5
15+
rotate 1 / 5
16+
point 0 -1
17+
rotate 1 / 5
18+
}
19+
point 0 -0.5
20+
}
21+
}
22+
```
23+
24+
You can call it by simply referencing its name, like this:
25+
26+
```swift
27+
star
28+
```
29+
30+
![Star](../../images/star.png)
31+
32+
**Note:** there is a subtle distinction between the code above and the code below:
33+
34+
```swift
35+
define star path {
36+
for 1 to 5 {
37+
point 0 -0.5
38+
rotate 1 / 5
39+
point 0 -1
40+
rotate 1 / 5
41+
}
42+
point 0 -0.5
43+
}
44+
```
45+
46+
In the original code, we defined a new block symbol that creates a star-shaped path. In the code above we've defined a symbol whose value is a star-shaped path. The former code is evaluated at the point when it is *called*, whereas the latter code is evaluated at the point when it is *defined*.
47+
48+
The end-result is the same in this case, so it may seem like the distinction doesn't matter, but the advantage of the former approach is that we can add *options* to vary the behavior of the code when it is called.
49+
50+
## Options
51+
52+
To add an option to a block, you use the `option` command. This works in a similar way to the [define](symbols.md) command, but it allows the specified value to be overridden by the caller.
53+
54+
The code below extends the `star` definition with options for the radius and number of points:
55+
56+
```swift
57+
define star {
58+
option radius 1
59+
option points 5
60+
path {
61+
for 1 to points {
62+
point 0 -0.5
63+
rotate 1 / points
64+
point 0 -radius
65+
rotate 1 / points
66+
}
67+
point 0 -0.5
68+
}
69+
}
70+
```
71+
72+
Now we can use those options to create a star with 6 points if we choose:
73+
74+
```swift
75+
star {
76+
points 6
77+
radius 2
78+
}
79+
```
80+
81+
![Star](../../images/six-pointed-star.png)
82+
83+
---
84+
[Index](index.md) | Next: [Scope](scope.md)

docs/1.6.0/ios/bounds.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
Bounds
2+
---
3+
4+
ShapeScript's [size](transforms.md#size) ands [scale](transforms.md#relative-transforms) commands let you control the relative size of a shape, but sometimes it's useful to know the exact dimensions.
5+
6+
A cube of size 1 has an easily-predicted size of one world unit square, but what about a more complex shape, such as a 5-pointed star (see the [procedural paths](paths.md#procedural-paths) and [blocks](blocks.md) sections for details):
7+
8+
```swift
9+
define star path {
10+
for 1 to 5 {
11+
point 0 -0.5
12+
rotate 1 / 5
13+
point 0 -1
14+
rotate 1 / 5
15+
}
16+
point 0 -0.5
17+
}
18+
19+
// draw star
20+
extrude {
21+
color red
22+
star
23+
}
24+
25+
// draw cube
26+
cube {
27+
color green 0.5
28+
}
29+
```
30+
31+
![Star with unit cube](../../images/star-with-unit-cube.png)
32+
33+
We can see that the star is larger than the unit cube, but other than trial-and-error or complex math, how can we get the exact size? This is where the `bounds` [member property](expressions.md#members) comes in.
34+
35+
## Mesh Bounds
36+
37+
Paths and meshes both expose a `bounds` property that represents a bounding box around the shape. From this you can get the exact size and position needed to place a box around the star:
38+
39+
```swift
40+
define star {
41+
...
42+
}
43+
44+
// define star shape
45+
define shape extrude {
46+
color red
47+
star
48+
}
49+
50+
// draw star
51+
shape
52+
53+
// draw box around star
54+
cube {
55+
color green 0.5
56+
position shape.bounds.center
57+
size shape.bounds.size
58+
}
59+
```
60+
61+
![Star with fitted cube](../../images/star-with-fitted-cube.png)
62+
63+
## Path Bounds
64+
65+
In the example above we computed the bounds of a solid `mesh` (an extruded star-shaped `path`) but you can also get the bounds of a `path` directly. The following code draws the star path inside its bounding rectangle:
66+
67+
```swift
68+
define star {
69+
...
70+
}
71+
72+
// draw star
73+
star
74+
75+
// draw rectangle around star
76+
square {
77+
position shape.bounds.center
78+
size shape.bounds.size
79+
}
80+
```
81+
82+
![Star with fitted rectangle](../../images/star-with-fitted-rect.png)
83+
84+
## Bounds Members
85+
86+
The `bounds` member property has the following sub-properties that you can use:
87+
88+
* `min` - The position of the corner of the box with the smallest X, Y and Z values relative to the origin.
89+
* `max` - The position of the corner of the box with the largest X, Y and Z values relative to the origin.
90+
* `center` - The position of the center of the box relative to the origin.
91+
* `size` - The size (width, height and depth) of the box in world units.
92+
* `width` - The width of the box along the X axis (equivalent to `size.width`)
93+
* `height` - The height of the box along the Y axis (equivalent to `size.height`)
94+
* `depth` - The depth of the box along the Z axis (equivalent to `size.depth`)
95+
96+
So, for example, to get the height of a shape, you could use:
97+
98+
```swift
99+
print someShape.bounds.size.height
100+
```
101+
102+
or just:
103+
104+
```swift
105+
print someShape.bounds.height
106+
```
107+
108+
And to get the X coordinate of its rightmost edge you could use:
109+
110+
```swift
111+
print someShape.bounds.max.x
112+
```
113+
114+
---
115+
[Index](index.md) | Next: [Meshes](meshes.md)

0 commit comments

Comments
 (0)