List<Shard> Split(Shard shard, int n) { if (n == 0) { return null; } else if (n == 1) { var set = new List<Shard>(); set.Add(shard); return set; } else { Shard shard1, shard2; shard.Split(out shard1, out shard2); int m = n / 2; var set1 = Split(shard1, m); var set2 = Split(shard2, n - m); set1.AddRange(set2); return set1; } }
public void Split(out Shard s1, out Shard s2) { bool horizontal = (_random.Next() & 1) == 1; Console.WriteLine(horizontal); if (horizontal) { var c1 = Coord.PointInBetween(_ul, _ll, _random.NextDouble()); var c2 = Coord.PointInBetween(_ur, _lr, _random.NextDouble()); s1 = new Shard(_ul, _ur, c1, c2); s2 = new Shard(c1, c2, _ll, _lr); } else { var c1 = Coord.PointInBetween(_ul, _ur, _random.NextDouble()); var c2 = Coord.PointInBetween(_ll, _lr, _random.NextDouble()); s1 = new Shard(_ul, c1, _ll, c2); s2 = new Shard(c1, _ur, c2, _lr); } }