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

- old
+ new

@@ -49,10 +49,16 @@ # Subclasses can override def height max_y - min_y if max_y && min_y end + # Center point is `[center_x, center_y]` + # Returns `nil` if either center_x or center_y are `nil` + def center_point + [center_x, center_y] unless center_x.nil? || center_y.nil? + end + # center_x is min_x + width/2.0 by default # Returns nil if min_x or width are nil def center_x min_x + width / BigDecimal('2.0') if min_x && width end @@ -77,11 +83,11 @@ # # @return Array of x and y BigDecimal's representing point def normalize_point(x_or_point, y = nil) x = x_or_point x, y = x if y.nil? && x_or_point.is_a?(Array) && x_or_point.size == 2 - x = BigDecimal(x.to_s) - y = BigDecimal(y.to_s) + x = x.is_a?(BigDecimal) ? x : BigDecimal(x.to_s) + y = y.is_a?(BigDecimal) ? y : BigDecimal(y.to_s) [x, y] end # Subclasses must implement def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)