public void NegativeIndexPositiveOriginTest2D() { // Линия возрастает по X var indexesService = new LineSpatialIndexesService(10, new Coordinate(20, 20)); var line = new List <Coordinate> { new Coordinate(-19, -19), new Coordinate(89, 59) }; var index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(18, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == -4 && sp.Column == -4)); Assert.IsTrue(index.Any(sp => sp.Row == -4 && sp.Column == -3)); Assert.IsTrue(index.Any(sp => sp.Row == -3 && sp.Column == -3)); Assert.IsTrue(index.Any(sp => sp.Row == -3 && sp.Column == -2)); Assert.IsTrue(index.Any(sp => sp.Row == -2 && sp.Column == -2)); Assert.IsTrue(index.Any(sp => sp.Row == -2 && sp.Column == -1)); Assert.IsTrue(index.Any(sp => sp.Row == -2 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == -1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == -1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 4)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 4)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 5)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 5)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 6)); // Линия убывает по X indexesService = new LineSpatialIndexesService(10, new Coordinate(20, 20)); line = new List <Coordinate> { new Coordinate(89, 59), new Coordinate(-19, -19) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(18, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == -4 && sp.Column == -4)); Assert.IsTrue(index.Any(sp => sp.Row == -4 && sp.Column == -3)); Assert.IsTrue(index.Any(sp => sp.Row == -3 && sp.Column == -3)); Assert.IsTrue(index.Any(sp => sp.Row == -3 && sp.Column == -2)); Assert.IsTrue(index.Any(sp => sp.Row == -2 && sp.Column == -2)); Assert.IsTrue(index.Any(sp => sp.Row == -2 && sp.Column == -1)); Assert.IsTrue(index.Any(sp => sp.Row == -2 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == -1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == -1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 4)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 4)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 5)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 5)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 6)); }
public void IntersectIndexes3DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0, 0)); var line = new List <Coordinate> { new Coordinate(4, 8, 7), new Coordinate(16, 14, 14) }; var index = indexesService.GetLineSpatial3DIndexes(line); Assert.AreEqual(4, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0 && sp.Layer == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0 && sp.Layer == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0 && sp.Layer == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1 && sp.Layer == 1)); }
public void SimpleIndexes3DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0, 0)); var line = new List <Coordinate> { new Coordinate(5, 5, 5), new Coordinate(15, 18, 25) }; var index = indexesService.GetLineSpatial3DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0 && sp.Layer == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0 && sp.Layer == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0 && sp.Layer == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1 && sp.Layer == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1 && sp.Layer == 2)); }
public void NotIntersectVerticalLinesIndexes2DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0)); var line = new List <Coordinate> { new Coordinate(4, 8), new Coordinate(26, 22) }; var index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 2)); }
public void PointOnGridIndexes2DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0)); var line = new List <Coordinate> { new Coordinate(10, 5), new Coordinate(20, 5) }; var index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(3, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); }
public void SimpleIndexes2DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0)); var line = new List <Coordinate> { new Coordinate(17, 12), new Coordinate(57, 18) }; var index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 4)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 5)); }
public void LineInCellIndexes2DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0)); var line = new List <Coordinate> { new Coordinate(11, 11), new Coordinate(13, 17), new Coordinate(17, 18), new Coordinate(18, 15), new Coordinate(17, 11) }; var index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(1, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); }
public void NegativeIndexPositiveOriginTest3D() { var indexesService = new LineSpatialIndexesService(20, new Coordinate(20, 20, 20)); var line = new List <Coordinate> { new Coordinate(-19, -19, -9), new Coordinate(89, 59, 79) }; var index = indexesService.GetLineSpatial3DIndexes(line); var rows = index.Select(ind => ind.Layer).Distinct().ToList(); Assert.AreEqual(5, rows.Count, "Неверное количество слоёв"); Assert.IsTrue(rows.Any(sp => sp == -2)); Assert.IsTrue(rows.Any(sp => sp == -1)); Assert.IsTrue(rows.Any(sp => sp == 0)); Assert.IsTrue(rows.Any(sp => sp == 1)); Assert.IsTrue(rows.Any(sp => sp == 2)); }
public void ComplexIndexes2DTest() { var indexesService = new LineSpatialIndexesService(10, new Coordinate(0, 0)); #region Возрастает по OY интенсивнее, чем убывает по OX var line = new List <Coordinate> { new Coordinate(25, 5), new Coordinate(5, 45) }; var index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 4 && sp.Column == 0)); #endregion #region Возрастает по OY, не изменяется по OX line = new List <Coordinate> { new Coordinate(5, 5), new Coordinate(5, 45) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 4 && sp.Column == 0)); #endregion #region Возрастает по OY интенсивнее, чем возрастает по OX line = new List <Coordinate> { new Coordinate(5, 5), new Coordinate(25, 45) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 4 && sp.Column == 2)); #endregion #region Убывает по OY интенсивнее, чем убывает по OX line = new List <Coordinate> { new Coordinate(25, 45), new Coordinate(5, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 4 && sp.Column == 2)); #endregion #region Убывает по OY, не изменяется по OX line = new List <Coordinate> { new Coordinate(5, 45), new Coordinate(5, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 4 && sp.Column == 0)); #endregion #region Убывает по OY интенсивнее, чем возрастает по OX line = new List <Coordinate> { new Coordinate(5, 45), new Coordinate(25, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 3 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 4 && sp.Column == 0)); #endregion #region Возрастает по OX интенсивнее, чем возрастает по OY line = new List <Coordinate> { new Coordinate(5, 5), new Coordinate(45, 25) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 4)); #endregion #region Возрастает по OX, не изменяется по OY line = new List <Coordinate> { new Coordinate(5, 5), new Coordinate(45, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 4)); #endregion #region Возрастает по OX интенсивнее, чем убывает по OY line = new List <Coordinate> { new Coordinate(5, 25), new Coordinate(45, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 4)); #endregion #region Убывает по OX интенсивнее, чем возрастает по OY line = new List <Coordinate> { new Coordinate(45, 5), new Coordinate(5, 25) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 4)); #endregion #region Убывает по OX, не изменяется по OY line = new List <Coordinate> { new Coordinate(45, 5), new Coordinate(5, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(5, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 4)); #endregion #region Убывает по OX интенсивнее, чем убывает по OY line = new List <Coordinate> { new Coordinate(45, 25), new Coordinate(5, 5) }; index = indexesService.GetLineSpatial2DIndexes(line); Assert.AreEqual(7, index.Count, "Неверное количество ячеек индекса"); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 0 && sp.Column == 0)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 1)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 2)); Assert.IsTrue(index.Any(sp => sp.Row == 1 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 3)); Assert.IsTrue(index.Any(sp => sp.Row == 2 && sp.Column == 4)); #endregion }