File tree 2 files changed +7
-7
lines changed
2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ module ConvexHull
8
8
def initialize (points : Array (Tuple (Int32 | Float32 | Float64 , Int32 | Float32 | Float64 )))
9
9
raise " There must be at least 3 points" if points.size < 3
10
10
11
- points = points.uniq.map { |p | Point .new(p [0 ], p [1 ]) }.sort!
11
+ points = points.uniq.map { |point | Point .new(point [0 ], point [1 ]) }.sort!
12
12
13
13
@convex_hull = convex_hull(points)
14
14
end
Original file line number Diff line number Diff line change @@ -3,22 +3,22 @@ module ConvexHull
3
3
private def convex_hull (points ) : Array (Point )
4
4
lower = Array (Point ).new
5
5
6
- points.each do |p |
7
- while lower.size > 1 && cross(lower[-2 ], lower[-1 ], p ) <= 0
6
+ points.each do |point |
7
+ while lower.size > 1 && cross(lower[-2 ], lower[-1 ], point ) <= 0
8
8
lower.pop
9
9
end
10
10
11
- lower.push(p )
11
+ lower.push(point )
12
12
end
13
13
14
14
upper = Array (Point ).new
15
15
16
- points.reverse_each do |p |
17
- while upper.size > 1 && cross(upper[-2 ], upper[-1 ], p ) <= 0
16
+ points.reverse_each do |point |
17
+ while upper.size > 1 && cross(upper[-2 ], upper[-1 ], point ) <= 0
18
18
upper.pop
19
19
end
20
20
21
- upper.push(p )
21
+ upper.push(point )
22
22
end
23
23
24
24
hull = lower[...- 1 ] + upper[...- 1 ]
You can’t perform that action at this time.
0 commit comments