Class: Skia::IRect

Inherits:
Object
  • Object
show all
Defined in:
lib/skia/rect.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left = 0, top = 0, right = 0, bottom = 0) ⇒ IRect

Returns a new instance of IRect.



124
125
126
127
128
129
# File 'lib/skia/rect.rb', line 124

def initialize(left = 0, top = 0, right = 0, bottom = 0)
  @left = left.to_i
  @top = top.to_i
  @right = right.to_i
  @bottom = bottom.to_i
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



122
123
124
# File 'lib/skia/rect.rb', line 122

def bottom
  @bottom
end

#leftObject

Returns the value of attribute left.



122
123
124
# File 'lib/skia/rect.rb', line 122

def left
  @left
end

#rightObject

Returns the value of attribute right.



122
123
124
# File 'lib/skia/rect.rb', line 122

def right
  @right
end

#topObject

Returns the value of attribute top.



122
123
124
# File 'lib/skia/rect.rb', line 122

def top
  @top
end

Class Method Details

.from_struct(struct) ⇒ Object



139
140
141
# File 'lib/skia/rect.rb', line 139

def self.from_struct(struct)
  new(struct[:left], struct[:top], struct[:right], struct[:bottom])
end

.from_wh(width, height) ⇒ Object



135
136
137
# File 'lib/skia/rect.rb', line 135

def self.from_wh(width, height)
  new(0, 0, width, height)
end

.from_xywh(x, y, width, height) ⇒ Object



131
132
133
# File 'lib/skia/rect.rb', line 131

def self.from_xywh(x, y, width, height)
  new(x, y, x + width, y + height)
end

Instance Method Details

#==(other) ⇒ Object



164
165
166
167
168
169
# File 'lib/skia/rect.rb', line 164

def ==(other)
  return false unless other.is_a?(IRect)

  @left == other.left && @top == other.top &&
    @right == other.right && @bottom == other.bottom
end

#empty?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/skia/rect.rb', line 160

def empty?
  @left >= @right || @top >= @bottom
end

#heightObject



156
157
158
# File 'lib/skia/rect.rb', line 156

def height
  @bottom - @top
end

#to_aObject



171
172
173
# File 'lib/skia/rect.rb', line 171

def to_a
  [@left, @top, @right, @bottom]
end

#to_rectObject



175
176
177
# File 'lib/skia/rect.rb', line 175

def to_rect
  Rect.new(@left.to_f, @top.to_f, @right.to_f, @bottom.to_f)
end

#to_structObject



143
144
145
146
147
148
149
150
# File 'lib/skia/rect.rb', line 143

def to_struct
  struct = Native::SKIRect.new
  struct[:left] = @left
  struct[:top] = @top
  struct[:right] = @right
  struct[:bottom] = @bottom
  struct
end

#widthObject



152
153
154
# File 'lib/skia/rect.rb', line 152

def width
  @right - @left
end