Class: Geometry::SizedObround

Inherits:
Obround
  • Object
show all
Defined in:
lib/geometry/obround.rb

Instance Attribute Summary collapse

Attributes inherited from Obround

#closed?

Accessors collapse

Instance Method Summary collapse

Methods inherited from Obround

new

Methods included from ClusterFactory

included

Constructor Details

#new(width, height) ⇒ Object #new(size) ⇒ Object #new(origin, size) ⇒ Object

Returns a new instance of SizedObround.

Overloads:

  • #new(width, height) ⇒ Object

    Creates an Obround of the given width and height with its origin at [0,0]

  • #new(size) ⇒ Object

    Creates an Obround of the given Geometry::Size with its origin at [0,0]

  • #new(origin, size) ⇒ Object

    Creates an Obround with the given origin point and size



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/geometry/obround.rb', line 202

def initialize(*args)
    if args[0].is_a?(Size)
	@origin = Point[0,0]
	@size = args[0]
    elsif (args[0].is_a?(Point) or args[0].is_a?(Array)) and args[1].is_a?(Geometry::Size)
	@origin, @size = Point[args[0]], args[1]
    elsif (2 == args.size) and args.all? {|a| a.is_a?(Numeric)}
	@origin = Point[0,0]
	@size = Geometry::Size[*args]
    end
end

Instance Attribute Details

#originPoint



184
185
186
# File 'lib/geometry/obround.rb', line 184

def origin
  @origin
end

#sizeSize



186
187
188
# File 'lib/geometry/obround.rb', line 186

def size
  @size
end

Instance Method Details

#centerPoint



221
222
223
# File 'lib/geometry/obround.rb', line 221

def center
    @origin + @size/2
end

#eql?(other) ⇒ Boolean Also known as: ==



214
215
216
# File 'lib/geometry/obround.rb', line 214

def eql?(other)
    (self.origin == other.origin) && (self.size == other.size)
end

#heightObject



234
235
236
# File 'lib/geometry/obround.rb', line 234

def height
    @size.height
end

#pointsArray<Point>



226
227
228
229
230
231
232
# File 'lib/geometry/obround.rb', line 226

def points
    point0 = @origin
    point2 = @origin + @size
    point1 = Point[point0.x,point2.y]
    point3 = Point[point2.x, point0.y]
    [point0, point1, point2, point3]
end

#widthObject



238
239
240
# File 'lib/geometry/obround.rb', line 238

def width
    @size.width
end