class Euclidean::SizedRectangle
Attributes
origin[RW]
@return [Point] The {Rectangle}‘s origin
size[RW]
@return [Size] The {Size} of the {Rectangle}
Public Class Methods
new(*args)
click to toggle source
@overload new(width, height)
Creates a {Rectangle} of the given width and height with its origin at [0,0] @param [Number] height Height @param [Number] width Width @return SizedRectangle
@overload new(size)
Creates a {Rectangle} of the given {Size} with its origin at [0,0] @param [Size] size Width and height @return SizedRectangle
@overload new(origin, size)
Creates a {Rectangle} with the given origin point and size @param [Point] origin @param [Size] size @return SizedRectangle
# File lib/euclidean/rectangle.rb, line 310 def initialize(*args) options, args = args.partition {|a| a.is_a? Hash} options = options.reduce({}, :merge) @origin = options[:origin] ? Point[options[:origin]] : PointZero.new if options.has_key?(:size) @size = Euclidean::Size[options[:size]] elsif options.has_key?(:height) and options.has_key?(:width) @size = Euclidean::Size[options[:width], options[:height]] else raise ArgumentError, "Bad arguments to SizeRectangle#new" end end
Public Instance Methods
center()
click to toggle source
@group Accessors @return [Point] The {Rectangle}‘s center
# File lib/euclidean/rectangle.rb, line 332 def center @origin + @size/2 end
edges()
click to toggle source
@return [Array<Edge>] The {Rectangle}‘s four edges
# File lib/euclidean/rectangle.rb, line 337 def edges point0 = @origin point2 = @origin + @size point1 = Point[point0.x,point2.y] point3 = Point[point2.x, point0.y] [Edge.new(point0, point1), Edge.new(point1, point2), Edge.new(point2, point3), Edge.new(point3, point0)] end
eql?(other)
click to toggle source
# File lib/euclidean/rectangle.rb, line 325 def eql?(other) (self.origin == other.origin) && (self.size == other.size) end
Also aliased as: ==
height()
click to toggle source
# File lib/euclidean/rectangle.rb, line 348 def height @size.height end
max()
click to toggle source
@return [Point] The upper right corner of the bounding {Rectangle}
# File lib/euclidean/rectangle.rb, line 353 def max @origin + @size end
min()
click to toggle source
@return [Point] The lower left corner of the bounding {Rectangle}
# File lib/euclidean/rectangle.rb, line 358 def min @origin end
points()
click to toggle source
@return [Array<Point>] The {Rectangle}‘s four points (clockwise)
# File lib/euclidean/rectangle.rb, line 363 def points point0 = @origin point2 = @origin + @size point1 = Point[point0.x,point2.y] point3 = Point[point2.x, point0.y] [point0, point1, point2, point3] end
width()
click to toggle source
# File lib/euclidean/rectangle.rb, line 371 def width @size.width end