Skip to content

Commit

Permalink
Add package description to README
Browse files Browse the repository at this point in the history
  • Loading branch information
mkj-is committed Sep 30, 2019
1 parent d3d6eea commit 80604dd
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
Binary file added Documentation/SwiftLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Documentation/SwiftLogo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Path {
Move(to: CGPoint(x: 87.15, y: 15))
Curve(to: CGPoint(x: 99.68, y: 68.36), control1: CGPoint(x: 99, y: 31.31), control2: CGPoint(x: 104.42, y: 51.03))
Curve(to: CGPoint(x: 98.13, y: 73.09), control1: CGPoint(x: 99.24, y: 69.99), control2: CGPoint(x: 98.72, y: 71.57))
Curve(to: CGPoint(x: 95.95, y: 71.76), control1: CGPoint(x: 97.56, y: 72.7), control2: CGPoint(x: 96.86, y: 72.28))
Curve(to: CGPoint(x: 39.07, y: 24.85), control1: CGPoint(x: 95.95, y: 71.76), control2: CGPoint(x: 68.53, y: 54.77))
Curve(to: CGPoint(x: 73.61, y: 68.36), control1: CGPoint(x: 38.39, y: 24.18), control2: CGPoint(x: 54.99, y: 48.65))
Curve(to: CGPoint(x: 24.51, y: 30.97), control1: CGPoint(x: 64.8, y: 63.26), control2: CGPoint(x: 40.09, y: 45.25))
Curve(to: CGPoint(x: 31.28, y: 40.15), control1: CGPoint(x: 26.54, y: 34.03), control2: CGPoint(x: 28.58, y: 37.43))
Curve(to: CGPoint(x: 81.73, y: 92.83), control1: CGPoint(x: 44.15, y: 56.81), control2: CGPoint(x: 61.42, y: 77.2))
Curve(to: CGPoint(x: 81.76, y: 92.86), control1: CGPoint(x: 81.74, y: 92.84), control2: CGPoint(x: 81.75, y: 92.85))
Curve(to: CGPoint(x: 26.88, y: 92.83), control1: CGPoint(x: 67.47, y: 101.73), control2: CGPoint(x: 47.18, y: 102.38))
Curve(to: CGPoint(x: 13, y: 84.34), control1: CGPoint(x: 21.8, y: 90.45), control2: CGPoint(x: 17.06, y: 87.73))
Curve(to: CGPoint(x: 50.58, y: 116.62), control1: CGPoint(x: 21.46, y: 97.93), control2: CGPoint(x: 34.67, y: 109.83))
Curve(to: CGPoint(x: 103.98, y: 115.99), control1: CGPoint(x: 70.24, y: 125.08), control2: CGPoint(x: 89.77, y: 124.23))
Curve(to: CGPoint(x: 131.84, y: 123.09), control1: CGPoint(x: 110.9, y: 113.07), control2: CGPoint(x: 124.5, y: 108.66))
Curve(to: CGPoint(x: 133.62, y: 117.78), control1: CGPoint(x: 132.55, y: 124.51), control2: CGPoint(x: 133.61, y: 122.19))
Curve(to: CGPoint(x: 123.72, y: 91.48), control1: CGPoint(x: 133.6, y: 111.47), control2: CGPoint(x: 131.55, y: 101.3))
Curve(to: CGPoint(x: 123.48, y: 91.18), control1: CGPoint(x: 123.64, y: 91.38), control2: CGPoint(x: 123.56, y: 91.28))
Curve(to: CGPoint(x: 124.06, y: 89.1), control1: CGPoint(x: 123.69, y: 90.5), control2: CGPoint(x: 123.88, y: 89.8))
Curve(to: CGPoint(x: 87.15, y: 15), control1: CGPoint(x: 130.83, y: 62.92), control2: CGPoint(x: 114.57, y: 31.65))
}
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
# PathBuilder

A description of this package.
_Path builder_ is a complete function builder for lifting paths into the declarative SwiftUI world. This function can be used for elegant and short definition of paths. Missing documentation gaps in SwiftUI are filled in using the old but good CGMutablePath knowledge.

## Motivation

Just wanted to learn to implement function builders. And during playing with animated paths in SwiftUI found a perfect place to experiment.

## Requirements

- Xcode 11 or above
- Swift 5.1 or above
- iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0 or above

## Installation

Using Swift Package Manager in Xcode.

## Usage

### Examples

With _PathBuilder_ you can write this to draw a triangle:

```swift
Path {
Move(to: CGPoint(x: 50, y: 50))
Line(to: CGPoint(x: 100, y: 100))
Line(to: CGPoint(x: 0, y: 100))
Close()
}
```

Instead of longer version:

```swift
Path { p in
p.move(to: CGPoint(x: 50, y: 50))
p.addLine(to: CGPoint(x: 100, y: 100))
p.addLine(to: CGPoint(x: 0, y: 100))
p.closeSubpath()
}
```

Drawing a Swift logo can be implemented like [this](Documentation/SwiftLogo.swift).

![Swift logo path drawing using PathBuilder](Documentation/SwiftLogo.png)

### Path components

There are many basic path components present. You can create a new one by conforming to the `PathComponent` protocol.

#### Elementary components

- *Arc* – Adds an arc of a circle to the path, specified with a radius and angles.
- *Close* – Closes and completes a subpath in a path.
- *Curve* – Adds a cubic Bézier curve to the path, with the specified end point and control points.
- *Ellipse* – Adds an ellipse that fits inside the specified rectangle.
- *Line* – Appends a straight line segment from the current point to the specified point.
- *Lines* – Adds a sequence of connected straight-line segments to the path.
- *Move* – Begins a new subpath at the specified point.
- *QuadCurve* – Adds a quadratic Bézier curve to the path, with the specified end point and control point.
- *Rect* – Adds a set of rectangular subpaths to the path.
- *RelativeArc* – Adds an arc of a circle to the path, specified with a radius and a difference in angle.
- *RoundedRect* – Adds a subpath to the path, in the shape of a rectangle with rounded corners.
- *TangentArc* – Adds an arc of a circle to the path, specified with a radius and two tangent lines.

#### Grouping components

- *Subpath* – Groups and appends another subpath object to the path.
- *Transform* – Groups, transforms and appends another transformed subpath object to the path.

## Contributing

All contributions are welcome.

Project was created by [Matěj Kašpar Jirásek](https://github.com/mkj-is).

Project is licensed under [MIT license](LICENSE.txt).
2 changes: 1 addition & 1 deletion Sources/PathBuilder/Path components/Transform.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

/// Appends another transformed subpath object to the path.
/// Groups and appends another subpath object to the path.
public struct Transform: PathComponent {
private let transform: CGAffineTransform
private let path: Path
Expand Down

0 comments on commit 80604dd

Please sign in to comment.