Class: Geometry::SizedObround

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

Accessors collapse

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]

    Parameters:

    • height (Number)

      Height

    • width (Number)

      Width

  • #new(size) ⇒ Object

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

    Parameters:

    • size (Size)

      Width and height

  • #new(origin, size) ⇒ Object

    Creates an Obround with the given origin point and size

    Parameters:



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

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

#centerObject (readonly)



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

def center
  @center
end

#originPoint

Returns The Obround‘s origin.

Returns:



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

def origin
  @origin
end

#sizeSize

Returns The Geometry::Size of the Obround.

Returns:



188
189
190
# File 'lib/geometry/obround.rb', line 188

def size
  @size
end

Instance Method Details

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

Returns:

  • (Boolean)


216
217
218
# File 'lib/geometry/obround.rb', line 216

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

#heightObject



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

def height
    @size.height
end

#pointsArray<Point>

Returns The Obround‘s four points (clockwise).

Returns:

  • (Array<Point>)

    The Obround‘s four points (clockwise)



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

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



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

def width
    @size.width
end