vedeu 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/LICENSE.txt +5 -0
- data/bin/vedeu +3 -1
- data/docs/api.md +2 -0
- data/examples/cursor_app/cursor_app.rb +22 -7
- data/examples/hello_world.rb +42 -0
- data/lib/vedeu.rb +5 -5
- data/lib/vedeu/api/api.rb +16 -33
- data/lib/vedeu/api/helpers.rb +86 -0
- data/lib/vedeu/api/interface.rb +60 -17
- data/lib/vedeu/api/keymap.rb +5 -0
- data/lib/vedeu/api/line.rb +52 -34
- data/lib/vedeu/api/menu.rb +1 -1
- data/lib/vedeu/api/stream.rb +0 -34
- data/lib/vedeu/configuration/api.rb +10 -10
- data/lib/vedeu/configuration/cli.rb +1 -1
- data/lib/vedeu/launcher.rb +21 -6
- data/lib/vedeu/models/background.rb +1 -1
- data/lib/vedeu/models/composition.rb +1 -1
- data/lib/vedeu/models/cursor.rb +25 -35
- data/lib/vedeu/models/foreground.rb +1 -1
- data/lib/vedeu/models/geometry.rb +216 -6
- data/lib/vedeu/models/interface.rb +14 -16
- data/lib/vedeu/models/keymap.rb +38 -6
- data/lib/vedeu/models/line.rb +1 -1
- data/lib/vedeu/models/stream.rb +1 -1
- data/lib/vedeu/output/compositor.rb +1 -1
- data/lib/vedeu/output/render.rb +1 -5
- data/lib/vedeu/output/viewport.rb +37 -2
- data/lib/vedeu/repositories/buffers.rb +21 -27
- data/lib/vedeu/repositories/cursors.rb +3 -15
- data/lib/vedeu/repositories/focus.rb +2 -6
- data/lib/vedeu/repositories/groups.rb +1 -1
- data/lib/vedeu/repositories/interfaces.rb +1 -1
- data/lib/vedeu/repositories/keymaps.rb +26 -22
- data/lib/vedeu/repositories/menus.rb +1 -1
- data/lib/vedeu/repositories/offsets.rb +30 -12
- data/lib/vedeu/repositories/positional.rb +23 -0
- data/lib/vedeu/support/colour_translator.rb +1 -16
- data/lib/vedeu/support/esc.rb +23 -28
- data/lib/vedeu/support/event.rb +6 -14
- data/lib/vedeu/{output → support}/refresh.rb +0 -0
- data/lib/vedeu/support/registrar.rb +6 -14
- data/lib/vedeu/support/repository.rb +3 -2
- data/lib/vedeu/support/terminal.rb +9 -13
- data/lib/vedeu/support/trace.rb +2 -3
- data/test/integration/cursors_test.rb +9 -0
- data/test/integration/views/basic_view_test.rb +19 -0
- data/test/lib/vedeu/api/api_test.rb +28 -5
- data/test/lib/vedeu/api/composition_test.rb +7 -3
- data/test/lib/vedeu/api/defined_test.rb +9 -3
- data/test/lib/vedeu/api/helpers_test.rb +39 -5
- data/test/lib/vedeu/api/interface_test.rb +88 -8
- data/test/lib/vedeu/api/keymap_test.rb +5 -3
- data/test/lib/vedeu/api/line_test.rb +9 -3
- data/test/lib/vedeu/api/menu_test.rb +11 -7
- data/test/lib/vedeu/api/stream_test.rb +9 -31
- data/test/lib/vedeu/application_test.rb +25 -2
- data/test/lib/vedeu/configuration/api_test.rb +5 -3
- data/test/lib/vedeu/configuration/cli_test.rb +5 -3
- data/test/lib/vedeu/configuration/configuration_test.rb +5 -2
- data/test/lib/vedeu/input/input_test.rb +5 -2
- data/test/lib/vedeu/launcher_test.rb +37 -2
- data/test/lib/vedeu/models/background_test.rb +6 -2
- data/test/lib/vedeu/models/char_test.rb +9 -6
- data/test/lib/vedeu/models/colour_test.rb +6 -2
- data/test/lib/vedeu/models/composition_test.rb +4 -2
- data/test/lib/vedeu/models/cursor_test.rb +27 -16
- data/test/lib/vedeu/models/foreground_test.rb +6 -2
- data/test/lib/vedeu/models/geometry_test.rb +6 -2
- data/test/lib/vedeu/models/interface_test.rb +5 -2
- data/test/lib/vedeu/models/keymap_test.rb +6 -4
- data/test/lib/vedeu/models/line_test.rb +5 -2
- data/test/lib/vedeu/models/offset_test.rb +7 -3
- data/test/lib/vedeu/models/stream_test.rb +4 -2
- data/test/lib/vedeu/models/style_test.rb +5 -2
- data/test/lib/vedeu/output/clear_test.rb +6 -2
- data/test/lib/vedeu/output/compositor_test.rb +8 -4
- data/test/lib/vedeu/output/render_test.rb +9 -6
- data/test/lib/vedeu/output/view_test.rb +7 -3
- data/test/lib/vedeu/output/viewport_test.rb +42 -9
- data/test/lib/vedeu/repositories/buffers_test.rb +52 -12
- data/test/lib/vedeu/repositories/cursors_test.rb +4 -26
- data/test/lib/vedeu/repositories/events_test.rb +6 -2
- data/test/lib/vedeu/repositories/focus_test.rb +5 -2
- data/test/lib/vedeu/repositories/groups_test.rb +5 -2
- data/test/lib/vedeu/repositories/interfaces_test.rb +4 -2
- data/test/lib/vedeu/repositories/keymaps_test.rb +8 -2
- data/test/lib/vedeu/repositories/menus_test.rb +3 -2
- data/test/lib/vedeu/repositories/offsets_test.rb +26 -19
- data/test/lib/vedeu/repositories/positional_test.rb +50 -0
- data/test/lib/vedeu/support/coercions_test.rb +7 -3
- data/test/lib/vedeu/support/colour_translator_test.rb +6 -2
- data/test/lib/vedeu/support/common_test.rb +5 -3
- data/test/lib/vedeu/support/esc_test.rb +6 -2
- data/test/lib/vedeu/support/event_test.rb +6 -2
- data/test/lib/vedeu/support/grid_test.rb +9 -3
- data/test/lib/vedeu/support/keymap_validator_test.rb +5 -2
- data/test/lib/vedeu/support/log_test.rb +4 -2
- data/test/lib/vedeu/support/menu_test.rb +10 -2
- data/test/lib/vedeu/support/position_test.rb +10 -2
- data/test/lib/vedeu/support/presentation_test.rb +6 -3
- data/test/lib/vedeu/{output → support}/refresh_test.rb +6 -2
- data/test/lib/vedeu/support/registrar_test.rb +2 -2
- data/test/lib/vedeu/support/repository_test.rb +4 -3
- data/test/lib/vedeu/support/terminal_test.rb +6 -2
- data/test/lib/vedeu/support/trace_test.rb +17 -2
- data/test/lib/vedeu_test.rb +1 -1
- data/vedeu.gemspec +2 -2
- metadata +13 -13
- data/lib/vedeu/output/area.rb +0 -284
- data/lib/vedeu/support/move.rb +0 -50
- data/test/lib/vedeu/output/area_test.rb +0 -242
- data/test/lib/vedeu/support/move_test.rb +0 -35
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Vedeu
|
4
|
+
|
4
5
|
describe Terminal do
|
6
|
+
|
5
7
|
let(:console) { IO.console }
|
6
8
|
|
7
9
|
describe '.open' do
|
@@ -165,5 +167,7 @@ module Vedeu
|
|
165
167
|
Terminal.console.must_equal(console)
|
166
168
|
end
|
167
169
|
end
|
168
|
-
|
169
|
-
end
|
170
|
+
|
171
|
+
end # Terminal
|
172
|
+
|
173
|
+
end # Vedeu
|
@@ -1,6 +1,21 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Vedeu
|
4
|
+
|
4
5
|
describe Trace do
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
describe '.call' do
|
8
|
+
it { skip }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
it { skip }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#trace' do
|
16
|
+
it { skip }
|
17
|
+
end
|
18
|
+
|
19
|
+
end # Trace
|
20
|
+
|
21
|
+
end # Vedeu
|
data/test/lib/vedeu_test.rb
CHANGED
data/vedeu.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'vedeu'
|
7
|
-
spec.version = '0.2.
|
7
|
+
spec.version = '0.2.5'
|
8
8
|
spec.authors = ['Gavin Laking']
|
9
9
|
spec.email = ['gavinlaking@gmail.com']
|
10
10
|
spec.summary = %q{A terminal case of wonderland.}
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'guard-bundler', '2.0.0'
|
23
23
|
spec.add_development_dependency 'guard-minitest', '2.3.2'
|
24
24
|
spec.add_development_dependency 'minitest', '5.4.2'
|
25
|
-
spec.add_development_dependency 'minitest-reporters', '1.0.
|
25
|
+
spec.add_development_dependency 'minitest-reporters', '1.0.6'
|
26
26
|
spec.add_development_dependency 'mocha', '1.1.0'
|
27
27
|
spec.add_development_dependency 'pry', '0.10.1'
|
28
28
|
spec.add_development_dependency 'rake', '10.3.2'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vedeu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Laking
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.0.
|
89
|
+
version: 1.0.6
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.0.
|
96
|
+
version: 1.0.6
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: mocha
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- docs/events.md
|
188
188
|
- docs/getting_started.md
|
189
189
|
- examples/cursor_app/cursor_app.rb
|
190
|
+
- examples/hello_world.rb
|
190
191
|
- examples/lines_app/lines_app.rb
|
191
192
|
- lib/vedeu.rb
|
192
193
|
- lib/vedeu/api/api.rb
|
@@ -217,10 +218,8 @@ files:
|
|
217
218
|
- lib/vedeu/models/offset.rb
|
218
219
|
- lib/vedeu/models/stream.rb
|
219
220
|
- lib/vedeu/models/style.rb
|
220
|
-
- lib/vedeu/output/area.rb
|
221
221
|
- lib/vedeu/output/clear.rb
|
222
222
|
- lib/vedeu/output/compositor.rb
|
223
|
-
- lib/vedeu/output/refresh.rb
|
224
223
|
- lib/vedeu/output/render.rb
|
225
224
|
- lib/vedeu/output/view.rb
|
226
225
|
- lib/vedeu/output/viewport.rb
|
@@ -233,6 +232,7 @@ files:
|
|
233
232
|
- lib/vedeu/repositories/keymaps.rb
|
234
233
|
- lib/vedeu/repositories/menus.rb
|
235
234
|
- lib/vedeu/repositories/offsets.rb
|
235
|
+
- lib/vedeu/repositories/positional.rb
|
236
236
|
- lib/vedeu/support/coercions.rb
|
237
237
|
- lib/vedeu/support/colour_translator.rb
|
238
238
|
- lib/vedeu/support/common.rb
|
@@ -243,14 +243,15 @@ files:
|
|
243
243
|
- lib/vedeu/support/keymap_validator.rb
|
244
244
|
- lib/vedeu/support/log.rb
|
245
245
|
- lib/vedeu/support/menu.rb
|
246
|
-
- lib/vedeu/support/move.rb
|
247
246
|
- lib/vedeu/support/position.rb
|
248
247
|
- lib/vedeu/support/presentation.rb
|
248
|
+
- lib/vedeu/support/refresh.rb
|
249
249
|
- lib/vedeu/support/registrar.rb
|
250
250
|
- lib/vedeu/support/repository.rb
|
251
251
|
- lib/vedeu/support/terminal.rb
|
252
252
|
- lib/vedeu/support/trace.rb
|
253
253
|
- logs/.gitkeep
|
254
|
+
- test/integration/cursors_test.rb
|
254
255
|
- test/integration/defining_interfaces_test.rb
|
255
256
|
- test/integration/run_once_test.rb
|
256
257
|
- test/integration/views/basic_view_test.rb
|
@@ -282,10 +283,8 @@ files:
|
|
282
283
|
- test/lib/vedeu/models/offset_test.rb
|
283
284
|
- test/lib/vedeu/models/stream_test.rb
|
284
285
|
- test/lib/vedeu/models/style_test.rb
|
285
|
-
- test/lib/vedeu/output/area_test.rb
|
286
286
|
- test/lib/vedeu/output/clear_test.rb
|
287
287
|
- test/lib/vedeu/output/compositor_test.rb
|
288
|
-
- test/lib/vedeu/output/refresh_test.rb
|
289
288
|
- test/lib/vedeu/output/render_test.rb
|
290
289
|
- test/lib/vedeu/output/view_test.rb
|
291
290
|
- test/lib/vedeu/output/viewport_test.rb
|
@@ -298,6 +297,7 @@ files:
|
|
298
297
|
- test/lib/vedeu/repositories/keymaps_test.rb
|
299
298
|
- test/lib/vedeu/repositories/menus_test.rb
|
300
299
|
- test/lib/vedeu/repositories/offsets_test.rb
|
300
|
+
- test/lib/vedeu/repositories/positional_test.rb
|
301
301
|
- test/lib/vedeu/support/coercions_test.rb
|
302
302
|
- test/lib/vedeu/support/colour_translator_test.rb
|
303
303
|
- test/lib/vedeu/support/common_test.rb
|
@@ -307,9 +307,9 @@ files:
|
|
307
307
|
- test/lib/vedeu/support/keymap_validator_test.rb
|
308
308
|
- test/lib/vedeu/support/log_test.rb
|
309
309
|
- test/lib/vedeu/support/menu_test.rb
|
310
|
-
- test/lib/vedeu/support/move_test.rb
|
311
310
|
- test/lib/vedeu/support/position_test.rb
|
312
311
|
- test/lib/vedeu/support/presentation_test.rb
|
312
|
+
- test/lib/vedeu/support/refresh_test.rb
|
313
313
|
- test/lib/vedeu/support/registrar_test.rb
|
314
314
|
- test/lib/vedeu/support/repository_test.rb
|
315
315
|
- test/lib/vedeu/support/terminal_test.rb
|
@@ -344,6 +344,7 @@ signing_key:
|
|
344
344
|
specification_version: 4
|
345
345
|
summary: A terminal case of wonderland.
|
346
346
|
test_files:
|
347
|
+
- test/integration/cursors_test.rb
|
347
348
|
- test/integration/defining_interfaces_test.rb
|
348
349
|
- test/integration/run_once_test.rb
|
349
350
|
- test/integration/views/basic_view_test.rb
|
@@ -375,10 +376,8 @@ test_files:
|
|
375
376
|
- test/lib/vedeu/models/offset_test.rb
|
376
377
|
- test/lib/vedeu/models/stream_test.rb
|
377
378
|
- test/lib/vedeu/models/style_test.rb
|
378
|
-
- test/lib/vedeu/output/area_test.rb
|
379
379
|
- test/lib/vedeu/output/clear_test.rb
|
380
380
|
- test/lib/vedeu/output/compositor_test.rb
|
381
|
-
- test/lib/vedeu/output/refresh_test.rb
|
382
381
|
- test/lib/vedeu/output/render_test.rb
|
383
382
|
- test/lib/vedeu/output/view_test.rb
|
384
383
|
- test/lib/vedeu/output/viewport_test.rb
|
@@ -391,6 +390,7 @@ test_files:
|
|
391
390
|
- test/lib/vedeu/repositories/keymaps_test.rb
|
392
391
|
- test/lib/vedeu/repositories/menus_test.rb
|
393
392
|
- test/lib/vedeu/repositories/offsets_test.rb
|
393
|
+
- test/lib/vedeu/repositories/positional_test.rb
|
394
394
|
- test/lib/vedeu/support/coercions_test.rb
|
395
395
|
- test/lib/vedeu/support/colour_translator_test.rb
|
396
396
|
- test/lib/vedeu/support/common_test.rb
|
@@ -400,9 +400,9 @@ test_files:
|
|
400
400
|
- test/lib/vedeu/support/keymap_validator_test.rb
|
401
401
|
- test/lib/vedeu/support/log_test.rb
|
402
402
|
- test/lib/vedeu/support/menu_test.rb
|
403
|
-
- test/lib/vedeu/support/move_test.rb
|
404
403
|
- test/lib/vedeu/support/position_test.rb
|
405
404
|
- test/lib/vedeu/support/presentation_test.rb
|
405
|
+
- test/lib/vedeu/support/refresh_test.rb
|
406
406
|
- test/lib/vedeu/support/registrar_test.rb
|
407
407
|
- test/lib/vedeu/support/repository_test.rb
|
408
408
|
- test/lib/vedeu/support/terminal_test.rb
|
data/lib/vedeu/output/area.rb
DELETED
@@ -1,284 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
# Provides a collection of methods useful in calculating geometries for
|
4
|
-
# interfaces, cursors and viewports.
|
5
|
-
#
|
6
|
-
class Area
|
7
|
-
|
8
|
-
attr_reader :attributes, :height, :x_min, :y_min, :width, :x, :y
|
9
|
-
|
10
|
-
# Returns an instance of Area.
|
11
|
-
#
|
12
|
-
# @param interface [Interface]
|
13
|
-
# @return [Area]
|
14
|
-
def self.from_interface(interface)
|
15
|
-
new({
|
16
|
-
y_min: interface.top,
|
17
|
-
height: interface.height,
|
18
|
-
x_min: interface.left,
|
19
|
-
width: interface.width
|
20
|
-
})
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns an instance of Area.
|
24
|
-
#
|
25
|
-
# @param attributes [Hash] The attributes to initialize this class with.
|
26
|
-
# @option attributes :y_min [Fixnum] The starting y coordinate for the area,
|
27
|
-
# equivalent to +:top+ in {Geometry} parlance.
|
28
|
-
# @option attributes :height [Fixnum] The number of rows or lines to use.
|
29
|
-
# @option attributes :x_min [Fixnum] The starting x coordinate for the area,
|
30
|
-
# equivalent to +:left+ in {Geometry} parlance.
|
31
|
-
# @option attributes :width [Fixnum] The number of characters or columns to
|
32
|
-
# use.
|
33
|
-
# @option attributes :y [Fixnum] A coordinate in the area. This value should
|
34
|
-
# be an actual terminal coordinate.
|
35
|
-
# @option attributes :x [Fixnum] A coordinate in the area. This value should
|
36
|
-
# be an actual terminal coordinate.
|
37
|
-
#
|
38
|
-
# @return [Area]
|
39
|
-
def initialize(attributes = {})
|
40
|
-
@attributes = defaults.merge!(attributes)
|
41
|
-
|
42
|
-
@y_min = @attributes.fetch(:y_min)
|
43
|
-
@height = @attributes.fetch(:height)
|
44
|
-
|
45
|
-
@x_min = @attributes.fetch(:x_min)
|
46
|
-
@width = @attributes.fetch(:width)
|
47
|
-
|
48
|
-
@y = @attributes.fetch(:y)
|
49
|
-
@x = @attributes.fetch(:x)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns the same as #y_range, except as indices of an array.
|
53
|
-
#
|
54
|
-
# @example
|
55
|
-
# # height = 4
|
56
|
-
# y_indices # => [0, 1, 2, 3]
|
57
|
-
#
|
58
|
-
# @return [Array]
|
59
|
-
def y_indices
|
60
|
-
(0...height).to_a
|
61
|
-
end
|
62
|
-
|
63
|
-
# Returns the same as #x_range, except as indices of an array.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# # width = 10
|
67
|
-
# x_indices # => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
68
|
-
#
|
69
|
-
# @return [Array]
|
70
|
-
def x_indices
|
71
|
-
(0...width).to_a
|
72
|
-
end
|
73
|
-
|
74
|
-
# Returns the maximum y coordinate for an area.
|
75
|
-
#
|
76
|
-
# @example
|
77
|
-
# # y_min = 2
|
78
|
-
# # height = 4
|
79
|
-
# y_max # => 6
|
80
|
-
#
|
81
|
-
# @return [Fixnum]
|
82
|
-
def y_max
|
83
|
-
if height <= 0
|
84
|
-
0
|
85
|
-
|
86
|
-
else
|
87
|
-
y_min + height
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Returns the maximum x coordinate for an area.
|
93
|
-
#
|
94
|
-
# @example
|
95
|
-
# # x_min = 5
|
96
|
-
# # width = 20
|
97
|
-
# x_max # => 25
|
98
|
-
#
|
99
|
-
# @return [Fixnum]
|
100
|
-
def x_max
|
101
|
-
if width <= 0
|
102
|
-
0
|
103
|
-
|
104
|
-
else
|
105
|
-
x_min + width
|
106
|
-
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# Returns the maximum y index for an area.
|
111
|
-
#
|
112
|
-
# @example
|
113
|
-
# # height = 3
|
114
|
-
# y_max_index # => 2
|
115
|
-
#
|
116
|
-
# @return [Fixnum]
|
117
|
-
def y_max_index
|
118
|
-
return 0 if y_indices.empty?
|
119
|
-
|
120
|
-
y_indices.last
|
121
|
-
end
|
122
|
-
|
123
|
-
# Returns the maximum x index for an area.
|
124
|
-
#
|
125
|
-
# @example
|
126
|
-
# # width = 6
|
127
|
-
# x_max_index # => 5
|
128
|
-
#
|
129
|
-
# @return [Fixnum]
|
130
|
-
def x_max_index
|
131
|
-
return 0 if x_indices.empty?
|
132
|
-
|
133
|
-
x_indices.last
|
134
|
-
end
|
135
|
-
|
136
|
-
# Returns the y coordinate as an offset index in the area's y range. When a
|
137
|
-
# value is provided, the y coordinate is overridden. Crudely corrects out of
|
138
|
-
# range values.
|
139
|
-
#
|
140
|
-
# @example
|
141
|
-
# # y_range = [7, 8, 9, 10]
|
142
|
-
# # y = 8
|
143
|
-
# y_index # => 1
|
144
|
-
# y_index(10) # => 3
|
145
|
-
# y_index(5) # => 0
|
146
|
-
# y_index(15) # => 3
|
147
|
-
#
|
148
|
-
# @param value [Fixnum]
|
149
|
-
# @return [Fixnum]
|
150
|
-
def y_index(value = y)
|
151
|
-
if height <= 0 || value <= y_min
|
152
|
-
0
|
153
|
-
|
154
|
-
elsif value >= y_max
|
155
|
-
y_max_index
|
156
|
-
|
157
|
-
else
|
158
|
-
y_range.index(value)
|
159
|
-
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# Returns the x coordinate as an offset index in the area's x range. When a
|
164
|
-
# value is provided, the x coordinate is overridden. Crudely corrects out of
|
165
|
-
# range values.
|
166
|
-
#
|
167
|
-
# @example
|
168
|
-
# # x_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
169
|
-
# # x = 8
|
170
|
-
# x_index # => 4
|
171
|
-
# x_index(11) # => 7
|
172
|
-
# x_index(2) # => 0
|
173
|
-
# x_index(15) # => 9
|
174
|
-
#
|
175
|
-
# @param value [Fixnum]
|
176
|
-
# @return [Fixnum]
|
177
|
-
def x_index(value = x)
|
178
|
-
if width <= 0 || value <= x_min
|
179
|
-
0
|
180
|
-
|
181
|
-
elsif value >= x_max
|
182
|
-
x_max_index
|
183
|
-
|
184
|
-
else
|
185
|
-
x_range.index(value)
|
186
|
-
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
# Returns the actual position of y for a given index. Crudely corrects out
|
191
|
-
# of range values.
|
192
|
-
#
|
193
|
-
# @example
|
194
|
-
# # y_range = [7, 8, 9, 10, 11]
|
195
|
-
# y_position # => 7
|
196
|
-
# y_position(-2) # => 7
|
197
|
-
# y_position(2) # => 9
|
198
|
-
# y_position(7) # => 11
|
199
|
-
#
|
200
|
-
# @param index [Fixnum]
|
201
|
-
# @return [Fixnum]
|
202
|
-
def y_position(index = 0)
|
203
|
-
if index <= 0
|
204
|
-
y_min
|
205
|
-
|
206
|
-
elsif index >= y_max_index
|
207
|
-
y_max
|
208
|
-
|
209
|
-
else
|
210
|
-
y_range[index]
|
211
|
-
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
# Returns the actual position of x for a given index. Crudely corrects out
|
216
|
-
# of range values.
|
217
|
-
#
|
218
|
-
# @example
|
219
|
-
# # x_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
220
|
-
# x_position # => 4
|
221
|
-
# x_position(-2) # => 4
|
222
|
-
# x_position(2) # => 6
|
223
|
-
# x_position(15) # => 13
|
224
|
-
#
|
225
|
-
# @param index [Fixnum]
|
226
|
-
# @return [Fixnum]
|
227
|
-
def x_position(index = 0)
|
228
|
-
if index <= 0
|
229
|
-
x_min
|
230
|
-
|
231
|
-
elsif index >= x_max_index
|
232
|
-
x_max
|
233
|
-
|
234
|
-
else
|
235
|
-
x_range[index]
|
236
|
-
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
# Returns an array with all coordinates from x to x_max.
|
241
|
-
#
|
242
|
-
# @example
|
243
|
-
# # width = 10
|
244
|
-
# # x_min = 4
|
245
|
-
# # x_max = 14
|
246
|
-
# x_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
247
|
-
#
|
248
|
-
# @return [Array]
|
249
|
-
def x_range
|
250
|
-
(x_min...x_max).to_a
|
251
|
-
end
|
252
|
-
|
253
|
-
# Returns an array with all coordinates from y to y_max.
|
254
|
-
#
|
255
|
-
# @example
|
256
|
-
# # height = 4
|
257
|
-
# # y_min = 7
|
258
|
-
# # y_max = 11
|
259
|
-
# y_range # => [7, 8, 9, 10]
|
260
|
-
#
|
261
|
-
# @return [Array]
|
262
|
-
def y_range
|
263
|
-
(y_min...y_max).to_a
|
264
|
-
end
|
265
|
-
|
266
|
-
private
|
267
|
-
|
268
|
-
# Returns the default attributes for an Area instance.
|
269
|
-
#
|
270
|
-
# @return [Hash]
|
271
|
-
def defaults
|
272
|
-
{
|
273
|
-
height: 0,
|
274
|
-
x_min: 0,
|
275
|
-
y_min: 0,
|
276
|
-
width: 0,
|
277
|
-
x: 0,
|
278
|
-
y: 0,
|
279
|
-
}
|
280
|
-
end
|
281
|
-
|
282
|
-
end # Area
|
283
|
-
|
284
|
-
end # Vedeu
|