@@ -60,19 +60,17 @@ extension NSBezierPath {
6060 let distance1 = sqrt ( vector1. x * vector1. x + vector1. y * vector1. y)
6161 let distance2 = sqrt ( vector2. x * vector2. x + vector2. y * vector2. y)
6262
63- // TODO: Check if .zero should get used or just skipped
64- if distance1. isZero || distance2. isZero { continue }
63+ if distance1. isZero || distance2. isZero {
64+ // Dividing by 0 will result in `NaN` points.
65+ continue
66+ }
6567 let unitVector1 = distance1 > 0 ? NSPoint ( x: vector1. x / distance1, y: vector1. y / distance1) : NSPoint . zero
6668 let unitVector2 = distance2 > 0 ? NSPoint ( x: vector2. x / distance2, y: vector2. y / distance2) : NSPoint . zero
6769
6870 // This uses the dot product formula: cos(θ) = (u1 • u2),
6971 // where u1 and u2 are unit vectors. The result will range from -1 to 1:
7072 let angleCosine = unitVector1. x * unitVector2. x + unitVector1. y * unitVector2. y
7173
72- // If the cosine of the angle is less than 0.5 (i.e., angle > ~60 degrees),
73- // the radius is reduced to half to avoid overlapping or excessive smoothing.
74- let clampedRadius = angleCosine < 0.5 ? radius /** 0.5 */: radius // Adjust for sharp angles
75-
7674 // Calculate the corner start and end
7775 let cornerStart = NSPoint ( x: p1. x - unitVector1. x * radius, y: p1. y - unitVector1. y * radius)
7876 let cornerEnd = NSPoint ( x: p1. x + unitVector2. x * radius, y: p1. y + unitVector2. y * radius)
@@ -95,6 +93,14 @@ extension NSBezierPath {
9593 // Calculate the vectors and unit vectors
9694 let finalVector = NSPoint ( x: firstPoint. x - lastPoint. x, y: firstPoint. y - lastPoint. y)
9795 let distance = sqrt ( finalVector. x * finalVector. x + finalVector. y * finalVector. y)
96+
97+ // Dividing by 0 after this will cause an assertion failure. Something went wrong with the given points
98+ // this could mean we're rounding a 0-width and 0-height rect.
99+ guard distance != 0 else {
100+ path. line ( to: lastPoint)
101+ return path
102+ }
103+
98104 let unitVector = NSPoint ( x: finalVector. x / distance, y: finalVector. y / distance)
99105
100106 // Calculate the final corner start and initial corner end
0 commit comments