Skip to content

Commit

Permalink
Use XY.Less comparison func
Browse files Browse the repository at this point in the history
`XY` has `Less` method to compare two `XY` values. This logic was
duplicated in two other places. This change removes the duplication,
instead relying on the `Less` method.
  • Loading branch information
peterstace committed Jan 20, 2024
1 parent 8ee2e0f commit e5f3ef7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
5 changes: 1 addition & 4 deletions geom/alg_convex_hull.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ func convexHullPointSet(g Geometry) []XY {

func monotoneChain(pts []XY) []XY {
sort.Slice(pts, func(i, j int) bool {
if pts[i].X != pts[j].X {
return pts[i].X < pts[j].X
}
return pts[i].Y < pts[j].Y
return pts[i].Less(pts[j])
})

// Calculate lower hull.
Expand Down
4 changes: 1 addition & 3 deletions geom/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ func rightmostThenHighestIndex(ps []XY) int {
func leftmostThenLowestIndex(ps []XY) int {
rpi := 0
for i := 1; i < len(ps); i++ {
if ps[i].X < ps[rpi].X ||
(ps[i].X == ps[rpi].X &&
ps[i].Y < ps[rpi].Y) {
if ps[i].Less(ps[rpi]) {
rpi = i
}
}
Expand Down

0 comments on commit e5f3ef7

Please sign in to comment.