/// <summary> /// Constructor for the Base Point. Takes in a Simple Point structure. /// </summary> /// <param name="inPoint">Input Point.</param> public BasePoint(SimplePoint inPoint) { _position = inPoint; _theta = _position.X * _angleSize; _cosPhi = Math.Cos((_position.Y * _angleSize) + _phiShift); _sinPhi = Math.Sin((_position.Y * _angleSize) + _phiShift); }
/// <summary> /// Determines the points above and below this point, including wrap-arounds. /// </summary> /// <param name="abovePoint">The point above this point.</param> /// <param name="belowPoint">The point below this point.</param> public void FindAboveBelowPoints(out SimplePoint abovePoint, out SimplePoint belowPoint) { if (_y == 0) { if (_x >= _mapSize) { abovePoint = new SimplePoint(_x - _mapSize, _y); } else { abovePoint = new SimplePoint(_x + _mapSize, _y); } belowPoint = new SimplePoint(_x, _y + 1); } else if (_y == _mapSize - 1) { abovePoint = new SimplePoint(_x, _y - 1); if (_x >= _mapSize) { belowPoint = new SimplePoint(_x - _mapSize, _y); } else { belowPoint = new SimplePoint(_x + _mapSize, _y); } } else { abovePoint = new SimplePoint(_x, _y - 1); belowPoint = new SimplePoint(_x, _y + 1); } }
/// <summary> /// Sets static variables for Base Point and Simple Point. /// </summary> /// <param name="inMapSize">Map Size to set up points.</param> public static void MapSetup(int inMapSize) { SimplePoint.MapSize(inMapSize); _mapSize = inMapSize; _angleSize = Math.PI / (double)_mapSize; _phiShift = 0.5 * _angleSize - (Math.PI / 2); }
/// <summary> /// Constructor that sets the position and initial indexes. /// </summary> /// <param name="inX">X Coordinate of point.</param> /// <param name="inY">Y Coordinate of point.</param> /// <param name="inPlateIndex">First index for plate index.</param> /// <param name="inPointIndex">First index for point index.</param> public OverlapPoint(int inX, int inY, int inPlateIndex, int inPointIndex) { _position = new SimplePoint(inX, inY); plateIndex = new List <int>(); pointIndex = new List <int>(); plateIndex.Add(inPlateIndex); pointIndex.Add(inPointIndex); }
/// <summary> /// Determines the points left and right of this point, including wrap-arounds. /// </summary> /// <param name="leftPoint">The point to the left of this point.</param> /// <param name="rightPoint">The point to the right of this point.</param> public void FindLeftRightPoints(out SimplePoint leftPoint, out SimplePoint rightPoint) { if (_x == 0) { leftPoint = new SimplePoint(2 * _mapSize - 1, _y); rightPoint = new SimplePoint(_x + 1, _y); } else if (_x == 2 * _mapSize - 1) { leftPoint = new SimplePoint(_x - 1, _y); rightPoint = new SimplePoint(0, _y); } else { leftPoint = new SimplePoint(_x - 1, _y); rightPoint = new SimplePoint(_x + 1, _y); } }
/// <summary> /// Expands each plate one pixel in every direction until no point outside of all plates exists. /// </summary> private void ExpandPlates() { Queue <OverlapPoint> borderPoints = new Queue <OverlapPoint>(); for (int i = 0; i < Plates.Length; i++) { for (int j = 0; j < Plates[i].PlatePoints.Count; j++) { SimplePoint[] newPoints = new SimplePoint[4]; Plates[i].PlatePoints[j].FindLeftRightPoints(out newPoints[0], out newPoints[1]); Plates[i].PlatePoints[j].FindAboveBelowPoints(out newPoints[2], out newPoints[3]); for (int k = 0; k < 4; k++) { if (!ActivePoints[newPoints[k].X, newPoints[k].Y]) { borderPoints.Enqueue(new OverlapPoint(newPoints[k], i)); } } } } while (borderPoints.Count != 0) { OverlapPoint borderPoint = borderPoints.Dequeue(); if (!ActivePoints[borderPoint.X, borderPoint.Y]) { ActivePoints[borderPoint.X, borderPoint.Y] = true; SimplePoint oldPoint = new SimplePoint(borderPoint.X, borderPoint.Y); Plates[borderPoint.plateIndex[0]].PlatePoints.Add(new PlatePoint(oldPoint)); SimplePoint[] newPointsP = new SimplePoint[4]; oldPoint.FindLeftRightPoints(out newPointsP[0], out newPointsP[1]); oldPoint.FindAboveBelowPoints(out newPointsP[2], out newPointsP[3]); for (int k = 0; k < 4; k++) { if (!ActivePoints[newPointsP[k].X, newPointsP[k].Y]) { OverlapPoint newPoint = new OverlapPoint(newPointsP[k], borderPoint.plateIndex[0]); borderPoints.Enqueue(newPoint); } } } } }
/// <summary> /// Scans for all points in <see cref="ActivePoints"/> that are set to true and are /// contiguously adjacent to the given point and adds them to <see cref="temporaryPlate"/>, /// setting the <see cref="ActivePoints"/> to false in the process. /// </summary> /// <param name="startingPoint">Starting point to check neighbors.</param> private void CheckNeighbor(SimplePoint startingPoint) { Stack <SimplePoint> pointStack = new Stack <SimplePoint>(); ActivePoints[startingPoint.X, startingPoint.Y] = false; pointStack.Push(startingPoint); while (pointStack.Count != 0) { SimplePoint point = pointStack.Pop(); temporaryPlate.PlatePoints.Add(new PlatePoint(point)); SimplePoint[] newPoints = new SimplePoint[4]; point.FindLeftRightPoints(out newPoints[0], out newPoints[1]); point.FindAboveBelowPoints(out newPoints[2], out newPoints[3]); for (int i = 0; i < 4; i++) { if (ActivePoints[newPoints[i].X, newPoints[i].Y]) { ActivePoints[newPoints[i].X, newPoints[i].Y] = false; pointStack.Push(newPoints[i]); } } } }
/// <summary> /// Constructor that sets the position and initial index. /// </summary> /// <param name="inPoint">Coordinates of point.</param> /// <param name="inPlateIndex">First index for plate index.</param> public OverlapPoint(SimplePoint inPoint, int inPlateIndex) { plateIndex = new List <int>(); _position = inPoint; plateIndex.Add(inPlateIndex); }
/// <summary> /// Determines the points left and right of this point, including wrap-arounds. /// </summary> /// <param name="leftPoint">The point to the left of this point.</param> /// <param name="rightPoint">The point to the right of this point.</param> public void FindLeftRightPoints(out SimplePoint leftPoint, out SimplePoint rightPoint) { _position.FindLeftRightPoints(out leftPoint, out rightPoint); }
/// <summary> /// Determines the points above and below this point, including wrap-arounds. /// </summary> /// <param name="abovePoint">The point above this point.</param> /// <param name="belowPoint">The point below this point.</param> public void FindAboveBelowPoints(out SimplePoint abovePoint, out SimplePoint belowPoint) { _position.FindAboveBelowPoints(out abovePoint, out belowPoint); }
/// <summary> /// Calculates the average height of adjacent points in <see cref="PastHeights"/>. /// </summary> /// <param name="iPlate">Index of plate to scan for with <see cref="PastPlates"/>.</param> /// <param name="inPoint">Input point.</param> /// <returns>Average of nearby points from <see cref="PastHeights"/>.</returns> private double AdjacentHeightAverage(int inPlate, SimplePoint inPoint, bool moveHorizontal) { double average = 0; int averageCount = 0; if (moveHorizontal) { inPoint.FindLeftRightPoints(out SimplePoint leftPoint, out SimplePoint rightPoint); if (PastPlates[leftPoint.X, leftPoint.Y] == inPlate) { if (PastHeights[leftPoint.X, leftPoint.Y] != 0) { average += PastHeights[leftPoint.X, leftPoint.Y]; averageCount++; } } if (PastPlates[rightPoint.X, rightPoint.Y] == inPlate) { if (PastHeights[rightPoint.X, rightPoint.Y] != 0) { average += PastHeights[rightPoint.X, rightPoint.Y]; averageCount++; } } if (averageCount == 0) { inPoint.FindAboveBelowPoints(out SimplePoint abovePoint, out SimplePoint belowPoint); if (PastPlates[abovePoint.X, abovePoint.Y] == inPlate) { if (PastHeights[abovePoint.X, abovePoint.Y] != 0) { average += PastHeights[abovePoint.X, abovePoint.Y]; averageCount++; } } if (PastPlates[belowPoint.X, belowPoint.Y] == inPlate) { if (PastHeights[belowPoint.X, belowPoint.Y] != 0) { average += PastHeights[belowPoint.X, belowPoint.Y]; averageCount++; } } } } else { inPoint.FindAboveBelowPoints(out SimplePoint abovePoint, out SimplePoint belowPoint); if (PastPlates[abovePoint.X, abovePoint.Y] == inPlate) { if (PastHeights[abovePoint.X, abovePoint.Y] != 0) { average += PastHeights[abovePoint.X, abovePoint.Y]; averageCount++; } } if (PastPlates[belowPoint.X, belowPoint.Y] == inPlate) { if (PastHeights[belowPoint.X, belowPoint.Y] != 0) { average += PastHeights[belowPoint.X, belowPoint.Y]; averageCount++; } } if (averageCount == 0) { inPoint.FindLeftRightPoints(out SimplePoint leftPoint, out SimplePoint rightPoint); if (PastPlates[leftPoint.X, leftPoint.Y] == inPlate) { if (PastHeights[leftPoint.X, leftPoint.Y] != 0) { average += PastHeights[leftPoint.X, leftPoint.Y]; averageCount++; } } if (PastPlates[rightPoint.X, rightPoint.Y] == inPlate) { if (PastHeights[rightPoint.X, rightPoint.Y] != 0) { average += PastHeights[rightPoint.X, rightPoint.Y]; averageCount++; } } } } if (averageCount > 1) { average = average / (double)averageCount; } return(average); }
/// <summary> /// Constructor for Plate Point. /// </summary> /// <param name="inPoint"> Input coordinates for new point.</param> /// <param name="inHeight">Height of Plate Point, defaults to 0.</param> public PlatePoint(SimplePoint inPoint, double inHeight = 0) { _point = new BasePoint(inPoint); Height = inHeight; }