class StandardDrawTk::Coordinates

Constants

BORDER
DEFAULT_MAX
DEFAULT_MIN
DEFAULT_SIZE

Attributes

height[R]
width[R]

Public Class Methods

new() click to toggle source
# File lib/coordinates.rb, line 9
def initialize
  @height = @width = DEFAULT_SIZE
  @xmin = @ymin = DEFAULT_MIN
  @xmax = @ymax = DEFAULT_MAX
end

Public Instance Methods

box(x, y, r) click to toggle source
# File lib/coordinates.rb, line 44
def box(x, y, r)
  [x - r, y - r, x + r, y + r]
end
factor_x(w) click to toggle source
# File lib/coordinates.rb, line 28
def factor_x(w)
  w * @width  / (@xmax - @xmin).abs
end
factor_y(h) click to toggle source
# File lib/coordinates.rb, line 32
def factor_y(h)
  h * @height / (@ymax - @ymin).abs
end
init() click to toggle source
# File lib/coordinates.rb, line 15
def init
  set_xscale(DEFAULT_XMIN, DEFAULT_XMAX)
  set_yscale(DEFAULT_YMIN, DEFAULT_YMAX)
end
scale_x(x) click to toggle source
# File lib/coordinates.rb, line 20
def scale_x(x)
  @width  * (x - @xmin) / (@xmax - @xmin)
end
scale_y(y) click to toggle source
# File lib/coordinates.rb, line 24
def scale_y(y)
  @height * (@ymax - y) / (@ymax - @ymin)
end
set_xscale(min, max) click to toggle source
# File lib/coordinates.rb, line 48
def set_xscale(min, max)
  size = max - min
  throw 'the min and max are the same' if size == 0.0
  @xmin = min - BORDER * size
  @xmax = max + BORDER * size
end
set_yscale(min, max) click to toggle source
# File lib/coordinates.rb, line 55
def set_yscale(min, max)
  size = max - min
  throw 'the min and max are the same' if size == 0.0
  @ymin = min - BORDER * size
  @ymax = max + BORDER * size
end
user_x(x) click to toggle source
# File lib/coordinates.rb, line 36
def user_x(x)
  @xmin + x * (@xmax - @xmin) / @width
end
user_y(y) click to toggle source
# File lib/coordinates.rb, line 40
def user_y(y)
  @ymax - y * (@ymax - @ymin) / @height
end