Re:Amit’s Thoughts on Grids
by dxbydt on Thursday August 30, 2012 @06:33PM
(#4457235)
Regarding implementation, he says "All the algorithms are straightforward. How might you implement them? You’ll first want to choose data structures for each of the three coordinate systems. I recommend keeping it very simple and transparent. All the coordinate systems I listed have an integer u and an integer v, and some of them have an annotation like L or W ; in Java use a class with public fields; The next step is to implement the algorithms you need. The simplest thing to do is to write functions (or methods) that take A and return a list of B. "
Atleast in Java ( and therefore in Scala, Clojure etc), the data-structure of choice is a general path, and all of those algorithms have built-in implementations, mostly on Path2D or other concretes. Also, instead of dealing with squares, hexagons & triangles separately... a square is just 2 isosceles triangles, and a hex is 6 equilateral triangles. So if you have a Triangle2D class extending Path2D, you get all of the algorithms and the you can handle all 3 face types. The transformation between cooordinate systems is handled by affine transforms
Atleast in Java ( and therefore in Scala, Clojure etc), the data-structure of choice is a general path, and all of those algorithms have built-in implementations, mostly on Path2D or other concretes. Also, instead of dealing with squares, hexagons & triangles separately... a square is just 2 isosceles triangles, and a hex is 6 equilateral triangles. So if you have a Triangle2D class extending Path2D, you get all of the algorithms and the you can handle all 3 face types. The transformation between cooordinate systems is handled by affine transforms
Path2D: http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Path2...
AffineTransform: http://docs.oracle.com/javase/6/docs/api/java/awt/geom/Affin...