Skip to content

Commit

Permalink
move tests around, fix compilation issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutrell committed Nov 25, 2020
1 parent f3b1b05 commit bcdef1e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 39 deletions.
6 changes: 0 additions & 6 deletions BezierKit/BezierKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
FD4A6404200ACBD200930E10 /* ShapeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD4A6400200ACB8900930E10 /* ShapeTests.swift */; };
FD4A6408200B11DF00930E10 /* PathComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD4A6405200B11DA00930E10 /* PathComponentTests.swift */; };
FD4A6409200B11DF00930E10 /* PathComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD4A6405200B11DA00930E10 /* PathComponentTests.swift */; };
FD5CAEE6256C3E480081A964 /* PathComponent+Projection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD5CAEE5256C3E480081A964 /* PathComponent+Projection.swift */; };
FD5CAEE7256C3E480081A964 /* PathComponent+Projection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD5CAEE5256C3E480081A964 /* PathComponent+Projection.swift */; };
FD5CAEF5256C42C00081A964 /* Path+Projection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD5CAEF4256C42C00081A964 /* Path+Projection.swift */; };
FD5CAEF6256C42C00081A964 /* Path+Projection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD5CAEF4256C42C00081A964 /* Path+Projection.swift */; };
FD5CAF04256C92B90081A964 /* Path+ProjectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD5CAF03256C92B90081A964 /* Path+ProjectionTests.swift */; };
Expand Down Expand Up @@ -164,7 +162,6 @@
FD4A63FD200AA50B00930E10 /* Shape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Shape.swift; path = Library/Shape.swift; sourceTree = SOURCE_ROOT; };
FD4A6400200ACB8900930E10 /* ShapeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapeTests.swift; sourceTree = "<group>"; };
FD4A6405200B11DA00930E10 /* PathComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathComponentTests.swift; sourceTree = "<group>"; };
FD5CAEE5256C3E480081A964 /* PathComponent+Projection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PathComponent+Projection.swift"; sourceTree = "<group>"; };
FD5CAEF4256C42C00081A964 /* Path+Projection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Path+Projection.swift"; sourceTree = "<group>"; };
FD5CAF03256C92B90081A964 /* Path+ProjectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Path+ProjectionTests.swift"; sourceTree = "<group>"; };
FD5CAF0A256C92DB0081A964 /* PathComponent+ProjectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PathComponent+ProjectionTests.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -339,7 +336,6 @@
FDCE99A4223C404E00597989 /* Path+Data.swift */,
FD5CAEF4256C42C00081A964 /* Path+Projection.swift */,
FDB6B3FD1EAFD6DF00001C61 /* PathComponent.swift */,
FD5CAEE5256C3E480081A964 /* PathComponent+Projection.swift */,
FD84360422B0091500AA90EF /* PathComponent+WindingCount.swift */,
FD067AC7246F1200006DA36B /* Polynomial.swift */,
FDB6B3FE1EAFD6DF00001C61 /* QuadraticCurve.swift */,
Expand Down Expand Up @@ -665,7 +661,6 @@
FDB6B4071EAFD6DF00001C61 /* Draw.swift in Sources */,
FDB6B4131EAFD6DF00001C61 /* Types.swift in Sources */,
FDB6B4031EAFD6DF00001C61 /* BezierCurve.swift in Sources */,
FD5CAEE7256C3E480081A964 /* PathComponent+Projection.swift in Sources */,
FDB6B4051EAFD6DF00001C61 /* CubicCurve.swift in Sources */,
FDE6CD8D1EC8F2F800FAB479 /* LineSegment.swift in Sources */,
FD149EBB2135CBFF009E791D /* AugmentedGraph.swift in Sources */,
Expand All @@ -692,7 +687,6 @@
FDB6B4061EAFD6DF00001C61 /* Draw.swift in Sources */,
FDB6B4121EAFD6DF00001C61 /* Types.swift in Sources */,
FDB6B4021EAFD6DF00001C61 /* BezierCurve.swift in Sources */,
FD5CAEE6256C3E480081A964 /* PathComponent+Projection.swift in Sources */,
FDB6B4041EAFD6DF00001C61 /* CubicCurve.swift in Sources */,
FDE6CD8C1EC8F2F800FAB479 /* LineSegment.swift in Sources */,
FD149EBA2135CBFF009E791D /* AugmentedGraph.swift in Sources */,
Expand Down
26 changes: 25 additions & 1 deletion BezierKit/BezierKitTests/Path+ProjectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//

@testable import BezierKit
import Foundation
import XCTest

#if canImport(CoreGraphics)
import CoreGraphics

class PathProjectionTests: XCTestCase {
func testProjection() {
XCTAssertNil(Path().project(CGPoint.zero), "projection requires non-empty path.")
Expand All @@ -35,4 +37,26 @@ class PathProjectionTests: XCTestCase {
XCTAssertEqual(projection?.location, IndexedPathLocation(componentIndex: 1, elementIndex: 2, t: 0.5))
XCTAssertEqual(projection?.point, CGPoint(x: 2.5, y: 1.5))
}
func testPointIsWithinDistanceOfBoundary() {

let circleCGPath = CGMutablePath()
circleCGPath.addEllipse(in: CGRect(origin: CGPoint(x: -1.0, y: -1.0), size: CGSize(width: 2.0, height: 2.0)))

let circlePath = Path(cgPath: circleCGPath) // a circle centered at origin with radius 1

let d = CGFloat(0.1)
let p1 = CGPoint(x: -3.0, y: 0.0)
let p2 = CGPoint(x: -0.9, y: 0.9)
let p3 = CGPoint(x: 0.75, y: 0.75)
let p4 = CGPoint(x: 0.5, y: 0.5)

XCTAssertFalse(circlePath.pointIsWithinDistanceOfBoundary(p1, distance: d)) // no, path bounding box isn't even within that distance
XCTAssertFalse(circlePath.pointIsWithinDistanceOfBoundary(p2, distance: d)) // no, within bounding box, but no individual curves are within that distance
XCTAssertTrue(circlePath.pointIsWithinDistanceOfBoundary(p3, distance: d)) // yes, one of the curves that makes up the circle is within that distance
XCTAssertTrue(circlePath.pointIsWithinDistanceOfBoundary(p3, distance: CGFloat(10.0))) // yes, so obviously within that distance implementation should early return yes
XCTAssertFalse(circlePath.pointIsWithinDistanceOfBoundary(p4, distance: d)) // no, we are inside the path but too far from the boundary

}
}

#endif
6 changes: 5 additions & 1 deletion BezierKit/BezierKitTests/PathComponent+ProjectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//

@testable import BezierKit
import Foundation
import XCTest

#if canImport(CoreGraphics)
import CoreGraphics

class PathComponentProjectionTests: XCTestCase {
func testProject() {
let line = PathComponent(curve: LineSegment(p0: CGPoint(x: 1, y: 1), p1: CGPoint(x: 2, y: 2)))
Expand Down Expand Up @@ -93,3 +95,5 @@ class PathComponentProjectionTests: XCTestCase {
}
}
}

#endif
21 changes: 0 additions & 21 deletions BezierKit/BezierKitTests/PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,6 @@ class PathTests: XCTestCase {
indexedPathLocation2: IndexedPathLocation(componentIndex: 0, elementIndex: 2, t: 0.5))])
}

func testPointIsWithinDistanceOfBoundary() {

let circleCGPath = CGMutablePath()
circleCGPath.addEllipse(in: CGRect(origin: CGPoint(x: -1.0, y: -1.0), size: CGSize(width: 2.0, height: 2.0)))

let circlePath = Path(cgPath: circleCGPath) // a circle centered at origin with radius 1

let d = CGFloat(0.1)
let p1 = CGPoint(x: -3.0, y: 0.0)
let p2 = CGPoint(x: -0.9, y: 0.9)
let p3 = CGPoint(x: 0.75, y: 0.75)
let p4 = CGPoint(x: 0.5, y: 0.5)

XCTAssertFalse(circlePath.pointIsWithinDistanceOfBoundary(p1, distance: d)) // no, path bounding box isn't even within that distance
XCTAssertFalse(circlePath.pointIsWithinDistanceOfBoundary(p2, distance: d)) // no, within bounding box, but no individual curves are within that distance
XCTAssertTrue(circlePath.pointIsWithinDistanceOfBoundary(p3, distance: d)) // yes, one of the curves that makes up the circle is within that distance
XCTAssertTrue(circlePath.pointIsWithinDistanceOfBoundary(p3, distance: CGFloat(10.0))) // yes, so obviously within that distance implementation should early return yes
XCTAssertFalse(circlePath.pointIsWithinDistanceOfBoundary(p4, distance: d)) // no, we are inside the path but too far from the boundary

}

func testEquatable() {
let rect = CGRect(origin: CGPoint(x: -1, y: -1), size: CGSize(width: 2, height: 2))
let path1 = Path(cgPath: CGPath(rect: rect, transform: nil))
Expand Down
3 changes: 3 additions & 0 deletions BezierKit/Library/Path+Projection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Copyright © 2020 Holmes Futrell. All rights reserved.
//

#if canImport(CoreGraphics)
import CoreGraphics
#endif
import Foundation

public extension Path {
Expand Down
10 changes: 0 additions & 10 deletions BezierKit/Library/PathComponent+Projection.swift

This file was deleted.

0 comments on commit bcdef1e

Please sign in to comment.