diff --git a/src/convex_hull/algorithm.cr b/src/convex_hull/algorithm.cr index 0ba6986..1ae639f 100644 --- a/src/convex_hull/algorithm.cr +++ b/src/convex_hull/algorithm.cr @@ -8,7 +8,7 @@ module ConvexHull def initialize(points : Array(Tuple(Int32 | Float32 | Float64, Int32 | Float32 | Float64))) raise "There must be at least 3 points" if points.size < 3 - points = points.uniq.map { |p| Point.new(p[0], p[1]) }.sort! + points = points.uniq.map { |point| Point.new(point[0], point[1]) }.sort! @convex_hull = convex_hull(points) end diff --git a/src/convex_hull/graham_scan.cr b/src/convex_hull/graham_scan.cr index ce8538f..9015a6f 100644 --- a/src/convex_hull/graham_scan.cr +++ b/src/convex_hull/graham_scan.cr @@ -3,22 +3,22 @@ module ConvexHull private def convex_hull(points) : Array(Point) lower = Array(Point).new - points.each do |p| - while lower.size > 1 && cross(lower[-2], lower[-1], p) <= 0 + points.each do |point| + while lower.size > 1 && cross(lower[-2], lower[-1], point) <= 0 lower.pop end - lower.push(p) + lower.push(point) end upper = Array(Point).new - points.reverse_each do |p| - while upper.size > 1 && cross(upper[-2], upper[-1], p) <= 0 + points.reverse_each do |point| + while upper.size > 1 && cross(upper[-2], upper[-1], point) <= 0 upper.pop end - upper.push(p) + upper.push(point) end hull = lower[...-1] + upper[...-1]