Class: Geometry::CenteredObround

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

Instance Attribute Summary collapse

Accessors collapse

Instance Method Summary collapse

Methods inherited from Obround

new

Methods included from ClusterFactory

included

Constructor Details

#new(width, height) ⇒ CenteredObround #new(size) ⇒ CenteredObround #new(center, size) ⇒ CenteredObround

Returns a new instance of CenteredObround.

Overloads:

  • #new(width, height) ⇒ CenteredObround

    Creates a Obround of the given width and height, centered on the origin

    Parameters:

    • height (Number)

      Height

    • width (Number)

      Width

  • #new(size) ⇒ CenteredObround

    Creates a Obround of the given Size centered on the origin

    Parameters:

    • size (Size)

      Width and height

  • #new(center, size) ⇒ CenteredObround

    Creates a Obround with the given center point and size

    Parameters:



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/geometry/obround.rb', line 139

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

Instance Attribute Details

#centerPoint

Returns The Obround‘s center.

Returns:



121
122
123
# File 'lib/geometry/obround.rb', line 121

def center
  @center
end

#originObject (readonly)

Returns the value of attribute origin.



122
123
124
# File 'lib/geometry/obround.rb', line 122

def origin
  @origin
end

#sizeSize

Returns The Size of the Obround.

Returns:



124
125
126
# File 'lib/geometry/obround.rb', line 124

def size
  @size
end

Instance Method Details

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

Returns:

  • (Boolean)


151
152
153
# File 'lib/geometry/obround.rb', line 151

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

#heightObject



166
167
168
# File 'lib/geometry/obround.rb', line 166

def height
    @size.height
end

#pointsArray<Point>

Returns The Obround‘s four points (clockwise).

Returns:

  • (Array<Point>)

    The Obround‘s four points (clockwise)



158
159
160
161
162
163
164
# File 'lib/geometry/obround.rb', line 158

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

#widthObject



170
171
172
# File 'lib/geometry/obround.rb', line 170

def width
    @size.width
end