Skip to content

Commit

Permalink
Add optional parameter "epsilon" to Geometry2D.PointOnLine method
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahStolk committed Sep 26, 2024
1 parent e64d294 commit e13fcba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This library uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

### Added

- Added optional parameter `epsilon` to `Geometry2D.PointOnLine` method.

### Changed

- Renamed `OrientedRectangle.Position` to `OrientedRectangle.Center`.
Expand Down
4 changes: 2 additions & 2 deletions src/Detach/Collisions/Geometry2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class Geometry2D
{
#region Point vs primitives

public static bool PointOnLine(Vector2 point, LineSegment2D line)
public static bool PointOnLine(Vector2 point, LineSegment2D line, float epsilon = 0.0001f)
{
// Find the slope.
float dy = line.End.Y - line.Start.Y;
Expand All @@ -21,7 +21,7 @@ public static bool PointOnLine(Vector2 point, LineSegment2D line)
float b = line.Start.Y - m * line.Start.X;

// Check if the point is on the line.
return MathF.Abs(point.Y - (m * point.X + b)) < 0.0001f;
return MathF.Abs(point.Y - (m * point.X + b)) < epsilon;
}

public static bool PointInCircle(Vector2 point, Circle circle)
Expand Down

0 comments on commit e13fcba

Please sign in to comment.