Skip to content

Commit

Permalink
Merge pull request #5 from koher/dev-0.3.0
Browse files Browse the repository at this point in the history
Develop 0.3.0
  • Loading branch information
koher authored Oct 30, 2018
2 parents 0b7b1c5 + a8a7c59 commit 5b6df07
Show file tree
Hide file tree
Showing 20 changed files with 889 additions and 377 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ matrix:
include:
- os: osx
language: objective-c
osx_image: xcode9.2
osx_image: xcode10
script:
- set -o pipefail
- xcodebuild test -scheme CGPointVector-macOS -configuration Debug | xcpretty -c
- xcodebuild test -scheme CGPointVector-iOS -configuration Debug -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone X" | xcpretty -c
- xcodebuild test -scheme CGPointVector-iOS -configuration Debug -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone XS" | xcpretty -c
- xcodebuild test -scheme CGPointVector-tvOS -configuration Debug -sdk appletvsimulator -destination "platform=tvOS Simulator,name=Apple TV 4K" | xcpretty -c
- xcodebuild build -scheme CGPointVector-watchOS -configuration Debug -sdk watchsimulator -destination "platform=watchOS Simulator,name=Apple Watch Series 3 - 38mm" | xcpretty -c
- xcodebuild build -scheme CGPointVector-watchOS -configuration Debug -sdk watchsimulator -destination "platform=watchOS Simulator,name=Apple Watch Series 4 - 44mm" | xcpretty -c
- os: osx
language: generic
osx_image: xcode9.2
osx_image: xcode10
script:
- swift --version
- swift build
Expand Down
81 changes: 56 additions & 25 deletions CGPointVector.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let sum = a + b // (5.0, -9.0)
let length = a.length // 5.0
let distance = a.distance(from: b) // 1.4142135623731
let unitVector = a.unit // (0.6, -0.8)
let dotProduct = a * b // 26.0
let dotProduct = a.dot(b) // 26.0
```

## Installation
Expand All @@ -35,14 +35,14 @@ let dotProduct = a * b // 26.0
```swift
.package(
url: "https://github.com/koher/CGPointVector.git",
from: "0.2.0"
from: "0.3.0"
)
```

### Carthage

```
github "koher/CGPointVector" ~> 0.2.0
github "koher/CGPointVector" ~> 0.3.0
```

## License
Expand Down
34 changes: 14 additions & 20 deletions Sources/CGPointVector/CGAffineTransform.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import CoreGraphics

extension CGAffineTransform {
public func nearlyEqual(to transform: CGAffineTransform, epsilon: CGFloat) -> Bool {
return fabs(a - transform.a) < epsilon && fabs(b - transform.b) < epsilon && fabs(c - transform.c) < epsilon && fabs(d - transform.d) < epsilon && fabs(tx - transform.tx) < epsilon && fabs(ty - transform.ty) < epsilon
}

public var inverse: CGAffineTransform {
return self.inverted()
public func isNearlyEqual(to transform: CGAffineTransform, epsilon: CGFloat) -> Bool {
return abs(a - transform.a) < epsilon && abs(b - transform.b) < epsilon && abs(c - transform.c) < epsilon && abs(d - transform.d) < epsilon && abs(tx - transform.tx) < epsilon && abs(ty - transform.ty) < epsilon
}
}

Expand All @@ -16,18 +12,16 @@ extension CGAffineTransform: CustomStringConvertible {
}
}

public func * (left: CGAffineTransform, right: CGAffineTransform) -> CGAffineTransform {
return left.concatenating(right)
}

public func * (left: CGAffineTransform, right: CGPoint) -> CGPoint {
return right.applying(left)
}

public func * (left: CGPoint, right: CGAffineTransform) -> CGPoint {
return left.applying(right)
}

public func *= (left: inout CGAffineTransform, right: CGAffineTransform) {
left = left * right
extension CGAffineTransform {
public static func * (lhs: CGAffineTransform, rhs: CGAffineTransform) -> CGAffineTransform {
return lhs.concatenating(rhs)
}

public static func *= (lhs: inout CGAffineTransform, rhs: CGAffineTransform) {
lhs = lhs * rhs
}

public static func * (lhs: CGAffineTransform, rhs: CGPoint) -> CGPoint {
return rhs.applying(lhs)
}
}
146 changes: 97 additions & 49 deletions Sources/CGPointVector/CGPoint.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import CoreGraphics

extension CGPoint {
public func nearlyEqual(to point: CGPoint, epsilon: CGFloat) -> Bool {
public func isNearlyEqual(to point: CGPoint, epsilon: CGFloat) -> Bool {
let difference = self - point
return fabs(difference.x) < epsilon && fabs(difference.y) < epsilon
return abs(difference.x) < epsilon && abs(difference.y) < epsilon
}

public var length: CGFloat {
Expand Down Expand Up @@ -31,11 +31,19 @@ extension CGPoint {
}

public func angle(from point: CGPoint) -> CGFloat {
return acos(cos(angleFrom: point))
return acos(cos(from: point))
}

public func cos(angleFrom point: CGPoint) -> CGFloat {
return fmin(fmax(self * point / sqrt(self.squareLength * point.squareLength), -1.0), 1.0)
public func cos(from point: CGPoint) -> CGFloat {
let squareLength1 = self.squareLength
guard squareLength1 > 0.0 else { return 1.0 }
let squareLength2 = point.squareLength
guard squareLength2 > 0.0 else { return 1.0 }
return Swift.min(Swift.max(self.dot(point) / sqrt(squareLength1 * squareLength2), -1.0), 1.0)
}

public func dot(_ other: CGPoint) -> CGFloat {
return self.x * other.x + self.y * other.y
}
}

Expand All @@ -45,50 +53,90 @@ extension CGPoint: CustomStringConvertible {
}
}

public prefix func + (value: CGPoint) -> CGPoint {
return value
}

public prefix func - (value: CGPoint) -> CGPoint {
return CGPoint(x: -value.x, y: -value.y)
}

public func + (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x + right.x, y: left.y + right.y)
}

public func - (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x - right.x, y: left.y - right.y)
}

public func * (left: CGPoint, right: CGPoint) -> CGFloat {
return left.x * right.x + left.y * right.y
}

public func * (left: CGPoint, right: CGFloat) -> CGPoint {
return CGPoint(x: left.x * right, y: left.y * right)
}

public func * (left: CGFloat, right: CGPoint) -> CGPoint {
return CGPoint(x: right.x * left, y: right.y * left)
}

public func / (left: CGPoint, right: CGFloat) -> CGPoint {
return CGPoint(x: left.x / right, y: left.y / right)
}

public func += (left: inout CGPoint, right: CGPoint) {
left = left + right
}

public func -= (left: inout CGPoint, right: CGPoint) {
left = left - right
}

public func *= (left: inout CGPoint, right: CGFloat) {
left = left * right
extension CGPoint {
public static prefix func + (value: CGPoint) -> CGPoint {
return value
}

public static prefix func - (value: CGPoint) -> CGPoint {
return CGPoint(x: -value.x, y: -value.y)
}

public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
}

public static func - (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
}

public static func * (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x * rhs.x, y: lhs.y * rhs.y)
}

public static func * (lhs: CGPoint, rhs: CGFloat) -> CGPoint {
return CGPoint(x: lhs.x * rhs, y: lhs.y * rhs)
}

public static func * (lhs: CGFloat, rhs: CGPoint) -> CGPoint {
return CGPoint(x: rhs.x * lhs, y: rhs.y * lhs)
}

public static func / (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x / rhs.x, y: lhs.y / rhs.y)
}

public static func / (lhs: CGPoint, rhs: CGFloat) -> CGPoint {
return CGPoint(x: lhs.x / rhs, y: lhs.y / rhs)
}

public static func * (lhs: CGPoint, rhs: CGAffineTransform) -> CGPoint {
return lhs.applying(rhs)
}

public static func += (lhs: inout CGPoint, rhs: CGPoint) {
lhs = lhs + rhs
}

public static func -= (lhs: inout CGPoint, rhs: CGPoint) {
lhs = lhs - rhs
}

public static func *= (lhs: inout CGPoint, rhs: CGPoint) {
lhs = lhs * rhs
}

public static func *= (lhs: inout CGPoint, rhs: CGFloat) {
lhs = lhs * rhs
}

public static func /= (lhs: inout CGPoint, rhs: CGPoint) {
lhs = lhs / rhs
}

public static func /= (lhs: inout CGPoint, rhs: CGFloat) {
lhs = lhs / rhs
}

public static func *= (lhs: inout CGPoint, rhs: CGAffineTransform) {
lhs = lhs * rhs
}
}

public func /= (left: inout CGPoint, right: CGFloat) {
left = left / right
extension CGPoint {
public static func + (lhs: CGPoint, rhs: CGSize) -> CGPoint {
return CGPoint(x: lhs.x + rhs.width, y: lhs.y + rhs.height)
}

public static func - (lhs: CGPoint, rhs: CGSize) -> CGPoint {
return CGPoint(x: lhs.x - rhs.width, y: lhs.y - rhs.height)
}

public static func * (lhs: CGPoint, rhs: CGSize) -> CGPoint {
return CGPoint(x: lhs.x * rhs.width, y: lhs.y * rhs.height)
}

public static func / (lhs: CGPoint, rhs: CGSize) -> CGPoint {
return CGPoint(x: lhs.x / rhs.width, y: lhs.y / rhs.height)
}
}
16 changes: 11 additions & 5 deletions Sources/CGPointVector/CGRect.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import CoreGraphics

extension CGRect {
public func nearlyEqual(to rect: CGRect, epsilon: CGFloat) -> Bool {
public func isNearlyEqual(to rect: CGRect, epsilon: CGFloat) -> Bool {
let difference1 = self.origin - rect.origin
let difference2 = (self.origin + self.size) - (rect.origin + rect.size)
return fabs(difference1.x) < epsilon && fabs(difference1.y) < epsilon
&& fabs(difference2.x) < epsilon && fabs(difference2.y) < epsilon
return abs(difference1.x) < epsilon && abs(difference1.y) < epsilon
&& abs(difference2.x) < epsilon && abs(difference2.y) < epsilon
}

public var center: CGPoint {
Expand All @@ -19,6 +19,12 @@ extension CGRect: CustomStringConvertible {
}
}

public func * (left: CGRect, right: CGAffineTransform) -> CGRect {
return left.applying(right)
extension CGRect {
public static func * (lhs: CGRect, rhs: CGAffineTransform) -> CGRect {
return lhs.applying(rhs)
}

public static func *= (lhs: inout CGRect, rhs: CGAffineTransform) {
lhs = lhs * rhs
}
}
Loading

0 comments on commit 5b6df07

Please sign in to comment.