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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
//! Useful structures and tools used by the fields
//!

use crate::prelude::*;
use bevy::prelude::*;

/// Defines the dimenions of all field arrays
pub const FIELD_RESOLUTION: usize = 10;

/// Convenience way of accessing the 4 sides of a sector in [crate::prelude::Portals], the 4 sides of a field cell in [crate::prelude::IntegrationField] and the 8 directions
/// of movement in [crate::prelude::flow_field::FlowField]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Debug, PartialEq, Clone, Copy, Reflect)]
pub enum Ordinal {
	North,
	East,
	South,
	West,
	NorthEast,
	SouthEast,
	SouthWest,
	NorthWest,
	/// Special case, used to indicate a forbidden cell in the [crate::prelude::flow_field::FlowField]
	Zero,
}

impl Ordinal {
	/// Based on a field cells `(column, row)` position find its neighbours based on FIELD_RESOLUTION limits (up to 4)
	pub fn get_orthogonal_cell_neighbours(cell_id: FieldCell) -> Vec<FieldCell> {
		let mut neighbours = Vec::new();
		if cell_id.get_row() > 0 {
			neighbours.push(FieldCell::new(cell_id.get_column(), cell_id.get_row() - 1)); // northern cell coords
		}
		if cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(cell_id.get_column() + 1, cell_id.get_row())); // eastern cell coords
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(cell_id.get_column(), cell_id.get_row() + 1)); // southern cell coords
		}
		if cell_id.get_column() > 0 {
			neighbours.push(FieldCell::new(cell_id.get_column() - 1, cell_id.get_row())); // western cell coords
		}
		neighbours
	}
	/// Based on a field cells `(column, row)` position find its diagonal neighbours based on FIELD_RESOLUTION limits (up to 4)
	pub fn get_diagonal_cell_neighbours(cell_id: FieldCell) -> Vec<FieldCell> {
		let mut neighbours = Vec::new();
		if cell_id.get_row() > 0 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() + 1,
				cell_id.get_row() - 1,
			)); // north-east cell
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() + 1,
				cell_id.get_row() + 1,
			)); // south-east cell
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() > 0 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() - 1,
				cell_id.get_row() + 1,
			)); // south-west cell
		}
		if cell_id.get_row() > 0 && cell_id.get_column() > 0 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() - 1,
				cell_id.get_row() - 1,
			)); // north-west cell
		}
		neighbours
	}
	/// Based on a field cells `(column, row)` and an [Ordinal] direction find the neighbouring [FieldCell] if one exists
	pub fn get_cell_neighbour(cell_id: FieldCell, ordinal: Ordinal) -> Option<FieldCell> {
		match ordinal {
			Ordinal::North => {
				if cell_id.get_row() > 0 {
					Some(FieldCell::new(cell_id.get_column(), cell_id.get_row() - 1))
				} else {
					None
				}
			}
			Ordinal::East => {
				if cell_id.get_column() < FIELD_RESOLUTION - 1 {
					Some(FieldCell::new(cell_id.get_column() + 1, cell_id.get_row()))
				} else {
					None
				}
			}
			Ordinal::South => {
				if cell_id.get_row() < FIELD_RESOLUTION - 1 {
					Some(FieldCell::new(cell_id.get_column(), cell_id.get_row() + 1))
				} else {
					None
				}
			}
			Ordinal::West => {
				if cell_id.get_column() > 0 {
					Some(FieldCell::new(cell_id.get_column() - 1, cell_id.get_row()))
				} else {
					None
				}
			}
			Ordinal::NorthEast => {
				if cell_id.get_row() > 0 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
					Some(FieldCell::new(
						cell_id.get_column() + 1,
						cell_id.get_row() - 1,
					))
				} else {
					None
				}
			}
			Ordinal::SouthEast => {
				if cell_id.get_row() < FIELD_RESOLUTION - 1
					&& cell_id.get_column() < FIELD_RESOLUTION - 1
				{
					Some(FieldCell::new(
						cell_id.get_column() + 1,
						cell_id.get_row() + 1,
					))
				} else {
					None
				}
			}
			Ordinal::SouthWest => {
				if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() > 0 {
					Some(FieldCell::new(
						cell_id.get_column() - 1,
						cell_id.get_row() + 1,
					))
				} else {
					None
				}
			}
			Ordinal::NorthWest => {
				if cell_id.get_row() > 0 && cell_id.get_column() > 0 {
					Some(FieldCell::new(
						cell_id.get_column() - 1,
						cell_id.get_row() - 1,
					))
				} else {
					None
				}
			}
			Ordinal::Zero => None,
		}
	}
	/// Based on a field cells `(column, row)` position find all possible neighbours including diagonal directions
	pub fn get_all_cell_neighbours(cell_id: FieldCell) -> Vec<FieldCell> {
		let mut neighbours = Vec::new();
		if cell_id.get_row() > 0 {
			neighbours.push(FieldCell::new(cell_id.get_column(), cell_id.get_row() - 1)); // northern cell coords
		}
		if cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(cell_id.get_column() + 1, cell_id.get_row())); // eastern cell coords
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(cell_id.get_column(), cell_id.get_row() + 1)); // southern cell coords
		}
		if cell_id.get_column() > 0 {
			neighbours.push(FieldCell::new(cell_id.get_column() - 1, cell_id.get_row())); // western cell coords
		}
		if cell_id.get_row() > 0 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() + 1,
				cell_id.get_row() - 1,
			)); // north-east cell
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() + 1,
				cell_id.get_row() + 1,
			)); // south-east cell
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() > 0 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() - 1,
				cell_id.get_row() + 1,
			)); // south-west cell
		}
		if cell_id.get_row() > 0 && cell_id.get_column() > 0 {
			neighbours.push(FieldCell::new(
				cell_id.get_column() - 1,
				cell_id.get_row() - 1,
			)); // north-west cell
		}
		neighbours
	}
	/// Based on a field cells `(column, row)` position find all possible neighbours including diagonal directions and the Ordinal they are found in
	pub fn get_all_cell_neighbours_with_ordinal(cell_id: FieldCell) -> Vec<(Ordinal, FieldCell)> {
		let mut neighbours = Vec::new();
		if cell_id.get_row() > 0 {
			neighbours.push((
				Ordinal::North,
				FieldCell::new(cell_id.get_column(), cell_id.get_row() - 1),
			)); // northern cell coords
		}
		if cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push((
				Ordinal::East,
				FieldCell::new(cell_id.get_column() + 1, cell_id.get_row()),
			)); // eastern cell coords
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 {
			neighbours.push((
				Ordinal::South,
				FieldCell::new(cell_id.get_column(), cell_id.get_row() + 1),
			)); // southern cell coords
		}
		if cell_id.get_column() > 0 {
			neighbours.push((
				Ordinal::West,
				FieldCell::new(cell_id.get_column() - 1, cell_id.get_row()),
			)); // western cell coords
		}
		if cell_id.get_row() > 0 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push((
				Ordinal::NorthEast,
				FieldCell::new(cell_id.get_column() + 1, cell_id.get_row() - 1),
			)); // north-east cell
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() < FIELD_RESOLUTION - 1 {
			neighbours.push((
				Ordinal::SouthEast,
				FieldCell::new(cell_id.get_column() + 1, cell_id.get_row() + 1),
			)); // south-east cell
		}
		if cell_id.get_row() < FIELD_RESOLUTION - 1 && cell_id.get_column() > 0 {
			neighbours.push((
				Ordinal::SouthWest,
				FieldCell::new(cell_id.get_column() - 1, cell_id.get_row() + 1),
			)); // south-west cell
		}
		if cell_id.get_row() > 0 && cell_id.get_column() > 0 {
			neighbours.push((
				Ordinal::NorthWest,
				FieldCell::new(cell_id.get_column() - 1, cell_id.get_row() - 1),
			)); // north-west cell
		}
		neighbours
	}
	/// Based on a sectors `(column, row)` position find its neighbours based on map size limits (up to 4)
	/// ```txt
	/// top left                     // top right
	/// has 2 valid neighbours      // has two valid neighbours
	/// ___________                 // ___________
	/// | x       |                 // |       x |
	/// |x        |                 // |        x|
	/// |         |                 // |         |
	/// |         |                 // |         |
	/// |_________|                 // |_________|
	/// bottom right                // bottom left sector
	/// has two valid neighbours    // has two valid neighbours
	/// ___________                 // ___________
	/// |         |                 // |         |
	/// |         |                 // |         |
	/// |         |                 // |         |
	/// |        x|                 // |x        |
	/// |_______x_|                 // |_x_______|
	/// northern row minus          // eastern column minus
	/// corners have three          // corners have three
	/// valid neighbours            // valid neighbours
	/// ___________                 // ___________
	/// |x       x|                 // |        x|
	/// |  xxxxx  |                 // |       x |
	/// |         |                 // |       x |
	/// |         |                 // |       x |
	/// |_________|                 // |________x|
	/// southern row minus          // western column minus
	/// corners have three          // corners have three
	/// valid neighbours            // valid neighbours
	/// ___________                 // ___________
	/// |         |                 // |x        |
	/// |         |                 // | x       |
	/// |         |                 // | x       |
	/// | xxxxxxx |                 // | x       |
	/// |x       x|                 // |x________|
	/// all other sectors not along an edge of the map have four valid sectors for portals
	/// ___________
	/// |         |
	/// |    x    |
	/// |   x x   |
	/// |    x    |
	/// |_________|
	/// ```
	pub fn get_sector_neighbours(
		sector_id: &SectorID,
		map_length: u32,
		map_depth: u32,
		sector_resolution: u32,
	) -> Vec<SectorID> {
		let mut neighbours = Vec::new();
		let sector_column_limit = map_length / sector_resolution - 1;
		let sector_row_limit = map_depth / sector_resolution - 1;
		if sector_id.get_row() > 0 {
			neighbours.push(SectorID::new(
				sector_id.get_column(),
				sector_id.get_row() - 1,
			)); // northern sector coords
		}
		if sector_id.get_column() < sector_column_limit {
			neighbours.push(SectorID::new(
				sector_id.get_column() + 1,
				sector_id.get_row(),
			)); // eastern sector coords
		}
		if sector_id.get_row() < sector_row_limit {
			neighbours.push(SectorID::new(
				sector_id.get_column(),
				sector_id.get_row() + 1,
			)); // southern sector coords
		}
		if sector_id.get_column() > 0 {
			neighbours.push(SectorID::new(
				sector_id.get_column() - 1,
				sector_id.get_row(),
			)); // western sector coords
		}
		neighbours
	}
	/// Based on a sectors `(column, row)` position find the [Ordinal] directions for its boundaries that can support [crate::prelude::Portals]
	pub fn get_sector_portal_ordinals(
		sector_id: &SectorID,
		map_length: u32,
		map_depth: u32,
		sector_resolution: u32,
	) -> Vec<Ordinal> {
		let mut neighbours = Vec::new();
		let sector_column_limit = map_length / sector_resolution - 1;
		let sector_row_limit = map_depth / sector_resolution - 1;
		if sector_id.get_row() > 0 {
			neighbours.push(Ordinal::North); // northern sector coords
		}
		if sector_id.get_column() < sector_column_limit {
			neighbours.push(Ordinal::East); // eastern sector coords
		}
		if sector_id.get_row() < sector_row_limit {
			neighbours.push(Ordinal::South); // southern sector coords
		}
		if sector_id.get_column() > 0 {
			neighbours.push(Ordinal::West); // western sector coords
		}
		neighbours
	}
	/// Based on a sectors `(column, row)` position find its neighbours based on map size limits (up to 4) and include the [Ordinal] direction in the result
	/// ```txt
	///top left                      top right
	/// has 2 valid neighbours       has two valid neighbours
	/// ___________                  ___________
	/// | x       |                  |       x |
	/// |x        |                  |        x|
	/// |         |                  |         |
	/// |         |                  |         |
	/// |_________|                  |_________|
	/// bottom right                 bottom left sector
	/// has two valid neighbours     has two valid neighbours
	/// ___________                  ___________
	/// |         |                  |         |
	/// |         |                  |         |
	/// |         |                  |         |
	/// |        x|                  |x        |
	/// |_______x_|                  |_x_______|
	/// northern row minus           eastern column minus
	/// corners have three           corners have three
	/// valid neighbours             valid neighbours
	/// ___________                  ___________
	/// |x       x|                  |        x|
	/// |  xxxxx  |                  |       x |
	/// |         |                  |       x |
	/// |         |                  |       x |
	/// |_________|                  |________x|
	/// southern row minus           western column minus
	/// corners have three           corners have three
	/// valid neighbours             valid neighbours
	/// ___________                  ___________
	/// |         |                  |x        |
	/// |         |                  | x       |
	/// |         |                  | x       |
	/// | xxxxxxx |                  | x       |
	/// |x       x|                  |x________|
	/// all other sectors not along an edge of the map have four valid sectors for portals
	/// ___________
	/// |         |
	/// |    x    |
	/// |   x x   |
	/// |    x    |
	/// |_________|
	/// ```
	pub fn get_sector_neighbours_with_ordinal(
		sector_id: &SectorID,
		map_x_dimension: u32,
		map_z_dimension: u32,
		sector_resolution: u32,
	) -> Vec<(Ordinal, SectorID)> {
		let mut neighbours = Vec::new();
		let sector_x_column_limit = map_x_dimension / sector_resolution - 1;
		let sector_z_row_limit = map_z_dimension / sector_resolution - 1;
		if sector_id.get_row() > 0 {
			neighbours.push((
				Ordinal::North,
				SectorID::new(sector_id.get_column(), sector_id.get_row() - 1),
			)); // northern sector coords
		}
		if sector_id.get_column() < sector_x_column_limit {
			neighbours.push((
				Ordinal::East,
				SectorID::new(sector_id.get_column() + 1, sector_id.get_row()),
			)); // eastern sector coords
		}
		if sector_id.get_row() < sector_z_row_limit {
			neighbours.push((
				Ordinal::South,
				SectorID::new(sector_id.get_column(), sector_id.get_row() + 1),
			)); // southern sector coords
		}
		if sector_id.get_column() > 0 {
			neighbours.push((
				Ordinal::West,
				SectorID::new(sector_id.get_column() - 1, sector_id.get_row()),
			)); // western sector coords
		}
		neighbours
	}
	/// Returns the opposite [Ordinal] of the current
	pub fn inverse(&self) -> Ordinal {
		match self {
			Ordinal::North => Ordinal::South,
			Ordinal::East => Ordinal::West,
			Ordinal::South => Ordinal::North,
			Ordinal::West => Ordinal::East,
			Ordinal::NorthEast => Ordinal::SouthWest,
			Ordinal::SouthEast => Ordinal::NorthWest,
			Ordinal::SouthWest => Ordinal::NorthEast,
			Ordinal::NorthWest => Ordinal::SouthEast,
			Ordinal::Zero => Ordinal::Zero,
		}
	}
	/// For two cells next to each other it can be useful to find the [Ordinal] point from the `source` to the `target`
	pub fn cell_to_cell_direction(target: FieldCell, source: FieldCell) -> Self {
		let i32_target = (target.get_column() as i32, target.get_row() as i32);
		let i32_source = (source.get_column() as i32, source.get_row() as i32);

		let direction = (i32_target.0 - i32_source.0, i32_target.1 - i32_source.1);
		match direction {
			(0, -1) => Ordinal::North,
			(1, -1) => Ordinal::NorthEast,
			(1, 0) => Ordinal::East,
			(1, 1) => Ordinal::SouthEast,
			(0, 1) => Ordinal::South,
			(-1, 1) => Ordinal::SouthWest,
			(-1, 0) => Ordinal::West,
			(-1, -1) => Ordinal::NorthWest,
			_ => panic!(
				"Cell {:?} is not orthogonally or diagonally adjacent to {:?}",
				target, source
			),
		}
	}
	/// For two sectors next to each other it can be useful to find the [Ordinal] from the `source` to the `target`. This will panic if the two sectors are not orthogonally adjacent
	pub fn sector_to_sector_direction(target: SectorID, source: SectorID) -> Option<Self> {
		let i32_target = (target.get_column() as i32, target.get_row() as i32);
		let i32_source = (source.get_column() as i32, source.get_row() as i32);

		let direction = (i32_target.0 - i32_source.0, i32_target.1 - i32_source.1);
		match direction {
			(0, -1) => Some(Ordinal::North),
			(1, 0) => Some(Ordinal::East),
			(0, 1) => Some(Ordinal::South),
			(-1, 0) => Some(Ordinal::West),
			_ => {
				error!(
					"Sector {:?} is not orthogonally adjacent to {:?}",
					target, source
				);
				None
			}
		}
	}
}

// #[rustfmt::skip]
#[cfg(test)]
mod tests {
	use super::*;
	#[test]
	fn ordinal_field_cell_neighbours() {
		let cell_id = FieldCell::new(0, 0);
		let result = Ordinal::get_orthogonal_cell_neighbours(cell_id);
		let actual = vec![FieldCell::new(1, 0), FieldCell::new(0, 1)];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_field_cell_neighbours2() {
		let cell_id = FieldCell::new(9, 9);
		let result = Ordinal::get_orthogonal_cell_neighbours(cell_id);
		let actual = vec![FieldCell::new(9, 8), FieldCell::new(8, 9)];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_field_cell_neighbours3() {
		let cell_id = FieldCell::new(4, 4);
		let result = Ordinal::get_orthogonal_cell_neighbours(cell_id);
		let actual = vec![
			FieldCell::new(4, 3),
			FieldCell::new(5, 4),
			FieldCell::new(4, 5),
			FieldCell::new(3, 4),
		];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_field_cell_neighbours4() {
		let cell_id = FieldCell::new(5, 0);
		let result = Ordinal::get_orthogonal_cell_neighbours(cell_id);
		let actual = vec![
			FieldCell::new(6, 0),
			FieldCell::new(5, 1),
			FieldCell::new(4, 0),
		];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_sector_neighbours() {
		let sector_id = SectorID::new(0, 0);
		let map_x_dimension = 300;
		let map_z_dimension = 550;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_neighbours(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![SectorID::new(1, 0), SectorID::new(0, 1)];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_sector_neighbours2() {
		let sector_id = SectorID::new(29, 54);
		let map_x_dimension = 300;
		let map_z_dimension = 550;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_neighbours(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![SectorID::new(29, 53), SectorID::new(28, 54)];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_sector_neighbours3() {
		let sector_id = SectorID::new(14, 31);
		let map_x_dimension = 300;
		let map_z_dimension = 550;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_neighbours(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![
			SectorID::new(14, 30),
			SectorID::new(15, 31),
			SectorID::new(14, 32),
			SectorID::new(13, 31),
		];
		assert_eq!(actual, result);
	}
	#[test]
	fn ordinal_sector_neighbours4() {
		let sector_id = SectorID::new(0, 13);
		let map_x_dimension = 300;
		let map_z_dimension = 550;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_neighbours(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![
			SectorID::new(0, 12),
			SectorID::new(1, 13),
			SectorID::new(0, 14),
		];
		assert_eq!(actual, result);
	}
	#[test]
	fn get_northern_oridnals() {
		let sector_id = SectorID::new(3, 0);
		let map_x_dimension = 200;
		let map_z_dimension = 200;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_portal_ordinals(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![Ordinal::East, Ordinal::South, Ordinal::West];
		assert_eq!(actual, result);
	}
	#[test]
	fn get_eastern_oridnals() {
		let sector_id = SectorID::new(19, 5);
		let map_x_dimension = 200;
		let map_z_dimension = 200;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_portal_ordinals(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![Ordinal::North, Ordinal::South, Ordinal::West];
		assert_eq!(actual, result);
	}
	#[test]
	fn get_southern_oridnals() {
		let sector_id = SectorID::new(4, 19);
		let map_x_dimension = 200;
		let map_z_dimension = 200;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_portal_ordinals(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![Ordinal::North, Ordinal::East, Ordinal::West];
		assert_eq!(actual, result);
	}
	#[test]
	fn get_western_oridnals() {
		let sector_id = SectorID::new(0, 5);
		let map_x_dimension = 200;
		let map_z_dimension = 200;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_portal_ordinals(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![Ordinal::North, Ordinal::East, Ordinal::South];
		assert_eq!(actual, result);
	}
	#[test]
	fn get_centre_oridnals() {
		let sector_id = SectorID::new(4, 5);
		let map_x_dimension = 200;
		let map_z_dimension = 200;
		let sector_resolution = 10;
		let result = Ordinal::get_sector_portal_ordinals(
			&sector_id,
			map_x_dimension,
			map_z_dimension,
			sector_resolution,
		);
		let actual = vec![Ordinal::North, Ordinal::East, Ordinal::South, Ordinal::West];
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_north() {
		let target = FieldCell::new(6, 2);
		let source = FieldCell::new(6, 3);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::North;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_north_east() {
		let target = FieldCell::new(7, 2);
		let source = FieldCell::new(6, 3);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::NorthEast;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_east() {
		let target = FieldCell::new(6, 7);
		let source = FieldCell::new(5, 7);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::East;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_south_east() {
		let target = FieldCell::new(5, 5);
		let source = FieldCell::new(4, 4);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::SouthEast;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_south() {
		let target = FieldCell::new(3, 1);
		let source = FieldCell::new(3, 0);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::South;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_south_west() {
		let target = FieldCell::new(6, 9);
		let source = FieldCell::new(7, 8);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::SouthWest;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_west() {
		let target = FieldCell::new(5, 7);
		let source = FieldCell::new(6, 7);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::West;
		assert_eq!(actual, result);
	}
	#[test]
	fn cell_to_cell_north_west() {
		let target = FieldCell::new(0, 0);
		let source = FieldCell::new(1, 1);
		let result = Ordinal::cell_to_cell_direction(target, source);
		let actual = Ordinal::NorthWest;
		assert_eq!(actual, result);
	}
}