class GerbilCharts::Surfaces::Rect
Rect
¶ ↑
Utility class for manipulations on a rectangle
Attributes
bottom[RW]
left[RW]
right[RW]
top[RW]
Public Class Methods
new()
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 10 def initialize() @left,@top,@right,@bottom=0,0,0,0 end
Public Instance Methods
clip_b(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 45 def clip_b(dim) @top=@bottom-dim end
clip_l(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 53 def clip_l(dim) @right=@left+dim end
clip_r(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 57 def clip_r(dim) @left=@right-dim end
clip_t(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 49 def clip_t(dim) @bottom=@top+dim end
crop_b(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 61 def crop_b(dim) @bottom=@bottom-dim end
crop_l(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 69 def crop_l(dim) @left=@left+dim end
crop_r(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 73 def crop_r(dim) @right=@right-dim end
crop_t(dim)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 65 def crop_t(dim) @top=@top+dim end
deflate(n)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 31 def deflate(n) @left+=n @top+=n @bottom-=n @right-=n end
deflate_h(l,r)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 21 def deflate_h(l,r) @left += l @right -= r end
deflate_v(t,b)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 26 def deflate_v(t,b) @top += t @bottom -= b end
from_wh(w,h)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 14 def from_wh(w,h) @left=0 @right=w @top=0 @bottom=h end
height()
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 81 def height @bottom-@top end
initfrom(r)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 38 def initfrom(r) @left=r.left @right=r.right @top=r.top @bottom=r.bottom end
intersect_point(x,y)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 85 def intersect_point(x,y) x = [ x, @left].max x = [ x, @right].min y = [ y, @top].max y = [ y, @bottom].min return x,y end
offset_x(delta)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 100 def offset_x(delta) @left+=delta @right+=delta end
rand_h(margin=30)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 110 def rand_h(margin=30) rand( (@top-margin)..(@bottom-margin)) end
rand_w(margin=30)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 114 def rand_w(margin=30) rand( (@left-margin)..(@right-margin)) end
to_s()
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 106 def to_s "#{@left},#{@top} [w=#{width} h=#{height}]" end
translate_x(newx)
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 94 def translate_x(newx) w=width @left=newx @right=@left+w end
width()
click to toggle source
# File lib/gerbilcharts/surfaces/rect.rb, line 77 def width @right-@left end