Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
macos-build:
SwiftActions:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]

runs-on: macos-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Build (macOS)
run: swift build -v
- name: Run tests
run: swift test -v

ubuntu-build:
- name: Checkout Source
uses: actions/checkout@v4

runs-on: ubuntu-latest
- name: Lint
if: ${{ runner.os == 'macOS' }}
shell: bash
run: swiftformat --lint . --reporter github-actions-log

steps:
- uses: actions/checkout@v2
- name: Build (Ubuntu)
run: swift build -v
- name: Run tests
run: swift test -v
- name: Swift Build
uses: SwiftActions/SwiftBuild@main

- name: Swift Test
uses: SwiftActions/SwiftTest@main

4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [GraphPoint]
15 changes: 15 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Compiler
--languagemode 5
--swiftversion 5.9

# Options
--exclude derivedData
--ifdef no-indent
--indent 4

# Rules
--disable blankLinesAtStartOfScope
--disable hoistPatternLet
--disable redundantType
--disable unusedArguments
--disable wrapArguments
33 changes: 20 additions & 13 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// swift-tools-version:5.0
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "GraphPoint",
platforms: [
.macOS(.v10_13),
.iOS(.v11),
.tvOS(.v11),
.watchOS(.v4),
.macOS(.v13),
.macCatalyst(.v16),
.iOS(.v16),
.tvOS(.v16),
.watchOS(.v9),
],
products: [
.library(
name: "GraphPoint",
targets: ["GraphPoint"]),
],
dependencies: [
.package(url: "https://github.com/richardpiazza/Swift2D", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/richardpiazza/Swift2D", .upToNextMajor(from: "2.2.0")),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.55.0"),
],
targets: [
.target(
Expand Down
65 changes: 29 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,16 @@
<img src="Resources/GraphPoint.png" width="1000" max-width="90%" alt="GraphPoint" />
</p>

<p align="center">
<img src="https://github.com/richardpiazza/GraphPoint/workflows/Swift/badge.svg?branch=main" />
<img src="https://img.shields.io/badge/Swift-5.0-orange.svg" />
<a href="https://twitter.com/richardpiazza">
<img src="https://img.shields.io/badge/twitter-@richardpiazza-blue.svg?style=flat" alt="Twitter: @richardpiazza" />
</a>
</p>

<p align="center">
A Swift implementation of the <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian Coordinate System</a>.
</p>

## Installation

**GraphPoint** is distributed using the [Swift Package Manager](https://swift.org/package-manager). To install it into a project, add it as a
dependency within your `Package.swift` manifest:

```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/richardpiazza/GraphPoint.git", from: "4.0.0")
],
...
)
```

Then import **GraphPoint** wherever you'd like to use it:
A Swift implementation of the <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">Cartesian Coordinate System</a>.

```swift
import GraphPoint
```
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FGraphPoint%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/richardpiazza/GraphPoint)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FGraphPoint%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/richardpiazza/GraphPoint)

## Dependencies

**GraphPoint** relies heavily on the **[Swift2D](https://github.com/richardpiazza/Swift2D)** library, which reimplements `Rect`, `Size`, and
`Point` in a cross-platform, non-Foundation reliant way.

## Deprecations

The `CoreGraphics` aliases have been deprecated and replaced by their _Cartesian_ counterparts. These type-aliases and
**GraphPointUI** will be removed in a future version.

## Usage

There are several key aspects to understand when using **GraphPoint**.
Expand Down Expand Up @@ -73,3 +40,29 @@ cartesianFrame == Rect(origin: Point(x: -10, y: 10), size: Size(width: 10, heigh
### `CartesianPoint`

A point within a `CartesianPlane`. The x & y coordinates of a `CartesianPoint` represent the offset from the planes 'origin' (0, 0).

## Deprecations

The `CoreGraphics` aliases have been deprecated and replaced by their _Cartesian_ counterparts. These type-aliases and
**GraphPointUI** will be removed in a future version.

## Installation

**GraphPoint** is distributed using the [Swift Package Manager](https://swift.org/package-manager). To install it into a project, add it as a
dependency within your `Package.swift` manifest:

```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/richardpiazza/GraphPoint.git", from: "4.0.0")
],
...
)
```

Then import **GraphPoint** wherever you'd like to use it:

```swift
import GraphPoint
```
43 changes: 26 additions & 17 deletions Sources/GraphPoint/Arc.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/// Arc of a circle (a continuous length around the circumference)
public struct Arc {
public struct Arc: Hashable, Codable, Sendable {
public var radius: Radius
public var startingDegree: Degree
public var endingDegree: Degree
public var clockwise: Bool

public init(radius: Radius = 0.0, startingDegree: Degree = 0.0, endingDegree: Degree = 0.0, clockwise: Bool = true) {

public init(
radius: Radius = 0.0,
startingDegree: Degree = 0.0,
endingDegree: Degree = 0.0,
clockwise: Bool = true
) {
self.radius = radius
self.startingDegree = startingDegree
self.endingDegree = endingDegree
Expand All @@ -19,37 +24,41 @@ public extension Arc {
guard let point = try? CartesianPoint.make(for: radius, degree: startingDegree) else {
return .zero
}

return point
}

/// The `CartesianPoint` that represents the ending point
var endingPoint: CartesianPoint {
guard let point = try? CartesianPoint.make(for: radius, degree: endingDegree) else {
return .zero
}

return point
}

/// Calculates the point of the right angle that joins the start and end points.
var pivotPoint: CartesianPoint {
var pivot = CartesianPoint(x: 0, y: 0)

if startingDegree < 90 {
pivot.x = endingPoint.x
pivot.y = startingPoint.y
pivot = pivot
.with(x: endingPoint.x)
.with(y: startingPoint.y)
} else if startingDegree < 180 {
pivot.x = startingPoint.x
pivot.y = endingPoint.y
pivot = pivot
.with(x: startingPoint.x)
.with(y: endingPoint.y)
} else if startingDegree < 270 {
pivot.x = endingPoint.x
pivot.y = startingPoint.y
pivot = pivot
.with(x: endingPoint.x)
.with(y: startingPoint.y)
} else {
pivot.x = startingPoint.x
pivot.y = endingPoint.y
pivot = pivot
.with(x: startingPoint.x)
.with(y: endingPoint.y)
}

return pivot
}
}
Loading