Class: Geometry::CenteredRectangle
Instance Attribute Summary collapse
Attributes inherited from Rectangle
#options, #origin
Instance Method Summary
collapse
Methods inherited from Rectangle
#bounds, #inset, #minmax, new
included
Constructor Details
Returns a new instance of CenteredRectangle.
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/geometry/rectangle.rb', line 235
def initialize(*args)
options, args = args.partition {|a| a.is_a? Hash}
options = options.reduce({}, :merge)
@center = options[:center] ? Point[options[:center]] : PointZero.new
if options.has_key?(:size)
@size = Geometry::Size[options[:size]]
elsif options.has_key?(:height) and options.has_key?(:width)
@size = Geometry::Size[options[:width], options[:height]]
else
raise ArgumentError, "Bad arguments to CenteredRectangle#new"
end
end
|
Instance Attribute Details
218
219
220
|
# File 'lib/geometry/rectangle.rb', line 218
def center
@center
end
|
220
221
222
|
# File 'lib/geometry/rectangle.rb', line 220
def size
@size
end
|
Instance Method Details
#edges ⇒ Array<Edge>
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/geometry/rectangle.rb', line 257
def edges
point0 = @center - @size/2.0
point2 = @center + @size/2.0
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) ⇒ Boolean
Also known as:
==
250
251
252
|
# File 'lib/geometry/rectangle.rb', line 250
def eql?(other)
(self.center == other.center) && (self.size == other.size)
end
|
#height ⇒ Object
287
288
289
|
# File 'lib/geometry/rectangle.rb', line 287
def height
@size.height
end
|
269
270
271
|
# File 'lib/geometry/rectangle.rb', line 269
def max
@center + @size/2.0
end
|
274
275
276
|
# File 'lib/geometry/rectangle.rb', line 274
def min
@center - @size/2.0
end
|
#points ⇒ Array<Point>
279
280
281
282
283
284
285
|
# File 'lib/geometry/rectangle.rb', line 279
def points
point0 = @center - @size/2.0
point2 = @center + @size/2.0
point1 = Point[point0.x,point2.y]
point3 = Point[point2.x, point0.y]
[point0, point1, point2, point3]
end
|
#width ⇒ Object
291
292
293
|
# File 'lib/geometry/rectangle.rb', line 291
def width
@size.width
end
|