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.
Instance Attribute Summary collapse
- #colour ⇒ Colour
- #height ⇒ Float
- #outline ⇒ Colour
- #roundness ⇒ Float
- #segments ⇒ Integer
- #thickness ⇒ Float
- #width ⇒ Float
- #x ⇒ Float
- #y ⇒ Float
Class Method Summary collapse
-
.[](x, y, width, height, colour = Colour::BLACK) ⇒ Rectangle
Shorthand for initializing a new Rectangle.
Instance Method Summary collapse
- #begin_scissoring ⇒ nil
-
#draw ⇒ nil
Draws the Rectangle.
-
#end_scissoring ⇒ nil
Ends scissoring within the Rectangle.
-
#initialize(x:, y:, width:, height:, colour: Colour::BLACK, outline: nil, thickness: 1, roundness: 0, segments: 4) ⇒ Rectangle
constructor
Creates a new instance of Rectangle.
- #overlaps?(other) ⇒ Boolean
- #scissor(&block) ⇒ nil
-
#to_h ⇒ Hash
Return the Rectangle represented by a Hash.
Constructor Details
#initialize(x:, y:, width:, height:, colour: Colour::BLACK, outline: nil, thickness: 1, roundness: 0, segments: 4) ⇒ Rectangle
Creates a new instance of Rectangle.
27 28 29 30 |
# File 'mrb_doc/models/rectangle.rb', line 27 def initialize(x:, y:, width:, height:, colour: Colour::BLACK, outline: nil, thickness: 1, roundness: 0, segments: 4) # mrb_Rectangle_initialize # src/mruby_integration/models/rectangle.cpp end |
Instance Attribute Details
#height ⇒ Float
3 4 5 |
# File 'mrb_doc/models/rectangle.rb', line 3 def height @height end |
#roundness ⇒ Float
3 4 5 |
# File 'mrb_doc/models/rectangle.rb', line 3 def roundness @roundness end |
#segments ⇒ Integer
6 7 8 |
# File 'mrb_doc/models/rectangle.rb', line 6 def segments @segments end |
#thickness ⇒ Float
3 4 5 |
# File 'mrb_doc/models/rectangle.rb', line 3 def thickness @thickness end |
#width ⇒ Float
3 4 5 |
# File 'mrb_doc/models/rectangle.rb', line 3 def width @width end |
#x ⇒ Float
3 4 5 |
# File 'mrb_doc/models/rectangle.rb', line 3 def x @x end |
#y ⇒ Float
3 4 5 |
# File 'mrb_doc/models/rectangle.rb', line 3 def y @y end |
Class Method Details
Instance Method Details
#begin_scissoring ⇒ nil
72 73 74 75 76 |
# File 'mrb_doc/models/rectangle.rb', line 72 def begin_scissoring # mrb_Rectangle_begin_scissoring # src/mruby_integration/models/rectangle.cpp nil end |
#draw ⇒ nil
53 54 55 56 57 |
# File 'mrb_doc/models/rectangle.rb', line 53 def draw # mrb_Rectangle_draw # src/mruby_integration/models/rectangle.cpp nil end |
#end_scissoring ⇒ nil
Ends scissoring within the Rectangle.
90 91 92 93 94 |
# File 'mrb_doc/models/rectangle.rb', line 90 def end_scissoring # mrb_Rectangle_end_scissoring # src/mruby_integration/models/rectangle.cpp nil end |
#overlaps?(other) ⇒ Boolean
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'src/ruby/models/rectangle.rb', line 136 def overlaps?(other) case other when Vector2 other.x.between?(x, x + width) && other.y.between?(y, y + height) when Rectangle x < (other.x + other.width) && (x + width) > other.x && y < (other.y + other.height) && (y + height) > other.y else raise ArgumentError, "Must pass in a Vector2 or Rectangle" unless other.is_a?(Vector2) end end |
#scissor(&block) ⇒ nil
77 78 79 80 81 82 |
# File 'src/ruby/models/rectangle.rb', line 77 def scissor(&block) begin_scissoring block.call ensure end_scissoring end |
#to_h ⇒ Hash
Return the Rectangle represented by a Hash.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'src/ruby/models/rectangle.rb', line 53 def to_h { x: x, y: y, width: width, height: height, colour: colour.to_h, outline: outline.to_h, thickness: thickness, roundness: roundness, segments: segments } end |