Skip to content

Commit

Permalink
Update for 1.5.10 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Oct 29, 2022
1 parent 38067a9 commit cbbc667
Show file tree
Hide file tree
Showing 63 changed files with 6,927 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [1.5.10](https://github.com/nicklockwood/ShapeScript/releases/tag/1.5.10) (2022-10-29)

- Improved documentation for strings and trigonometry functions
- Fixed empty bounds returned for lathe, fill, extrude and loft shapes
- Fixed runtime warning about postscript font names
- Fixed range bug in error formatting logic
- Fixed inconsistent handling of functions that return tuples
- Fixed inconsistent member lookup handling
- Bumped Euclid to version 0.6.0
- Fixed Linux build warnings

## [1.5.9](https://github.com/nicklockwood/ShapeScript/releases/tag/1.5.9) (2022-10-06)

- Fixed getting started link in Welcome modal
Expand Down
1 change: 0 additions & 1 deletion Euclid/Euclid.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down
4 changes: 2 additions & 2 deletions ShapeScript.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ShapeScript",
"version": "1.5.9",
"version": "1.5.10",
"license": {
"type": "MIT",
"file": "LICENSE.md"
Expand All @@ -10,7 +10,7 @@
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/nicklockwood/ShapeScript.git",
"tag": "1.5.9"
"tag": "1.5.10"
},
"source_files": ["ShapeScript", "LRUCache/Sources", "SVGPath/Sources"],
"requires_arc": true,
Expand Down
12 changes: 6 additions & 6 deletions ShapeScript.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.5.9;
MARKETING_VERSION = 1.5.10;
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
PRODUCT_MODULE_NAME = Viewer;
PRODUCT_NAME = "ShapeScript Viewer";
Expand Down Expand Up @@ -1137,7 +1137,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.5.9;
MARKETING_VERSION = 1.5.10;
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
PRODUCT_MODULE_NAME = Viewer;
PRODUCT_NAME = "ShapeScript Viewer";
Expand Down Expand Up @@ -1167,7 +1167,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.9;
MARKETING_VERSION = 1.5.10;
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
PRODUCT_MODULE_NAME = Viewer;
PRODUCT_NAME = ShapeScript;
Expand Down Expand Up @@ -1199,7 +1199,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.9;
MARKETING_VERSION = 1.5.10;
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptViewer;
PRODUCT_MODULE_NAME = Viewer;
PRODUCT_NAME = ShapeScript;
Expand Down Expand Up @@ -1363,7 +1363,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.9;
MARKETING_VERSION = 1.5.10;
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptLib;
PRODUCT_NAME = ShapeScript;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1394,7 +1394,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.9;
MARKETING_VERSION = 1.5.10;
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.ShapeScriptLib;
PRODUCT_NAME = ShapeScript;
SKIP_INSTALL = YES;
Expand Down
2 changes: 1 addition & 1 deletion ShapeScript/Interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation

// MARK: Public interface

public let version = "1.5.9"
public let version = "1.5.10"

public protocol EvaluationDelegate: AnyObject {
func resolveURL(for path: String) -> URL
Expand Down
84 changes: 84 additions & 0 deletions docs/1.5.10/ios/blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Blocks
---

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).

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.

You can define your own blocks using the `define` command. Here is a block that creates a five-pointed star:

```swift
define star {
path {
for 1 to 5 {
point 0 -0.5
rotate 1 / 5
point 0 -1
rotate 1 / 5
}
point 0 -0.5
}
}
```

You can call it by simply referencing its name, like this:

```swift
star
```

![Star](../../images/star.png)

**Note:** there is a subtle distinction between the code above and the code below:

```swift
define star path {
for 1 to 5 {
point 0 -0.5
rotate 1 / 5
point 0 -1
rotate 1 / 5
}
point 0 -0.5
}
```

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*.

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.

## Options

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.

The code below extends the `star` definition with options for the radius and number of points:

```swift
define star {
option radius 1
option points 5
path {
for 1 to points {
point 0 -0.5
rotate 1 / points
point 0 -radius
rotate 1 / points
}
point 0 -0.5
}
}
```

Now we can use those options to create a star with 6 points if we choose:

```swift
star {
points 6
radius 2
}
```

![Star](../../images/six-pointed-star.png)

---
[Index](index.md) | Next: [Scope](scope.md)
115 changes: 115 additions & 0 deletions docs/1.5.10/ios/bounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Bounds
---

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.

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):

```swift
define star path {
for 1 to 5 {
point 0 -0.5
rotate 1 / 5
point 0 -1
rotate 1 / 5
}
point 0 -0.5
}

// draw star
extrude {
color red
star
}

// draw cube
cube {
color green 0.5
}
```

![Star with unit cube](../../images/star-with-unit-cube.png)

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.

## Mesh Bounds

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 needs to place a box around the star:

```swift
define star {
...
}

// define star shape
define shape extrude {
color red
star
}

// draw star
shape

// draw box around star
cube {
color green 0.5
position shape.bounds.center
size shape.bounds.size
}
```

![Star with fitted cube](../../images/star-with-fitted-cube.png)

## Path Bounds

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:

```swift
define star {
...
}

// draw star
star

// draw rectangle around star
square {
position shape.bounds.center
size shape.bounds.size
}
```

![Star with fitted rectangle](../../images/star-with-fitted-rect.png)

## Bounds Members

The `bounds` member property has the following sub-properties that you can use:

* `min` - The position of the corner of the box with the smallest X, Y and Z values relative to the origin.
* `max` - The position of the corner of the box with the largest X, Y and Z values relative to the origin.
* `center` - The position of the center of the box relative to the origin.
* `size` - The size (width, height and depth) of the box in world units.
* `width` - The width of the box along the X axis (equivalent to `size.width`)
* `height` - The height of the box along the Y axis (equivalent to `size.height`)
* `depth` - The depth of the box along the Z axis (equivalent to `size.depth`)

So, for example, to get the height of a shape, you could use:

```swift
print someShape.bounds.size.height
```

or just:

```swift
print someShape.bounds.height
```

And to get the X coordinate of its rightmost edge you could use:

```swift
print someShape.bounds.max.x
```

---
[Index](index.md) | Next: [Groups](groups.md)
Loading

0 comments on commit cbbc667

Please sign in to comment.