lib/geometry/point_iso.rb in geometry-6.3 vs lib/geometry/point_iso.rb in geometry-6.4
- old
+ new
@@ -51,9 +51,47 @@
# This is a hack to get Array#== to work properly. It works on ruby 2.0 and 1.9.3.
def to_ary
[]
end
+ # @override max()
+ # @return [Number] The maximum value of the {Point}'s elements
+ # @override max(point)
+ # @return [Point] The element-wise maximum values of the receiver and the given {Point}
+ def max(*args)
+ if args.empty?
+ @value
+ else
+ args = args.first if 1 == args.size
+ Point[Array.new(args.size, @value).zip(args).map(&:max)]
+ end
+ end
+
+ # @override min()
+ # @return [Number] The minimum value of the {Point}'s elements
+ # @override min(point)
+ # @return [Point] The element-wise minimum values of the receiver and the given {Point}
+ def min(*args)
+ if args.empty?
+ @value
+ else
+ args = args.first if 1 == args.size
+ Point[Array.new(args.size, @value).zip(args).map(&:min)]
+ end
+ end
+
+ # @override minmax()
+ # @return [Array<Number>] The minimum value of the {Point}'s elements
+ # @override min(point)
+ # @return [Array<Point>] The element-wise minimum values of the receiver and the given {Point}
+ def minmax(*args)
+ if args.empty?
+ [@value, @value]
+ else
+ [min(*args), max(*args)]
+ end
+ end
+
# @group Accessors
# @param i [Integer] Index into the {Point}'s elements
# @return [Numeric] Element i (starting at 0)
def [](i)
@value