Skip to content

Commit 1bc0dbc

Browse files
fix unit tests
1 parent 299dc81 commit 1bc0dbc

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

BezierKit/BezierKitTests/Path+VectorBooleanTests.swift

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@testable import BezierKit
1010
import XCTest
1111

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

477-
func testCrossingsRemovedEdgeCase() {
478-
// this is an edge cases which caused difficulty in practice
479-
// the contour, which intersects at (1,1) creates two squares, one with -1 winding count
480-
// the other with +1 winding count
481-
// incorrect implementation of this algorithm previously interpretted
482-
// the crossing as an entry / exit, which would completely cull off the square with +1 count
483-
484-
let points = [CGPoint(x: 0, y: 1),
485-
CGPoint(x: 1, y: 1),
486-
CGPoint(x: 2, y: 1),
487-
CGPoint(x: 2, y: 2),
488-
CGPoint(x: 1, y: 2),
489-
CGPoint(x: 1, y: 1),
490-
CGPoint(x: 1, y: 0),
491-
CGPoint(x: 0, y: 0)]
492-
493-
let cgPath = CGMutablePath()
494-
cgPath.addLines(between: points)
495-
cgPath.closeSubpath()
496-
497-
let contour = Path(cgPath: cgPath)
498-
XCTAssertEqual(contour.windingCount(CGPoint(x: 0.5, y: 0.5)), -1) // winding count at center of one square region
499-
XCTAssertEqual(contour.windingCount(CGPoint(x: 1.5, y: 1.5)), 1) // winding count at center of other square region
500-
501-
let crossingsRemoved = contour.crossingsRemoved()
502-
503-
XCTAssertEqual(crossingsRemoved.components.count, 1)
504-
XCTAssertTrue(componentsEqualAsideFromElementOrdering(crossingsRemoved.components[0], contour.components[0]))
505-
}
506-
507477
func testCrossingsRemovedEdgeCaseInnerLoop() {
508478

509479
// the path is a box with a loop that begins at (2,0), touches the top of the box at (2,2) exactly tangent

BezierKit/Library/AugmentedGraph.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ private class Node {
4848
}
4949
func mergeNeighbors(of node: Node) {
5050
node.neighbors.forEach {
51-
$0.replaceNeighbor(node, with: self)
52-
self.addNeighbor($0)
51+
if !$0.neighborsContain(self) {
52+
$0.replaceNeighbor(node, with: self)
53+
}
54+
if !self.neighborsContain($0) {
55+
self.addNeighbor($0)
56+
}
5357
}
5458
}
5559
/// 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

0 commit comments

Comments
 (0)