Skip to content

Commit

Permalink
Merge pull request #18 from LinkAndreas/#15-Fix-line-contains
Browse files Browse the repository at this point in the history
Fix line contains point method
  • Loading branch information
Toine Heuvelmans authored May 22, 2019
2 parents a345caf + dd3cc14 commit ac32b11
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/Metron/Shape/Line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ public extension Line {
/// - returns: True when the provided point is on this `Line`.
/// - note: An error margin of 1e-12 is allowed.
public func contains(_ point: CGPoint) -> Bool {
guard let pointAtX = self.point(atX: point.x) else { return false }
return point.distance(to: pointAtX) <= 1e-12
switch definition {
case .sloped:
guard let pointAtX = self.point(atX: point.x) else { return false }
return point.distance(to: pointAtX) <= 1e-12

case let .vertical(x):
return point.x == x
}
}

/// - returns: The intersection of this `Line` with the provided `Line`.
Expand Down

0 comments on commit ac32b11

Please sign in to comment.