Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangel-dev committed Dec 10, 2021
1 parent 299dc81 commit 1bc0dbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
32 changes: 1 addition & 31 deletions BezierKit/BezierKitTests/Path+VectorBooleanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@testable import BezierKit
import XCTest

private extension Path {
internal extension Path {
/// copies the path in such a way that it's impossible that optimizations would allow the copy to share the same underlying storage
func independentCopy() -> Path {
return self.copy(using: CGAffineTransform(translationX: 1, y: 0)).copy(using: CGAffineTransform(translationX: -1, y: 0))
Expand Down Expand Up @@ -474,36 +474,6 @@ class PathVectorBooleanTests: XCTestCase {
XCTAssertTrue(componentsEqualAsideFromElementOrdering(result.components[0], square.components[0]))
}

func testCrossingsRemovedEdgeCase() {
// this is an edge cases which caused difficulty in practice
// the contour, which intersects at (1,1) creates two squares, one with -1 winding count
// the other with +1 winding count
// incorrect implementation of this algorithm previously interpretted
// the crossing as an entry / exit, which would completely cull off the square with +1 count

let points = [CGPoint(x: 0, y: 1),
CGPoint(x: 1, y: 1),
CGPoint(x: 2, y: 1),
CGPoint(x: 2, y: 2),
CGPoint(x: 1, y: 2),
CGPoint(x: 1, y: 1),
CGPoint(x: 1, y: 0),
CGPoint(x: 0, y: 0)]

let cgPath = CGMutablePath()
cgPath.addLines(between: points)
cgPath.closeSubpath()

let contour = Path(cgPath: cgPath)
XCTAssertEqual(contour.windingCount(CGPoint(x: 0.5, y: 0.5)), -1) // winding count at center of one square region
XCTAssertEqual(contour.windingCount(CGPoint(x: 1.5, y: 1.5)), 1) // winding count at center of other square region

let crossingsRemoved = contour.crossingsRemoved()

XCTAssertEqual(crossingsRemoved.components.count, 1)
XCTAssertTrue(componentsEqualAsideFromElementOrdering(crossingsRemoved.components[0], contour.components[0]))
}

func testCrossingsRemovedEdgeCaseInnerLoop() {

// the path is a box with a loop that begins at (2,0), touches the top of the box at (2,2) exactly tangent
Expand Down
8 changes: 6 additions & 2 deletions BezierKit/Library/AugmentedGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ private class Node {
}
func mergeNeighbors(of node: Node) {
node.neighbors.forEach {
$0.replaceNeighbor(node, with: self)
self.addNeighbor($0)
if !$0.neighborsContain(self) {
$0.replaceNeighbor(node, with: self)
}
if !self.neighborsContain($0) {
self.addNeighbor($0)
}
}
}
/// Nodes can have strong reference cycles either through their neighbors or through their edges, unlinking all nodes when owner no longer holds instance prevents memory leakage
Expand Down

0 comments on commit 1bc0dbc

Please sign in to comment.