Class: StandardDrawTk::Coordinates
- Inherits:
-
Object
- Object
- StandardDrawTk::Coordinates
- Defined in:
- lib/coordinates.rb
Constant Summary collapse
- BORDER =
0.00
- DEFAULT_MIN =
0.0
- DEFAULT_MAX =
1.0- DEFAULT_SIZE =
512
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #box(x, y, r) ⇒ Object
- #factor_x(w) ⇒ Object
- #factor_y(h) ⇒ Object
- #init ⇒ Object
-
#initialize ⇒ Coordinates
constructor
A new instance of Coordinates.
- #scale_x(x) ⇒ Object
- #scale_y(y) ⇒ Object
- #set_xscale(min, max) ⇒ Object
- #set_yscale(min, max) ⇒ Object
- #user_x(x) ⇒ Object
- #user_y(y) ⇒ Object
Constructor Details
#initialize ⇒ Coordinates
Returns a new instance of Coordinates.
9 10 11 12 13 |
# File 'lib/coordinates.rb', line 9 def initialize @height = @width = DEFAULT_SIZE @xmin = @ymin = DEFAULT_MIN @xmax = @ymax = DEFAULT_MAX end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
7 8 9 |
# File 'lib/coordinates.rb', line 7 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
7 8 9 |
# File 'lib/coordinates.rb', line 7 def width @width end |
Instance Method Details
#box(x, y, r) ⇒ Object
44 45 46 |
# File 'lib/coordinates.rb', line 44 def box(x, y, r) [x - r, y - r, x + r, y + r] end |
#factor_x(w) ⇒ Object
28 29 30 |
# File 'lib/coordinates.rb', line 28 def factor_x(w) w * @width / (@xmax - @xmin).abs end |
#factor_y(h) ⇒ Object
32 33 34 |
# File 'lib/coordinates.rb', line 32 def factor_y(h) h * @height / (@ymax - @ymin).abs end |
#init ⇒ Object
15 16 17 18 |
# File 'lib/coordinates.rb', line 15 def init set_xscale(DEFAULT_XMIN, DEFAULT_XMAX) set_yscale(DEFAULT_YMIN, DEFAULT_YMAX) end |
#scale_x(x) ⇒ Object
20 21 22 |
# File 'lib/coordinates.rb', line 20 def scale_x(x) @width * (x - @xmin) / (@xmax - @xmin) end |
#scale_y(y) ⇒ Object
24 25 26 |
# File 'lib/coordinates.rb', line 24 def scale_y(y) @height * (@ymax - y) / (@ymax - @ymin) end |
#set_xscale(min, max) ⇒ Object
48 49 50 51 52 53 |
# 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) ⇒ Object
55 56 57 58 59 60 |
# 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) ⇒ Object
36 37 38 |
# File 'lib/coordinates.rb', line 36 def user_x(x) @xmin + x * (@xmax - @xmin) / @width end |
#user_y(y) ⇒ Object
40 41 42 |
# File 'lib/coordinates.rb', line 40 def user_y(y) @ymax - y * (@ymax - @ymin) / @height end |