lib/perfect_shape/point.rb in perfect-shape-0.3.3 vs lib/perfect_shape/point.rb in perfect-shape-0.3.4

- old
+ new

@@ -25,14 +25,14 @@ module PerfectShape # Point class includes point-specific operations like `#==`, `point_distance` and a fuzzy `contain?` matcher class Point < Shape class << self def point_distance(x, y, px, py) - x = BigDecimal(x.to_s) - y = BigDecimal(y.to_s) - px = BigDecimal(px.to_s) - py = BigDecimal(py.to_s) + x = x.is_a?(BigDecimal) ? x : BigDecimal(x.to_s) + y = y.is_a?(BigDecimal) ? y : BigDecimal(y.to_s) + px = px.is_a?(BigDecimal) ? px : BigDecimal(px.to_s) + py = py.is_a?(BigDecimal) ? py : BigDecimal(py.to_s) BigDecimal(Math.sqrt((px - x)**2 + (py - y)**2).to_s) end end include PointLocation @@ -65,19 +65,20 @@ # @param y The Y coordinate of the point to test. # @param distance_tolerance The distance from point to tolerate (0 by default) # # @return {@code true} if the point is close enough within distance tolerance, # {@code false} if the point is too far. - def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) + def contain?(x_or_point, y = nil, outline: true, distance_tolerance: 0) x, y = normalize_point(x_or_point, y) return unless x && y distance_tolerance = BigDecimal(distance_tolerance.to_s) point_distance(x, y) <= distance_tolerance end def point_distance(x_or_point, y = nil) x, y = normalize_point(x_or_point, y) return unless x && y + Point.point_distance(self.x, self.y, x, y) end # Convert to pair Array of x,y coordinates def to_a