lib/perfect_shape/line.rb in perfect-shape-0.3.3 vs lib/perfect_shape/line.rb in perfect-shape-0.3.4
- old
+ new
@@ -102,11 +102,11 @@
# measured against the specified line segment
# @param py the Y coordinate of the specified point being
# measured against the specified line segment
# @return a double value that is the square of the distance from the
# specified point to the specified line segment.
- def point_segment_distance_square(x1, y1,
+ def point_distance_square(x1, y1,
x2, y2,
px, py)
x1 = BigDecimal(x1.to_s)
y1 = BigDecimal(y1.to_s)
x2 = BigDecimal(x2.to_s)
@@ -175,14 +175,14 @@
# measured against the specified line segment
# @param py the Y coordinate of the specified point being
# measured against the specified line segment
# @return a double value that is the distance from the specified point
# to the specified line segment.
- def point_segment_distance(x1, y1,
+ def point_distance(x1, y1,
x2, y2,
px, py)
- BigDecimal(::Math.sqrt(point_segment_distance_square(x1, y1, x2, y2, px, py)).to_s)
+ BigDecimal(::Math.sqrt(point_distance_square(x1, y1, x2, y2, px, py)).to_s)
end
# Calculates the number of times the line from (x1,y1) to (x2,y2)
# crosses the ray extending to the right from (px,py).
# If the point lies on the line, then no crossings are recorded.
@@ -210,20 +210,20 @@
# @param distance_tolerance The distance from line to tolerate (0 by default)
#
# @return {@code true} if the point lies within the bound of
# the line, {@code false} if the point lies outside of the
# line's bounds.
- 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_segment_distance(x, y) <= distance_tolerance
+ point_distance(x, y) <= distance_tolerance
end
- def point_segment_distance(x_or_point, y = nil)
+ def point_distance(x_or_point, y = nil)
x, y = normalize_point(x_or_point, y)
return unless x && y
- Line.point_segment_distance(points[0][0], points[0][1], points[1][0], points[1][1], x, y)
+ Line.point_distance(points[0][0], points[0][1], points[1][0], points[1][1], x, y)
end
def relative_counterclockwise(x_or_point, y = nil)
x, y = normalize_point(x_or_point, y)
return unless x && y