Class: Skia::Rect
- Inherits:
-
Object
- Object
- Skia::Rect
- Defined in:
- lib/skia/rect.rb
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#top ⇒ Object
Returns the value of attribute top.
Class Method Summary collapse
- .from_struct(struct) ⇒ Object
- .from_wh(width, height) ⇒ Object
- .from_xywh(x, y, width, height) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #center ⇒ Object
- #center_x ⇒ Object
- #center_y ⇒ Object
- #contains?(x, y) ⇒ Boolean
- #contains_rect?(other) ⇒ Boolean
- #empty? ⇒ Boolean
- #height ⇒ Object
-
#initialize(left = 0.0, top = 0.0, right = 0.0, bottom = 0.0) ⇒ Rect
constructor
A new instance of Rect.
- #inset(dx, dy) ⇒ Object
- #intersect(other) ⇒ Object
- #intersects?(other) ⇒ Boolean
- #offset(dx, dy) ⇒ Object
- #offset!(dx, dy) ⇒ Object
- #to_a ⇒ Object
- #to_struct ⇒ Object
- #union(other) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(left = 0.0, top = 0.0, right = 0.0, bottom = 0.0) ⇒ Rect
Returns a new instance of Rect.
7 8 9 10 11 12 |
# File 'lib/skia/rect.rb', line 7 def initialize(left = 0.0, top = 0.0, right = 0.0, bottom = 0.0) @left = left.to_f @top = top.to_f @right = right.to_f @bottom = bottom.to_f end |
Instance Attribute Details
#bottom ⇒ Object
Returns the value of attribute bottom.
5 6 7 |
# File 'lib/skia/rect.rb', line 5 def bottom @bottom end |
#left ⇒ Object
Returns the value of attribute left.
5 6 7 |
# File 'lib/skia/rect.rb', line 5 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
5 6 7 |
# File 'lib/skia/rect.rb', line 5 def right @right end |
#top ⇒ Object
Returns the value of attribute top.
5 6 7 |
# File 'lib/skia/rect.rb', line 5 def top @top end |
Class Method Details
.from_struct(struct) ⇒ Object
22 23 24 |
# File 'lib/skia/rect.rb', line 22 def self.from_struct(struct) new(struct[:left], struct[:top], struct[:right], struct[:bottom]) end |
.from_wh(width, height) ⇒ Object
18 19 20 |
# File 'lib/skia/rect.rb', line 18 def self.from_wh(width, height) new(0, 0, width, height) end |
.from_xywh(x, y, width, height) ⇒ Object
14 15 16 |
# File 'lib/skia/rect.rb', line 14 def self.from_xywh(x, y, width, height) new(x, y, x + width, y + height) end |
Instance Method Details
#==(other) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/skia/rect.rb', line 109 def ==(other) return false unless other.is_a?(Rect) @left == other.left && @top == other.top && @right == other.right && @bottom == other.bottom end |
#center ⇒ Object
51 52 53 |
# File 'lib/skia/rect.rb', line 51 def center Point.new(center_x, center_y) end |
#center_x ⇒ Object
43 44 45 |
# File 'lib/skia/rect.rb', line 43 def center_x (@left + @right) / 2.0 end |
#center_y ⇒ Object
47 48 49 |
# File 'lib/skia/rect.rb', line 47 def center_y (@top + @bottom) / 2.0 end |
#contains?(x, y) ⇒ Boolean
59 60 61 |
# File 'lib/skia/rect.rb', line 59 def contains?(x, y) x >= @left && x < @right && y >= @top && y < @bottom end |
#contains_rect?(other) ⇒ Boolean
63 64 65 66 |
# File 'lib/skia/rect.rb', line 63 def contains_rect?(other) @left <= other.left && @top <= other.top && @right >= other.right && @bottom >= other.bottom end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/skia/rect.rb', line 55 def empty? @left >= @right || @top >= @bottom end |
#height ⇒ Object
39 40 41 |
# File 'lib/skia/rect.rb', line 39 def height @bottom - @top end |
#inset(dx, dy) ⇒ Object
105 106 107 |
# File 'lib/skia/rect.rb', line 105 def inset(dx, dy) self.class.new(@left + dx, @top + dy, @right - dx, @bottom - dy) end |
#intersect(other) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/skia/rect.rb', line 73 def intersect(other) return nil unless intersects?(other) self.class.new( [@left, other.left].max, [@top, other.top].min, [@right, other.right].min, [@bottom, other.bottom].max ) end |
#intersects?(other) ⇒ Boolean
68 69 70 71 |
# File 'lib/skia/rect.rb', line 68 def intersects?(other) @left < other.right && other.left < @right && @top < other.bottom && other.top < @bottom end |
#offset(dx, dy) ⇒ Object
93 94 95 |
# File 'lib/skia/rect.rb', line 93 def offset(dx, dy) self.class.new(@left + dx, @top + dy, @right + dx, @bottom + dy) end |
#offset!(dx, dy) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/skia/rect.rb', line 97 def offset!(dx, dy) @left += dx @top += dy @right += dx @bottom += dy self end |
#to_a ⇒ Object
116 117 118 |
# File 'lib/skia/rect.rb', line 116 def to_a [@left, @top, @right, @bottom] end |
#to_struct ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/skia/rect.rb', line 26 def to_struct struct = Native::SKRect.new struct[:left] = @left struct[:top] = @top struct[:right] = @right struct[:bottom] = @bottom struct end |
#union(other) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/skia/rect.rb', line 84 def union(other) self.class.new( [@left, other.left].min, [@top, other.top].min, [@right, other.right].max, [@bottom, other.bottom].max ) end |
#width ⇒ Object
35 36 37 |
# File 'lib/skia/rect.rb', line 35 def width @right - @left end |