-
Notifications
You must be signed in to change notification settings - Fork 1
/
Generation.cs
50 lines (43 loc) · 1.81 KB
/
Generation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections.Generic;
using System.Linq;
namespace Lignus.HexTile
{
public static class Generation
{
public static List<Hex> Parallelogram(Hex min, Hex max) =>
Enumerable.Range(min.q, max.q - min.q + 1).SelectMany(
x => Enumerable.Range(min.r, max.r - min.r + 1),
(x, y) => new Hex(x, y)
).ToList();
public static List<Hex> Triangle(int size) => Triangle(Hex.Zero, size);
public static List<Hex> Triangle(Hex pos, int size) =>
Enumerable.Range(pos.q, size + 1).SelectMany(
x => Enumerable.Range(pos.r, size - x + 1),
(x, y) => new Hex(x, y)
).ToList();
public static List<Hex> Hexagon(int radius) => Hex.Zero.Range(radius);
public static List<Hex> Hexagon(Hex pos, int radius) => pos.Range(radius);
public static List<Hex> PointyRectangle(int left, int right, int top, int bottom) =>
Enumerable.Range(top, bottom - top + 1).SelectMany(
y =>
{
var yOffset = y >> 1;
var start = left - yOffset;
var end = right - yOffset - start + 1;
return Enumerable.Range(start, end);
},
(y, x) => new Hex(x, y)
).ToList();
public static List<Hex> FlatRectangle(int left, int right, int top, int bottom) =>
Enumerable.Range(left, right - left + 1).SelectMany(
x =>
{
var xOffset = x >> 1;
var start = top - xOffset;
var end = bottom - xOffset - start + 1;
return Enumerable.Range(start, end);
},
(x, y) => new Hex(x, y)
).ToList();
}
}