public void Handle(InitRectify message) { _node.LogMessage(message); // Notify the successor to update it's predecessor with this node's info var opId = _node.Config.CorrelationFactory.GetNextCorrelation(); var handler = _node.CreateAwaitAllResponsesHandler(); handler .PerformAction(() => { _node.Log($"Sending Rectify to {_node.Successor} Id:{opId}"); var msg = new Rectify(_node.Identity, _node.Successor, opId) { Predecessor = _node.Identity }; _commMgr.Send(msg); }) .AndAwait(opId, (RectifyReply reply) => { _node.LogMessage(reply); _node.Log($"{_node.Identity} Joined Network"); }) .Run(opId); }
//[TestMethod] //[TestCategory("Pathfinder")] public void CachePathTest() { //The caching was removed, so this test will fail. The prior method of caching worked _pretty_ well, but needs some refinements. //could run into an issue where navigating to two adjacent cells cut the corner due to the caching optimistically assuming the diagonal could //be taken when it could not. (See TestSingleCellObstruction) //I suspect there's a better way to handle caching. Perhaps some way based on the distance from the rectangle traversal edges? List <RectDetectPair> edges = new List <RectDetectPair> { new RectDetectPair(0, 3, EdgeType.Aperture) }; var result = Rectify.MakeRectangles(TestData.UnityModifiedDesertTitans(), DataLayout.CodeInitializedArray, edgeOverrides: edges); var pathfinder = new RectifyPathfinder(result, StandardParams); var resultPath = pathfinder.CalculatePath(new Position(109, 147), new Position(150, 75), out PathfinderMetrics metrics, (int)EdgeType.None | (int)EdgeType.Aperture); Assert.AreEqual(44, resultPath.Count, "fail to find a path as expected"); //same overall path, this should hit the cache. resultPath = pathfinder.CalculatePath(new Position(109, 145), new Position(150, 75), out PathfinderMetrics metricsAfterCache, (int)EdgeType.None | (int)EdgeType.Aperture); Assert.AreNotEqual(0, metrics.VisitedNodes, "pathfound w/o traversing nodes somehow"); Assert.AreEqual(0, metricsAfterCache.VisitedNodes, "pathfound w/o using the cache as intended"); }
public void TestBlockPathsLattice() { var result = Rectify.MakeRectangles(GridLatticeTestData.KeyholeApertureLattice()); Assert.AreEqual(2, result.Count, "Did not get 2 initial rectangles as expected"); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); var resultPath = pathfinder.CalculatePath(new Position(2, 3), new Position(2, 1)); Assert.AreEqual(3, resultPath.Count, "Did not find a path where expected"); pathfinder.ReplaceCellEdgeAt(new Position(2, 2), Direction.North, EdgeType.Wall); Assert.AreEqual(5, pathfinder.NodeCount, "Did not get the 5 total rectangles expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 3)); Assert.AreEqual(0, resultPath.Count, "did not find a path when expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 1)); Assert.AreEqual(2, resultPath.Count, "found a path when none expected"); resultPath = pathfinder.CalculatePath(new Position(1, 2), new Position(2, 2)); Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected"); }
public void RoomHolesTest() { var result = Rectify.GetRectNodes(TestData.RoomHoles(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); Assert.AreEqual(2, output[0].Holes.Count, "Did not get 2 holes as expected"); }
public void MakeRimworldSaveTest() { //break this down into pieces. List <RectifyRectangle> result = null; //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(0, 0), new Position(50, 50)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(50, 0), new Position(100, 50)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(100, 0), new Position(275, 50)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(100, 50), new Position(150, 100)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(200, 50), new Position(275, 150)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(0, 150), new Position(50, 274)); //completes w/o error //for whatever reason, only 274 height. Missed a row originally, I guess? //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(150, 150), new Position(250, 200)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(0, 25), new Position(100, 200)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(100, 0), new Position(275, 200)); //completes w/o error //result = Rectify.MakeRectangles(TestData.DesertTitans(), new Position(15, 0), new Position(275, 274)); result = Rectify.MakeRectangles(TestData.DesertTitans(), DataLayout.CodeInitializedArray); Assert.AreEqual(724, result.Count, "Expect 724 rectangles, probably"); //let's make sure that no rectangle overlaps. That would be super sad :( for (int i = 0; i < result.Count; i++) { var rr = result[i]; for (int j = i + 1; j < result.Count; j++) { var rr_other = result[j]; Assert.IsFalse( rr.Left <rr_other.Right && rr.Right> rr_other.Left && rr.Top > rr_other.Bottom && rr.Bottom < rr_other.Top, "Intersecting rectangles :("); } } }
public void TestBlockPaths() { var result = Rectify.MakeRectangles(TestData.KeyholeTest(), DataLayout.CodeInitializedArray); Assert.AreEqual(5, result.Count, "Did not get 5 initial rectangles as expected"); var pathfinder = new RectifyPathfinder(result, StandardParams); pathfinder.ReplaceCellAt(new Position(2, 2), 2); Assert.AreEqual(5, pathfinder.NodeCount, "Did not get the 5 total rectangles expected"); var resultPath = pathfinder.CalculatePath(new Position(2, 3), new Position(2, 1)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 3)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); resultPath = pathfinder.CalculatePath(new Position(1, 2), new Position(3, 2)); Assert.AreEqual(3, resultPath.Count, "Did not find a path where expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(1, 2)); Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected"); }
public void StardewFarmPathingTest() { //var result = Rectify.MakeRectangles(TestData.StardewTestData(), new Position(0, 0), new Position(55, 39)); //var result = Rectify.MakeRectangles(TestData.StardewTestData(), new Position(0, 0), new Position(50, 25)); var result = Rectify.MakeRectangles(TestData.StardewTestData()); Assert.AreEqual(195, result.Count); }
public void RectNodesFromEmptyUnevenGridLatticeTest() { List <RectifyRectangle> result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10, 20)); Assert.AreEqual(1, result.Count, "Didn't get the single Rectangle as expected"); List <RectifyRectangle> result2 = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(15, 10)); Assert.AreEqual(1, result2.Count, "Didn't get the single Rectangle as expected"); }
public void MultiEdgePathfinderTest() { var result = Rectify.MakeRectangles(TestData.OneDRectangleTest(), DataLayout.CodeInitializedArray); var pathfinder = new RectifyPathfinder(result, StandardParams); var resultPath = pathfinder.CalculatePath(new Position(0, 6), new Position(7, 6), (int)EdgeType.None + (int)EdgeType.Wall); Assert.AreEqual(5, resultPath.Count, "Didn't find straight-line path as expected"); }
public void NoPathPathfinderTest() { var result = Rectify.MakeRectangles(TestData.OneDRectangleTest(), DataLayout.CodeInitializedArray); var pathfinder = new RectifyPathfinder(result, StandardParams); var resultPath = pathfinder.CalculatePath(new Position(0, 1), new Position(3, 6), (int)EdgeType.None); Assert.AreEqual(0, resultPath.Count, "Didn't fail to find a path as expected"); }
public void NeighborsInitialTest() { var result = Rectify.MakeRectangles(TestData.OneDRectangleTest(), DataLayout.CodeInitializedArray); Assert.AreEqual(3, result[0].NeighborCount, "0,0::3,2 has 3 neighbors (2 east, 1 south)"); Assert.AreEqual(3, result[1].NeighborCount, "0,2::8,8 has 3 neighbors (3 north)"); Assert.AreEqual(3, result[2].NeighborCount, "4,0::8,2 has 3 neighbors (2 west, 1 south)"); Assert.AreEqual(3, result[3].NeighborCount, "3,0::4,1 has 3 neighbors (1 east, 1 west, 1 south)"); Assert.AreEqual(4, result[4].NeighborCount, "3,1::4,2 has 4 neighbors (1 east, 1 west, 1 south, 1 north)"); }
/// <summary> /// 将车机坐标转换成与地图显示一致的 /// </summary> /// <param name="lng"></param> /// <param name="lat"></param> /// <returns></returns> public static PointModel NetDecryFixTrue(double lng, double lat) { Rectify.Wgs84_To_Gcj02(ref lat, ref lng); //NetDecry.Fix(ref lng, ref lat, true); PointModel point = new PointModel() { Longitude = lng, Latitude = lat }; return(point); }
/// <summary> /// 将地图坐标转换成与车机一致的 /// </summary> /// <param name="lng"></param> /// <param name="lat"></param> /// <returns></returns> public static PointModel NetDecryFixFalse(double lng, double lat) { Rectify.Gcj02_To_Wgs84(ref lat, ref lng); //NetDecry.Fix(ref lng, ref lat, false); PointModel point = new PointModel() { Longitude = lng, Latitude = lat }; return(point); }
public void KoenigsAlgorithmAlternatingPathTest() { var data = TestData.GetAlternatingNodesMatching(); var uList = data.Item1.Select(ree => ree.FirstEdge); //maxmatching is <horizontal, vertical>, so only need to look for the firstEdge List <RectFlowNode> zNodes = new List <RectFlowNode>(data.Item2.FindAll(hn => hn.FlowType == FlowType.horizontal && uList.Contains(hn.Edge) == false)); var result = Rectify.FindAlternatingPathVerts(data.Item1, zNodes); Assert.AreEqual(10, result.Count, "alternating path didn't return 10 items as expected"); }
public void TestSingleCellObstruction() { var result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10)); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); pathfinder.ReplaceCellAt(new Position(2, 4), 7); var resultPath = pathfinder.CalculatePath(new Position(3, 4), new Position(1, 3)); Assert.AreEqual(4, resultPath.Count, "path was not length 4 as expected"); resultPath = pathfinder.CalculatePath(new Position(3, 4), new Position(1, 4)); Assert.AreEqual(5, resultPath.Count, "path was not length 5 as expected"); }
public void TestPathTranslate() { var result = Rectify.MakeRectangles(GridLatticeTestData.CornersLattice()); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); var resultPath = pathfinder.CalculatePath(new Position(3, 6), new Position(6, 4)); var resultPathAlt = pathfinder.CalculatePath(new Position(6, 4), new Position(3, 6)); //Due to changes in underlying code, this test is moot. }
public void MetoriteSiteTest() { var result = Rectify.GetRectNodes(TestData.MeteorStrike(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); var polygons = Rectify.FindVertsFromEdges(output); var subpolygons = Rectify.FirstLevelDecomposition(polygons[0]); Assert.AreEqual(1, subpolygons.Count, "Didn't get 1 subpolygon as expected"); List <RectShape> subsubPolygons = ValidateRects(subpolygons); Assert.AreEqual(8, subsubPolygons.Count, "Did not decomp into the minimum 8 polygons"); }
public void HoleSelfCutWithCogridCompanionTest() { var result = Rectify.GetRectNodes(TestData.SelfHoleCutWithCogridSide(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); var polygons = Rectify.FindVertsFromEdges(output); var subpolygons = Rectify.FirstLevelDecomposition(polygons[1]); Assert.AreEqual(2, subpolygons.Count, "Didn't get 2 subpolygon as expected"); List <RectShape> subsubPolygons = ValidateRects(subpolygons); Assert.AreEqual(6, subsubPolygons.Count, "Did not decomp into the minimum 6 polygons"); }
/// <summary> /// 高德地图坐标和车机坐标互转 /// 地图上获取的是地图坐标,存入数据库时需要转换成车机坐标 /// 数据库查询出来的坐标是车机坐标,地图显示时候需要转换成地图坐标 /// </summary> /// <param name="efType">坐标数据是圆形或者矩形、多边形,圆形和矩形、多边形的存储方式有别,需要分开处理</param> /// <param name="efInfo">坐标数据</param> /// <param name="changeType">1--地图坐标转车机坐标,2--车机坐标转地图坐标</param> /// <returns></returns> public static string ChangeCoordinateSystem(int?efType, string efInfo, int changeType) { string[] _tempEfInfo; string _rsEfInfo = ""; if (efType == 1) //圆形 { _tempEfInfo = efInfo.Split(';'); for (int i = 0; i < _tempEfInfo.Length - 1; i++) //最后一个是圆形半径,去掉 { string[] _tempCoordinate = _tempEfInfo[i].Split(','); double _lng = double.Parse(_tempCoordinate[0]); double _lat = double.Parse(_tempCoordinate[1]); if (changeType == 1) { //NetDecry.Fix(ref _lng, ref _lat, false); Rectify.Gcj02_To_Wgs84(ref _lat, ref _lng); } //将地图坐标置成车机坐标 else if (changeType == 2) { //NetDecry.Fix(ref _lng, ref _lat, true); Rectify.Wgs84_To_Gcj02(ref _lat, ref _lng); } //将车机坐标置成地图坐标 _rsEfInfo += _lng + "," + _lat + ";"; } _rsEfInfo += _tempEfInfo[_tempEfInfo.Length - 1]; //加上半径信息 } else if (efType == 2 || efType == 3) //矩形、多边形 { _tempEfInfo = efInfo.Split(';'); for (int i = 0; i < _tempEfInfo.Length; i++) { string[] _tempCoordinate = _tempEfInfo[i].Split(','); double _lng = double.Parse(_tempCoordinate[0]); double _lat = double.Parse(_tempCoordinate[1]); if (changeType == 1) { //NetDecry.Fix(ref _lng, ref _lat, false); Rectify.Gcj02_To_Wgs84(ref _lat, ref _lng); } //将地图坐标置成车机坐标 else if (changeType == 2) { //NetDecry.Fix(ref _lng, ref _lat, true); Rectify.Wgs84_To_Gcj02(ref _lat, ref _lng); } //将车机坐标置成地图坐标 _rsEfInfo += _lng + "," + _lat + ";"; } _rsEfInfo = _rsEfInfo.Substring(0, _rsEfInfo.Length - 1); //去掉最后一个";" } return(_rsEfInfo); }
public void TestLatticeCornerPathing() { var result = Rectify.MakeRectangles(GridLatticeTestData.CornersLattice()); Assert.AreEqual(14, result.Count, "Did not get 23 initial rectangles as expected"); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); var resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(1, 0)); Assert.AreEqual(2, resultPath.Count, "Did not find a path of 2 where expected"); Assert.AreEqual(new Position(0, 0), resultPath[0]); Assert.AreEqual(new Position(1, 0), resultPath[1]); }
public void DisjointHatTest() { var result = Rectify.GetRectNodes(TestData.DisjointHat(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); var polygons = Rectify.FindVertsFromEdges(output); var subpolygons = Rectify.FirstLevelDecomposition(polygons[0]); Assert.AreEqual(3, subpolygons.Count, "Didn't get 3 subpolygon as expected"); Assert.AreEqual(4, subpolygons[0].Vertices.Count, "Had wrong number of vertices for main square"); List <RectShape> subsubPolygons = ValidateRects(subpolygons); Assert.AreEqual(8, subsubPolygons.Count, "Did not decomp into the minimum 8 polygons"); }
public void TestNoPathNecessary() { var result = Rectify.MakeRectangles(GridLatticeTestData.HorizBisectedLattice()); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); var resultPath = pathfinder.CalculatePath(new Position(2, 0), new Position(2, 4)); Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected"); pathfinder.ReplaceCellEdgeAt(new Position(2, 2), Direction.North, EdgeType.None); resultPath = pathfinder.CalculatePath(new Position(2, 0), new Position(2, 4)); Assert.AreNotEqual(0, resultPath.Count, "Did not generate a non-zero path as expected"); }
public void BinaryConcaveShapeNoHolesPickChordsTest() { var result = Rectify.GetRectNodes(TestData.BinaryConcaveShapeNoHoles(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); var polygons = Rectify.FindVertsFromEdges(output); var subpolygons = Rectify.FirstLevelDecomposition(polygons[1]); Assert.AreEqual(4, subpolygons.Count, "Didn't get 4 subpolygons as expected"); Assert.AreEqual(8, subpolygons[0].Vertices.Count, "Had wrong number of vertices for bottom stair-step shape"); Assert.AreEqual(4, subpolygons[2].Vertices.Count, "Had wrong number of vertices for bottom middle thin shape"); Assert.AreEqual(6, subpolygons[1].Vertices.Count, "Had wrong number of vertices for top bent shape"); Assert.AreEqual(4, subpolygons[3].Vertices.Count, "Had wrong number of vertices for squarish shape"); //perimeters are traversable. foreach (var sp in subpolygons) { bool cycled = false; RectEdge start = sp.Perimeter[0]; RectEdge next = start.Next; for (int i = 0; i < 999; i++) { if (next == start) { cycled = true; break; } next = next.Next; } if (cycled == false) { Assert.Fail("Perimeter did not cycle"); } foreach (RectEdge re in sp.Perimeter) { Position p = re.SecondPosition - re.Next.FirstPosition; if (p.Magnitude != 0) { Assert.Fail("Two edges were not end-to-end"); } Position q = re.FirstPosition - re.Next.FirstPosition; if (q.Magnitude != 1) { Assert.Fail("Two edges were further than 1 apart"); } } } }
public void LPathTest() { List <RectDetectPair> edges = new List <RectDetectPair> { new RectDetectPair(0, 3, EdgeType.Aperture) }; var result = Rectify.MakeRectangles(TestData.LPathTest(), DataLayout.CodeInitializedArray, edgeOverrides: edges); var pathfinder = new RectifyPathfinder(result, StandardParams); var resultPath = pathfinder.CalculatePath(new Position(1, 6), new Position(7, 0), (int)EdgeType.None | (int)EdgeType.Aperture); Assert.AreNotEqual(13, resultPath.Count, "failed to find a path as expected"); }
public void BinaryConcaveShapeNoHolesTraverseShapesTest() { var result = Rectify.GetRectNodes(TestData.BinaryConcaveShapeNoHoles(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); Assert.AreEqual(4, output.Count, "Did not traverse 4 shapes as expected"); Assert.AreEqual(52, output[0].Perimeter.Count, "Top Left Shape not edged as expected"); Assert.AreEqual(62, output[1].Perimeter.Count, "Yellow Shape not edged as expected"); Assert.AreEqual(34, output[3].Perimeter.Count, "Top Right Shape not edged as expected"); Assert.AreEqual(22, output[2].Perimeter.Count, "Bottom Right Shape not edged as expected"); //52 edges (west) //62 edges (yellow) //34 edges (top right) //22 edges (bottom right) }
public void TestAddToRectangles() { var result = Rectify.MakeRectangles(TestData.UniformRectangle(), DataLayout.CodeInitializedArray); Assert.AreEqual(1, result.Count, "Did not get single rectangle as expected"); var pathfinder = new RectifyPathfinder(result, StandardParams); pathfinder.ReplaceCellAt(new Position(2, 2), 4); Assert.AreEqual(5, pathfinder.NodeCount, "Did not get 5 total rectangles as expected"); var resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(2, 2)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); }
public void BinaryConcaveShapeNoHolesMakePolygonsTest() { var result = Rectify.GetRectNodes(TestData.BinaryConcaveShapeNoHoles(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); var polygons = Rectify.FindVertsFromEdges(output); Assert.AreEqual(4, polygons.Count, "Did not maintain 4 shapes as expected"); Assert.AreEqual(12, polygons[0].Vertices.Count, "Top Left Shape not verticed as expected"); Assert.AreEqual(22, polygons[1].Vertices.Count, "Yellow Shape not verticed as expected"); Assert.AreEqual(8, polygons[3].Vertices.Count, "Top Right Shape not verticed as expected"); Assert.AreEqual(6, polygons[2].Vertices.Count, "Bottom Right Shape not verticed as expected"); Assert.AreEqual(4, polygons[0].Vertices.FindAll(v => v.IsConcave == true).Count, "Had wrong number of concave vertices"); Assert.AreEqual(9, polygons[1].Vertices.FindAll(v => v.IsConcave == true).Count, "Had wrong number of concave vertices"); Assert.AreEqual(2, polygons[3].Vertices.FindAll(v => v.IsConcave == true).Count, "Had wrong number of concave vertices"); Assert.AreEqual(1, polygons[2].Vertices.FindAll(v => v.IsConcave == true).Count, "Had wrong number of concave vertices"); }
public void BiggerSequentialEdgeAdditionTest() { var result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10)); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); //add edges to the same cell one after another pathfinder.ReplaceCellEdgeAt(new Position(6, 4), Direction.West, EdgeType.Wall); pathfinder.ReplaceCellEdgeAt(new Position(6, 4), Direction.South, EdgeType.Wall); pathfinder.ReplaceCellEdgeAt(new Position(7, 4), Direction.West, EdgeType.Wall); var resultPath = pathfinder.CalculatePath(new Position(3, 3), new Position(8, 2)); Assert.AreNotEqual(0, resultPath.Count, "Did not find expected path"); }
public void ExciseHoleTest() { var result = Rectify.GetRectNodes(TestData.ExcisedHoleIsland(), DataLayout.CodeInitializedArray); var output = Rectify.TraverseShapeOutlines(result); var polygons = Rectify.FindVertsFromEdges(output); var subpolygons = new List <RectShape>(); foreach (var p in polygons) { subpolygons.AddRange(Rectify.FirstLevelDecomposition(p)); } foreach (RectShape rs in subpolygons) { Assert.IsTrue(rs.Holes.Count < 2, "Did not get less than 2 holes as expected"); } }
public void TestCacheInvalidated() { var result = Rectify.MakeRectangles(TestData.BigKeyholeTest(), DataLayout.CodeInitializedArray); var pathfinder = new RectifyPathfinder(result, StandardParams); var resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(0, 5)); Assert.AreEqual(8, resultPath.Count, "Did not find a path where expected"); pathfinder.ReplaceCellAt(new Position(2, 4), 2); //either the caching algorithm isn't really working in the first place, or the checks we're already doing //wind up failling with the new rectangles. //This test is moot. resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(0, 5)); Assert.AreEqual(0, resultPath.Count, "Found previous path, cache not invalidated"); }