Skip to content

Commit

Permalink
Updated for 0.1.7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Mar 12, 2019
1 parent 29ccb0b commit 399ead6
Show file tree
Hide file tree
Showing 15 changed files with 511 additions and 489 deletions.
1 change: 1 addition & 0 deletions .swiftformat
@@ -1,3 +1,4 @@
--hexgrouping ignore
--decimalgrouping ignore
--enable isEmpty
--ifdef no-indent
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,12 @@
## [0.1.7](https://github.com/nicklockwood/Euclid/releases/tag/0.1.7) (2019-03-11)

- Added support for creating Euclid Paths from a Core Graphics CGPath
- Added support for rendering 2D or extruded 3D text using Core Text
- Fixed some bugs in triangulation that occasionally caused concave polygons not to render
- Fixed a bug where material was not set correctly for extrusions with a depth of zero
- Added XOR CSG function (useful for rendering text)
- Added ellipse constructor for Path

## [0.1.6](https://github.com/nicklockwood/Euclid/releases/tag/0.1.6) (2019-02-27)

- Improved CSG operations on coplanar polygons
Expand Down
4 changes: 2 additions & 2 deletions Euclid.podspec.json
@@ -1,6 +1,6 @@
{
"name": "Euclid",
"version": "0.1.6",
"version": "0.1.7",
"license": {
"type": "MIT",
"file": "LICENSE.md"
Expand All @@ -10,7 +10,7 @@
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/nicklockwood/Euclid.git",
"tag": "0.1.6"
"tag": "0.1.7"
},
"source_files": "Sources",
"requires_arc": true,
Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -137,6 +137,7 @@ All `Mesh`es are made of flat polygons, and since true curves cannot be represen

In addition to the 3D `Mesh` primitives listed, there are also 2D `Path` primitives. These are implemented as static constructor methods on the `Path` type instead of `Mesh`:

- `ellipse` - A closed, elliptical `Path`.
- `circle` - A closed, circular `Path`.
- `rectangle` - A closed, rectangular `Path`.
- `square` - Same as `rectangle`, but with equal width and height.
Expand Down Expand Up @@ -166,17 +167,28 @@ The `curve` method uses second-order (quadratic) Bezier curves, where each curve

This approach to curve generation is based on the popular [TrueType (TTF) font system](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM01/Chap1.html), and provides a good balance between simplicity and flexibility.

For more complex curves, on macOS and iOS you can create Euclid `Path`s from a Core Graphics `CGPath` by using the `CGPath.paths()` extension method. `CGPath` supports cubic bezier curves as well as quadratic, and has handy constructors for rounded rectangles and other shapes.

## CSG

CSG (Constructive Solid Geometry) is another powerful tool for creating intricate geometry. CSG allows you to perform boolean operations (logical AND, OR, etc) on solid shapes. The following CSG operations are defined as methods on the `Mesh` type:

- `subtract` - Subtracts the volume of one `Mesh` from another.
- `xor` - Produces a shape representing the non-overlapping parts of the input `Mesh`es (this is useful for rendering text glyphs).
- `union` - Combines two intersecting `Mesh`es, removing internal faces and leaving only the outer shell around both shapes (logical OR).
- `intersection` - Returns a single `Mesh` representing the common volume of two intersecting `Mesh`es (logical AND).
- `stencil` - This effectively "paints" part of one `Mesh` with the material from another.

All CSG operations require `Mesh`es that are "watertight", i.e. that have no holes in their surface. Using them on `Mesh`es that are not sealed may result in unexpected results.

## Text

On macOS and iOS you can make use of Euclid's Core Text integration to create 2D or 3D extruded text.

The `Path.text()` method produces an array of 2D `Path`s representing the contours of each glyph in an `AttributedString`, which can then be used with the `fill` or `extrude` builder methods and combined using the `xor` CSG function to create solid text.

Alternatively, the `Mesh(text:)` constructor directly produces an extruded 3D text model from a `String` or `AttributedString`.


# Rendering

Expand Down
18 changes: 9 additions & 9 deletions Sources/CoreGraphics.swift
Expand Up @@ -25,15 +25,15 @@ public extension CGPoint {
public extension CGPath {
private func enumerateElements(_ block: @convention(block) (CGPathElement) -> Void) {
#if os(iOS)
if #available(iOS 11.0, *) {
applyWithBlock { block($0.pointee) }
return
}
if #available(iOS 11.0, *) {
applyWithBlock { block($0.pointee) }
return
}
#elseif os(OSX)
if #available(OSX 10.13, *) {
applyWithBlock { block($0.pointee) }
return
}
if #available(OSX 10.13, *) {
applyWithBlock { block($0.pointee) }
return
}
#endif

// Fallback for earlier OSes
Expand Down Expand Up @@ -150,7 +150,7 @@ public extension CGPath {
}
points.append(.point(Vector(p2)))
case .addCurveToPoint:
let detail = max(detail * 2, 3)
let detail = max(detail * 2, 3)
var t = 0.0
let step = 1 / Double(detail)
let p0 = points.last ?? .point(startingPoint)
Expand Down

0 comments on commit 399ead6

Please sign in to comment.