Class: Rectangle
- Inherits:
-
Object
- Object
- Rectangle
- Defined in:
- src/ruby/models/rectangle.rb,
mrb_doc/models/rectangle.rb
Overview
The Rectangle class is used for drawing and also collision checking.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#draw(origin: Vector2::ZERO, rotation: 0, outline: false, thickness: 2, rounded: false, radius: 0.5, segments: 8, colour: BLACK) ⇒ Rectangle
Draws a rectangle in several configurations.
-
#initialize(x, y, width, height) ⇒ Rectangle
constructor
Creates a new instance of Rectangle.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
Constructor Details
Instance Attribute Details
#height ⇒ Integer
4 5 6 |
# File 'src/ruby/models/rectangle.rb', line 4 def height @height end |
#width ⇒ Integer
4 5 6 |
# File 'src/ruby/models/rectangle.rb', line 4 def width @width end |
#x ⇒ Integer
4 5 6 |
# File 'src/ruby/models/rectangle.rb', line 4 def x @x end |
#y ⇒ Integer
4 5 6 |
# File 'src/ruby/models/rectangle.rb', line 4 def y @y end |
Instance Method Details
#draw(origin: Vector2::ZERO, rotation: 0, outline: false, thickness: 2, rounded: false, radius: 0.5, segments: 8, colour: BLACK) ⇒ Rectangle
Draws a rectangle in several configurations
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'src/ruby/models/rectangle.rb', line 26 def draw( origin: Vector2::ZERO, rotation: 0, # only usable when outline and rounded are false outline: false, thickness: 2, # only used when outline is true rounded: false, radius: 0.5, # only used when rounded is true segments: 8, # only used when rounded is true colour: BLACK ) if rounded unless (0..1).include?(radius) raise ArgumentError, "Radius must fall between 0 and 1, you gave me #{radius}" end if outline draw_rectangle_rounded_lines(self, radius, segments, thickness, colour) else draw_rectangle_rounded(self, radius, segments, colour) end else if outline draw_rectangle_lines_ex(self, thickness, colour) else draw_rectangle_pro(self, origin, rotation, colour) end end end |
#to_h ⇒ Hash
Return the object represented by a Hash
8 9 10 11 12 13 14 15 |
# File 'src/ruby/models/rectangle.rb', line 8 def to_h { x: x, y: y, width: width, height: height, } end |