diff options
Diffstat (limited to 'common/coords.lua')
-rw-r--r-- | common/coords.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/common/coords.lua b/common/coords.lua index 49c2bf2..420b287 100644 --- a/common/coords.lua +++ b/common/coords.lua @@ -75,6 +75,16 @@ function Hex.offset_in_chunk(self) local cp,offs = self:chunk_and_offset() return offs end +function Hex.iter_neighbours(self,radius) + assert(radius > 0,"radius must be at least 1") + return coroutine.wrap(function() + for q = -radius,radius do + for r = math.max(-radius,-q-radius), math.min(radius,-q+radius) do + coroutine.yield(self+Hex:make(q,r)) + end + end + end) +end function Hex.__add(self,other) return Hex:make(self.q+other.q, self.r+other.r, self.s+other.s) end function Hex.__sub(self,other) return Hex:make(self.q-other.q, self.r-other.r, self.s-other.s) end function Hex.__tostring(self) return string.format("H(%.2f,%.2f)",self.q,self.r) end |