2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
11
* Produce iterators for locations of points. It is intended to be
12
* used with a TileCreator, but there is no limitation on this.
14
/*final*/ class TileStructure
21
private function new( type : String, size : Point2, ?units : Point2, times : Int )
29
public function iterator() : Iterator<Point2>
32
return new TSRegular( size, units, false, false );
33
else if( type == "staggeredX" )
34
return new TSRegular( size, units, true, false );
35
else if( type == "staggeredY" )
36
return new TSRegular( size, units, false, true );
37
else if( type == "random" )
38
return new TSRandom( size, times );
44
* Creates a regular grid pattern of points covering the given
45
* size in the given units.
46
* Note that the units may be fractional values; all points within
47
* the given size will be produced in a top-down, left-right fashion
49
static public function grid( size : Point2, units : Point2 ) : TileStructure
51
return new TileStructure( "grid", size, units , 0);
54
static public function staggeredX( size : Point2, units : Point2 ) : TileStructure
56
return new TileStructure( "staggeredX", size, units, 0 );
59
static public function staggeredY( size : Point2, units : Point2 ) : TileStructure
61
return new TileStructure( "staggeredY", size, units, 0 );
64
static public function random( size : Point2, times : Int ) : TileStructure
66
return new TileStructure( "random", size, null, times );
70
//HAXE: Why can't I implement Iterator<Point2>?
71
/*final*/ private class TSRegular /*implements Iterator<Point2>*/
76
var staggerAt : Point2;
83
public function new( size : Point2, units : Point2, staggerX : Bool, staggerY : Bool )
85
MixinSimpleIterator();
87
ASSERT_TRUE( size.x > 0 && size.y > 0 )
88
ASSERT_TRUE( units.x > 0 && units.y > 0 )
90
this.step = Point2.at( size.x/units.x, size.y/units.y );
95
this.staggerX = staggerX;
96
this.staggerY = staggerY;
97
this.staggerAt = Point2.at( 0, 0 );
100
function _next() : Point2
104
at = Point2.at( 0, 0 );
120
//stagger in the X/Y direction if desired
121
if( staggerX || staggerY )
126
if( staggerX && (row % 2) == 1 )
127
staggerAt.x += step.x/2;
128
if( staggerY && (col % 2) == 1 )
129
staggerAt.y += step.y/2;
137
define(`SimpleIteratorType',`Point2')
138
include(`MixinSimpleIterator.ihx')
141
/*final*/ private class TSRandom /*implements Iterator<Point2>*/
146
public function new( size : Point2, times : Int )
148
MixinSimpleIterator();
150
ASSERT_TRUE( size.x > 0 && size.y > 0 )
155
function _next() : Point2
157
if( this.remain <= 0 )
162
mathx.Random.s_nextFloat( 0, size.x ),
163
mathx.Random.s_nextFloat( 0, size.y )
167
define(`SimpleIteratorType',`Point2')
168
include(MixinSimpleIterator.ihx)