rhex 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89e0d43ab123768693ec204a0cd35d135e6b9d30
4
- data.tar.gz: 04ed10011307c6e8543c1e69c11c6e0f7ce9bafd
3
+ metadata.gz: 8d90bcb5012b56d62255885e20da656a2b6be751
4
+ data.tar.gz: b2e452c8f88b2157229e31d2e9d8cf8ef6c6625e
5
5
  SHA512:
6
- metadata.gz: 745370f83e96bef9357943e9a5006ec1fc2dd0b87702007c0b8ec0388e9082e55d114c47e47f080a3cfa57a0efa1173face5e80ad177e40f70ba8a330744b2b3
7
- data.tar.gz: bf649584d26204efd93770a8c054216d02d8143684d4ea31319307d05df9b19f3aca1cd1c453484c15e0fc39c4bbd5d6248e5f2da169e401f8d99d23c8077e50
6
+ metadata.gz: 8f8a15e4917422316690266295573c076ab615c88051af523b5026dc7f0641825e49872966406636f431a0040bcdbba5631c9deb55ff59b64656d82f7288a656
7
+ data.tar.gz: cab8437bf7021c059691908bed06d8ecd2d3b812c10cb39bbf98caf0cfb9d2c31c4b72df198e649daab80d72b8b2ec0b2fd24efbfe4e3f9b4399373ff4495513
@@ -100,37 +100,18 @@ class AxialGrid
100
100
  h.surrounding_hexes.map{ |sh| hget( sh ) }
101
101
  end
102
102
 
103
- # Get the hexagon at (x,y) coordinate.
104
- #
105
- # @param x [Integer] the x coordinate of the hexagon you want to get
106
- # @param y [Integer] the y coordinate of the hexagon you want to get
107
- #
108
- # @return [AxialGrid] the corresponding hex
109
- #
110
- def hex_at_xy(x, y)
111
- q = (x * Math.sqrt(3)/3.0 - y/3.0) / @hex_ray
112
- r = y * 2.0/3.0 / @hex_ray
113
- hex = AxialHex.new(q, r).round
114
- cget( hex.q, hex.r )
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
@@ -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 - ( @hex_width / 2 ) + 1 + @hex_width
26
- maxy = @hexes.keys.map{ |k| k[1] }.max * ( ( @hex_height * 3.0 )/ 4.0 ).ceil - ( @hex_width / 4 ).ceil - 2
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
- @hex_width = Math.sqrt(3)/2.0 * @hex_height
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric ZUGER