rhex 2.0.2 → 2.0.3
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/lib/hex/axial_grid.rb +12 -31
- data/lib/hex/axial_hex.rb +9 -0
- data/lib/hex/modules/grid_to_pic.rb +21 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d90bcb5012b56d62255885e20da656a2b6be751
|
|
4
|
+
data.tar.gz: b2e452c8f88b2157229e31d2e9d8cf8ef6c6625e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f8a15e4917422316690266295573c076ab615c88051af523b5026dc7f0641825e49872966406636f431a0040bcdbba5631c9deb55ff59b64656d82f7288a656
|
|
7
|
+
data.tar.gz: cab8437bf7021c059691908bed06d8ecd2d3b812c10cb39bbf98caf0cfb9d2c31c4b72df198e649daab80d72b8b2ec0b2fd24efbfe4e3f9b4399373ff4495513
|
data/lib/hex/axial_grid.rb
CHANGED
|
@@ -100,37 +100,18 @@ class AxialGrid
|
|
|
100
100
|
h.surrounding_hexes.map{ |sh| hget( sh ) }
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
# @
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
#
|
|
118
|
-
# Get the (x, y) position of an hexagon object
|
|
119
|
-
#
|
|
120
|
-
# @param hex [AxialHex] the hexagon you want to get the position
|
|
121
|
-
#
|
|
122
|
-
# @return [Array<Integer>] an array of two integers corrsponding respectively to the x, y values
|
|
123
|
-
#
|
|
124
|
-
def to_xy( hex )
|
|
125
|
-
|
|
126
|
-
tmp_q = hex.q
|
|
127
|
-
# x = ( @hex_ray * Math.sqrt(3) * ( tmp_q + hex.r/2.0 ) ) - @hex_width
|
|
128
|
-
# y = ( @hex_ray * 3.0/2.0 * hex.r ) - ( @quarter_height * 2 )
|
|
129
|
-
|
|
130
|
-
x = ( @hex_ray * Math.sqrt(3) * ( tmp_q + hex.r/2.0 ) )
|
|
131
|
-
y = ( @hex_ray * 3.0/2.0 * hex.r ) - ( @quarter_height * 2 )
|
|
132
|
-
|
|
133
|
-
[ x, y ]
|
|
103
|
+
# Return the grid as a hash object
|
|
104
|
+
#
|
|
105
|
+
# @return [Hash] the grid as a hash object
|
|
106
|
+
def to_hash
|
|
107
|
+
h = @hexes.clone
|
|
108
|
+
# p hash
|
|
109
|
+
h.each do |k, v|
|
|
110
|
+
# p k
|
|
111
|
+
h[ k ] = v.to_hash
|
|
112
|
+
end
|
|
113
|
+
# p h
|
|
114
|
+
h
|
|
134
115
|
end
|
|
135
116
|
|
|
136
117
|
end
|
data/lib/hex/axial_hex.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
3
5
|
require_relative 'cube_hex'
|
|
4
6
|
|
|
5
7
|
# This class represents an hexagon stored in axial coordinate system.
|
|
@@ -135,4 +137,11 @@ class AxialHex < BaseHex
|
|
|
135
137
|
[ q, r ]
|
|
136
138
|
end
|
|
137
139
|
|
|
140
|
+
# Return an hex as a hash object
|
|
141
|
+
#
|
|
142
|
+
# @return [Hash] the hex as a hash object
|
|
143
|
+
def to_hash
|
|
144
|
+
{ q: @q, r: @r, color: @color, border: @border, data: @data.to_hash }
|
|
145
|
+
end
|
|
146
|
+
|
|
138
147
|
end
|
|
@@ -22,8 +22,8 @@ module GridToPic
|
|
|
22
22
|
exit if exit_on_error
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
maxx = ( @hexes.keys.map{ |k| k[0] + k[1]/2 }.max ) * @hex_width
|
|
26
|
-
maxy = @hexes.keys.map{ |k| k[1] }.max * ( ( @hex_height * 3.0 )/ 4.0 ).ceil
|
|
25
|
+
maxx = ( @hexes.keys.map{ |k| k[0] + k[1]/2 }.max ) * @hex_width + ( @hex_width + @half_width + 1 )
|
|
26
|
+
maxy = @hexes.keys.map{ |k| k[1] }.max * ( ( @hex_height * 3.0 )/ 4.0 ).ceil + ( @hex_height + 1 )
|
|
27
27
|
|
|
28
28
|
# maxx = ( ( @hexes.keys.map{ |k| k[0] + k[1]/2 }.max ) + 0.5 ) * @hex_width
|
|
29
29
|
# maxy = ( ( @hexes.keys.map{ |k| k[1] }.max * 3.0/4.0 ) + 0.5 ) + @hex_heig
|
|
@@ -54,17 +54,32 @@ module GridToPic
|
|
|
54
54
|
canvas.write( pic_name )
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# Get the (x, y) position of an hexagon object
|
|
58
|
+
#
|
|
59
|
+
# @param hex [AxialHex] the hexagon you want to get the position
|
|
60
|
+
#
|
|
61
|
+
# @return [Array<Integer>] an array of two integers corrsponding respectively to the x, y values
|
|
62
|
+
#
|
|
63
|
+
def to_xy( hex )
|
|
64
|
+
x = ( @hex_ray * Math.sqrt(3) * ( hex.q + hex.r/2.0 ) )
|
|
65
|
+
y = ( @hex_ray * 3.0/2.0 * hex.r )
|
|
66
|
+
|
|
67
|
+
x += @half_width
|
|
68
|
+
y += @half_height
|
|
69
|
+
|
|
70
|
+
[ x, y ]
|
|
71
|
+
end
|
|
72
|
+
|
|
57
73
|
private
|
|
58
74
|
|
|
59
75
|
def set_hex_dimensions
|
|
60
76
|
|
|
61
|
-
# p :call
|
|
62
|
-
|
|
63
77
|
@hex_height = @hex_ray * 2.0
|
|
64
|
-
@
|
|
78
|
+
@half_height = @hex_ray
|
|
79
|
+
@quarter_height = @hex_height / 4.0
|
|
65
80
|
|
|
81
|
+
@hex_width = Math.sqrt(3)/2.0 * @hex_height
|
|
66
82
|
@half_width = @hex_width / 2.0
|
|
67
|
-
@quarter_height = @hex_height / 4.0
|
|
68
83
|
|
|
69
84
|
end
|
|
70
85
|
|