public void AddGap1() { CircleGap[] gaps = CircleGap.AddGap(null, 20, 50); Assert.AreEqual(1, gaps.Length); Assert.AreEqual(20, gaps[0].startAngle); Assert.AreEqual(50, gaps[0].stopAngle); }
public void DecodeCircleGaps() { CircleGap[] result; result = CircleGap.DecodeGaps(null); Assert.IsNull(result); result = CircleGap.DecodeGaps(""); Assert.IsNull(result); CultureInfo cultureUISave = Thread.CurrentThread.CurrentUICulture; CultureInfo cultureSave = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr"); result = CircleGap.DecodeGaps("45.4:90"); Assert.AreEqual(1, result.Length); Assert.AreEqual(45.4F, result[0].startAngle); Assert.AreEqual(90F, result[0].stopAngle); result = CircleGap.DecodeGaps("-4.3:7.1,98:123.412,180:270"); Assert.AreEqual(3, result.Length); Assert.AreEqual(-4.3F, result[0].startAngle); Assert.AreEqual(7.1F, result[0].stopAngle); Assert.AreEqual(98F, result[1].startAngle); Assert.AreEqual(123.412F, result[1].stopAngle); Assert.AreEqual(180F, result[2].startAngle); Assert.AreEqual(270F, result[2].stopAngle); } finally { Thread.CurrentThread.CurrentCulture = cultureSave; Thread.CurrentThread.CurrentUICulture = cultureUISave; } }
public void EncodeCircleGaps() { Assert.AreEqual("", CircleGap.EncodeGaps(null)); Assert.AreEqual("", CircleGap.EncodeGaps(new CircleGap[0])); Assert.AreEqual("-4.5:8.7", CircleGap.EncodeGaps(new CircleGap[] { new CircleGap(-4.5F, 8.7F) })); Assert.AreEqual("-4.5:8.7,34.1:220", CircleGap.EncodeGaps(new CircleGap[] { new CircleGap(-4.5F, 8.7F), new CircleGap(34.1F, 220F) })); Assert.AreEqual("-4.5:8.7,34.1:220,270:271.0001", CircleGap.EncodeGaps(new CircleGap[] { new CircleGap(-4.5F, 8.7F), new CircleGap(34.1F, 220F), new CircleGap(270F, 271.0001F) })); }
public void RemoveControlGap() { Setup("modes\\speciallegs.ppen"); // Select course 1. controller.SelectTab(1); // Course 1. CheckHighlightedLines(controller, -1, -1); // Click on control 1 to select it. MapViewer.DragAction dragAction = controller.LeftButtonDown(Pane.Map, new PointF(38.6F, -21F), 0.3F); Assert.AreEqual(MapViewer.DragAction.DelayedDrag, dragAction); controller.LeftButtonClick(Pane.Map, new PointF(38.6F, -21F), 0.3F); // Begin the remove gap mode. controller.BeginRemoveGap(); // Should have crosshair cursor ui.MouseMoved(39.0F, -29F, 0.3F); Cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(39.0F, -29F), 0.3F); Assert.AreSame(Cursors.Cross, cursor); // And the adding bend text. Assert.AreEqual(StatusBarText.RemovingControlGap, controller.StatusText); // Check the highlights CourseObj[] highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(1, highlights.Length); Assert.AreEqual(@"Control: control:2 course-control:2 scale:1 location:(37.72384,-22.41992) gaps:112.5:146.25,258.75:303.75", highlights[0].ToString()); // Click to add a gap. dragAction = controller.LeftButtonDown(Pane.Map, new PointF(42.0F, -32F), 0.3F); Assert.AreEqual(MapViewer.DragAction.None, dragAction); // Check the status text ui.MouseMoved(42.0F, -32F, 0.1F); Assert.AreEqual(StatusBarText.DefaultStatus, controller.StatusText); // Check the cursor cursor = controller.GetMouseCursor(Pane.Map, new PointF(42.0F, -32F), 0.3F); Assert.AreSame(Cursors.Default, cursor); // Check the highlights highlights = (CourseObj[])controller.GetHighlights(Pane.Map); Assert.AreEqual(2, highlights.Length); Assert.AreEqual(@"Control: control:2 course-control:2 scale:1 location:(37.72384,-22.41992) gaps:112.5:146.25", highlights[0].ToString()); Assert.AreEqual(@"ControlNumber: control:2 course-control:2 scale:1 text:1 top-left:(35.72,-25.85) font-name:Roboto font-style:Regular font-height:5.57", highlights[1].ToString()); // Make sure the control has a new gap. ControlPoint control = eventDB.GetControl(ControlId(2)); CollectionAssert.AreEqual(CircleGap.ComputeCircleGaps(0xFFFFE3FF), control.gaps[10000]); }
public void MoveStartStopPoint() { CircleGap[] oldGaps = { new CircleGap(-45, 90) }; PointF[] oldPts = CircleGap.GapStartStopPoints(new PointF(5, 7), 10, oldGaps); CircleGap[] newGaps = CircleGap.MoveStartStopPoint(new PointF(5, 7), 10, oldGaps, oldPts[0], new PointF(35, 37)); Assert.AreEqual(1, newGaps.Length); Assert.AreEqual(45, newGaps[0].startAngle); Assert.AreEqual(90, newGaps[0].stopAngle); }
public void GapStartStopPoints() { SymPath path = new SymPath(new PointF[] { new PointF(10, 10), new PointF(10, 0), new PointF(0, 0) }); CircleGap[] gaps = new CircleGap[] { new CircleGap(1, 2), new CircleGap(7, 0.5F), new CircleGap(12, 2) }; PointF[] expected = new PointF[] { new PointF(10, 9), new PointF(10, 7), new PointF(10, 3), new PointF(10, 2.5F), new PointF(8, 0), new PointF(6, 0) }; PointF[] result = CircleGap.GapStartStopPoints(path, gaps); TestUtil.TestEnumerableAnyOrder(result, expected); }
public void AddGap2() { // Add a gap to an existing array. CircleGap[] oldGaps = { new CircleGap(6, 8), new CircleGap(45, 90) }; CircleGap[] gaps = CircleGap.AddGap(oldGaps, -30, 7); Assert.AreEqual(2, gaps.Length); Assert.AreEqual(-30F, gaps[0].startAngle); Assert.AreEqual(8F, gaps[0].stopAngle); Assert.AreEqual(45F, gaps[1].startAngle); Assert.AreEqual(90F, gaps[1].stopAngle); }
public void SimplifyGaps() { CircleGap[] gaps = { new CircleGap(125, 134), new CircleGap(290, 270), new CircleGap(125, 140), new CircleGap(-40, -20), new CircleGap(180, 180), new CircleGap(-30, 45),new CircleGap(50, 100), new CircleGap(-140, -120), new CircleGap(55, 65), new CircleGap(75, 102),new CircleGap(129, 130) }; CircleGap[] expected = { new CircleGap(-40, 45), new CircleGap(50, 102), new CircleGap(125, 140), new CircleGap(220, 240) }; CircleGap[] result = CircleGap.SimplifyGaps(gaps); Assert.AreEqual(expected.Length, result.Length); for (int i = 0; i < result.Length; ++i) { Assert.IsTrue(expected[i] == result[i]); } }
public void MoveStartStopPoint() { SymPath path = new SymPath(new PointF[] { new PointF(10, 10), new PointF(10, 0), new PointF(0, 0) }); CircleGap[] gaps = new CircleGap[] { new CircleGap(1, 2), new CircleGap(7, 0.5F), new CircleGap(12, 2) }; CircleGap[] result = CircleGap.MoveStartStopPoint(path, gaps, new PointF(8, 0), new PointF(8.5F, 0)); CircleGap[] expected = new CircleGap[] { new CircleGap(1, 2), new CircleGap(7, 0.5F), new CircleGap(11.5F, 2.5F) }; TestUtil.TestEnumerableAnyOrder(result, expected); result = CircleGap.MoveStartStopPoint(path, gaps, new PointF(10, 2.5F), new PointF(8, 2)); expected = new CircleGap[] { new CircleGap(1, 2), new CircleGap(7, 1F), new CircleGap(12, 2) }; TestUtil.TestEnumerableAnyOrder(result, expected); }
public void RemoveGap() { CircleGap[] gaps = CircleGap.RemoveGap(null, 40); Assert.IsNull(gaps); CircleGap[] oldGaps = { new CircleGap(6, 8), new CircleGap(45, 90) }; gaps = CircleGap.RemoveGap(oldGaps, 7); Assert.AreEqual(1, gaps.Length); Assert.AreEqual(45, gaps[0].startAngle); Assert.AreEqual(90, gaps[0].stopAngle); oldGaps = new CircleGap[] { new CircleGap(-10, 10) }; gaps = CircleGap.RemoveGap(oldGaps, 355); Assert.IsNull(gaps); }
public void Version100beta2() { TestLoadFile("compatibility\\Sample Event_100b2.ppen"); // Make sure gaps converted correctly. EventDB eventDB = controller.GetEventDB(); ControlPoint control = eventDB.GetControl(ControlId(3)); Assert.AreEqual(2, control.gaps.Count); CollectionAssert.AreEqual(control.gaps[10000], CircleGap.ComputeCircleGaps(0x1FFFFF80)); CollectionAssert.AreEqual(control.gaps[15000], CircleGap.ComputeCircleGaps(0x1FFFFF80)); // Make sure all controls scale, description kind is correct by default. Assert.AreEqual(15000, eventDB.GetEvent().allControlsPrintScale); Assert.AreEqual(DescriptionKind.Symbols, eventDB.GetEvent().allControlsDescKind); }
public void ArcStartSweeps() { CircleGap[] gaps = { new CircleGap(-45, 30), new CircleGap(55, 270), new CircleGap(290, 300) }; float[] result = CircleGap.ArcStartSweeps(gaps); float[] expected = { -30F, -25F, -270F, -20F, -300F, -15F }; Assert.AreEqual(expected.Length, result.Length); for (int i = 0; i < expected.Length; ++i) { Assert.AreEqual(expected[i], result[i]); } result = CircleGap.ArcStartSweeps(null); Assert.AreEqual(0F, result[0]); Assert.AreEqual(360F, result[1]); }
public void GapStartStopPoints() { CircleGap[] gaps = { new CircleGap(-45, 30), new CircleGap(60, 270), new CircleGap(290, 300) }; PointF[] result = CircleGap.GapStartStopPoints(new PointF(7F, 13F), 10F, gaps); PointF[] expected = { new PointF((float)(10.0 * Math.Sqrt(2) / 2 + 7), (float)(10.0 * -Math.Sqrt(2) / 2 + 13)), new PointF((float)(10.0 * Math.Sqrt(3) / 2 + 7), (float)(5 + 13)), new PointF((float)(5 + 7), (float)(10.0 * Math.Sqrt(3) / 2 + 13)), new PointF((float)(7), (float)(-10 + 13)), new PointF((float)(10.0 * Math.Cos(2 * Math.PI * 290 / 360) + 7), (float)(10.0 * Math.Sin(2 * Math.PI * 290 / 360) + 13)), new PointF((float)(10.0 * Math.Cos(2 * Math.PI * 300 / 360) + 7), (float)(10.0 * Math.Sin(2 * Math.PI * 300 / 360) + 13)), }; TestUtil.TestEnumerableAnyOrder(result, expected); result = CircleGap.GapStartStopPoints(new PointF(7F, 13F), 10F, null); Assert.IsNull(result); result = CircleGap.GapStartStopPoints(new PointF(7F, 13F), 10F, new CircleGap[0]); Assert.IsNull(result); }
public void MoveGapsToNewPath() { SymPath oldPath = new SymPath(new PointF[] { new PointF(0, 0), new PointF(10, 10) }); CircleGap[] oldGaps = new CircleGap[] { new CircleGap(1, 2), new CircleGap(7, 0.5F), new CircleGap(12, 2) }; SymPath newPath = new SymPath(new PointF[] { new PointF(10, 10), new PointF(10, 0), new PointF(0, 0) }); CircleGap[] expected = new CircleGap[] { new CircleGap(0.1F, 1.414F), new CircleGap(17.88F, 1.414F) }; CircleGap[] newGaps = CircleGap.MoveGapsToNewPath(oldGaps, oldPath, newPath); // Make sure result and expected match. Assert.AreEqual(expected.Length, newGaps.Length); for (int i = 0; i < newGaps.Length; ++i) { Assert.AreEqual(expected[i].distanceFromStart, newGaps[i].distanceFromStart, 0.01F); Assert.AreEqual(expected[i].length, newGaps[i].length, 0.01F); } }
public void OrderGapAngles() { float a1, a2; bool result; a1 = -15; a2 = -30; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(330, a1); Assert.AreEqual(345, a2); Assert.IsTrue(result); a1 = -30; a2 = -15; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(330, a1); Assert.AreEqual(345, a2); Assert.IsFalse(result); a1 = 270; a2 = 95; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(95, a1); Assert.AreEqual(270, a2); Assert.IsTrue(result); a1 = 275; a2 = -90; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(270, a1); Assert.AreEqual(275, a2); Assert.IsTrue(result); a1 = 265; a2 = -90; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(265, a1); Assert.AreEqual(270, a2); Assert.IsFalse(result); a1 = -300; a2 = 300; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(-60, a1); Assert.AreEqual(60, a2); Assert.IsTrue(result); a1 = 95; a2 = 270; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(95, a1); Assert.AreEqual(270, a2); Assert.IsFalse(result); a1 = -90; a2 = 275; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(270, a1); Assert.AreEqual(275, a2); Assert.IsFalse(result); a1 = 300; a2 = -300; result = CircleGap.OrderGapAngles(ref a1, ref a2); Assert.AreEqual(-60, a1); Assert.AreEqual(60, a2); Assert.IsFalse(result); }
public void ComputeCircleGaps() { CircleGap[] result; result = CircleGap.ComputeCircleGaps(0xFFFFFFFF); Assert.IsNull(result); result = CircleGap.ComputeCircleGaps(0); Assert.AreEqual(1, result.Length); Assert.AreEqual(new CircleGap(-360, 0), result[0]); result = CircleGap.ComputeCircleGaps(0x03FF0060); Assert.AreEqual(2, result.Length); Assert.AreEqual(new CircleGap(-67.5F, 56.25F), result[0]); Assert.AreEqual(new CircleGap(78.75F, 180.0F), result[1]); result = CircleGap.ComputeCircleGaps(0xF3F1006F); Assert.AreEqual(4, result.Length); Assert.AreEqual(new CircleGap(45F, 56.25F), result[0]); Assert.AreEqual(new CircleGap(78.75F, 180F), result[1]); Assert.AreEqual(new CircleGap(191.25F, 225F), result[2]); Assert.AreEqual(new CircleGap(292.5F, 315.0F), result[3]); }
public void RoundTripControlPoints() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); ControlPoint ctl1, ctl2, ctl3, ctl4, ctl5, ctl6, ctl7, ctl8, ctl9, ctl10, ctl11; undomgr.BeginCommand(61, "Command1"); ctl1 = new ControlPoint(ControlPointKind.Start, null, new PointF(5, 0)); ctl1.symbolIds[1] = "2.8"; ctl1.symbolIds[2] = "8.5"; eventDB.AddControlPoint(ctl1); ctl2 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(10, 10)); ctl2.symbolIds[0] = "0.3"; ctl2.symbolIds[1] = "2.4"; ctl2.columnFText = "2m"; ctl2.customCodeLocation = true; ctl2.codeLocationAngle = 97F; eventDB.AddControlPoint(ctl2); ctl3 = new ControlPoint(ControlPointKind.CrossingPoint, null, new PointF(13, -7.8F)); ctl3.symbolIds[0] = "13.2"; ctl3.orientation = 94.5F; eventDB.AddControlPoint(ctl3); ctl4 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(20, -10.5F)); ctl4.symbolIds[1] = "3.7"; ctl4.symbolIds[5] = "12.1"; ctl4.gaps = new Dictionary <int, CircleGap[]>(); ctl4.gaps.Add(15000, CircleGap.ComputeCircleGaps(0xFFFFFFDF)); ctl4.gaps.Add(10000, CircleGap.ComputeCircleGaps(0xFF00FFFF)); ctl4.descriptionText = "very marshy spot"; ctl4.punches = new PunchPattern(); ctl4.punches.size = 9; ctl4.punches.dots = new bool[ctl4.punches.size, ctl4.punches.size]; ctl4.punches.dots[0, 0] = true; ctl4.punches.dots[4, 4] = true; ctl4.punches.dots[8, 8] = true; ctl4.punches.dots[8, 0] = true; eventDB.AddControlPoint(ctl4); ctl5 = new ControlPoint(ControlPointKind.Normal, "GO", new PointF(35.4F, -22.5F)); ctl5.symbolIds[0] = "0.1N"; ctl5.symbolIds[1] = "5.5"; ctl5.symbolIds[2] = "5.2"; ctl5.symbolIds[3] = "10.1"; ctl5.symbolIds[4] = "11.1N"; ctl5.symbolIds[5] = "12.3"; eventDB.AddControlPoint(ctl5); ctl6 = new ControlPoint(ControlPointKind.Finish, null, new PointF(30.3F, -27.11F)); ctl6.symbolIds[0] = "14.2"; eventDB.AddControlPoint(ctl6); ctl7 = new ControlPoint(ControlPointKind.Normal, "QX", new PointF(43, 7.1F)); ctl7.symbolIds[1] = "3.6"; ctl7.descTextBefore = "hi there"; ctl7.descTextAfter = "bye there"; eventDB.AddControlPoint(ctl7); ctl8 = new ControlPoint(ControlPointKind.MapExchange, null, new PointF(133, 7.8F)); ctl8.symbolIds[0] = "13.5"; eventDB.AddControlPoint(ctl8); ctl9 = new ControlPoint(ControlPointKind.MapIssue, null, new PointF(40.3F, -7.11F)); ctl9.symbolIds[0] = "13.6"; ctl9.mapIssueKind = MapIssueKind.Beginning; eventDB.AddControlPoint(ctl9); ctl10 = new ControlPoint(ControlPointKind.MapIssue, null, new PointF(-17.2F, 7.01F)); ctl10.symbolIds[0] = "13.6"; ctl10.mapIssueKind = MapIssueKind.Middle; eventDB.AddControlPoint(ctl10); ctl11 = new ControlPoint(ControlPointKind.MapIssue, null, new PointF(1.3F, 14.5F)); ctl11.symbolIds[0] = "13.6"; ctl11.mapIssueKind = MapIssueKind.End; eventDB.AddControlPoint(ctl11); undomgr.EndCommand(61); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); TestUtil.TestEnumerableAnyOrder(eventDB.AllControlPointPairs, new KeyValuePair <Id <ControlPoint>, ControlPoint>[] { new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(1), ctl1), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(2), ctl2), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(3), ctl3), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(4), ctl4), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(5), ctl5), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(6), ctl6), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(7), ctl7), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(8), ctl8), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(9), ctl9), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(10), ctl10), new KeyValuePair <Id <ControlPoint>, ControlPoint>(ControlId(11), ctl11) } ); }
public void RoundTripLeg() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); Leg leg1, leg2, leg3, leg4, leg5, leg6; ControlPoint ctl1, ctl2; Id <ControlPoint> ctlId1, ctlId2; undomgr.BeginCommand(81, "Command1"); ctl1 = new ControlPoint(ControlPointKind.Normal, "31", new PointF(10, 10)); ctl1.symbolIds[0] = "0.3"; ctl1.symbolIds[1] = "2.4"; ctl1.columnFText = "2m"; ctlId1 = eventDB.AddControlPoint(ctl1); ctl2 = new ControlPoint(ControlPointKind.Normal, "32", new PointF(20, -10.5F)); ctl2.symbolIds[1] = "3.7"; ctl2.symbolIds[5] = "12.1"; ctl2.gaps = new Dictionary <int, CircleGap[]>(); ctl2.gaps.Add(15000, CircleGap.ComputeCircleGaps(0xFFFFFFDF)); ctl2.gaps.Add(10000, CircleGap.ComputeCircleGaps(0xFF00FFFF)); ctl2.descriptionText = "very marshy spot"; ctlId2 = eventDB.AddControlPoint(ctl2); leg1 = new Leg(ctlId1, ctlId2); eventDB.AddLeg(leg1); leg2 = new Leg(ctlId1, ctlId2); leg2.flagging = FlaggingKind.All; eventDB.AddLeg(leg2); leg3 = new Leg(ctlId1, ctlId2); leg3.flagging = FlaggingKind.Begin; leg3.flagStartStop = new PointF(5, -7.5F); leg3.bends = new PointF[2] { leg3.flagStartStop, new PointF(17, 6) }; eventDB.AddLeg(leg3); leg4 = new Leg(ctlId1, ctlId2); leg4.flagging = FlaggingKind.End; leg4.flagStartStop = new PointF(5, -7.5F); leg4.bends = new PointF[1] { leg4.flagStartStop }; leg4.gaps = new LegGap[2] { new LegGap(2, 0.3F), new LegGap(3.4F, 0.4F) }; eventDB.AddLeg(leg4); leg5 = new Leg(ctlId1, ctlId2); leg5.gaps = new LegGap[3] { new LegGap(0.9F, 0.3F), new LegGap(3.4F, 0.4F), new LegGap(4.5F, 1.1F) }; eventDB.AddLeg(leg5); leg6 = new Leg(ctlId1, ctlId2); leg6.flagging = FlaggingKind.IssuePointMiddle; leg6.flagStartStop = new PointF(5, -7.5F); leg6.bends = new PointF[1] { leg6.flagStartStop }; eventDB.AddLeg(leg6); undomgr.EndCommand(81); eventDB.Validate(); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); eventDB.Validate(); TestUtil.TestEnumerableAnyOrder(eventDB.AllLegPairs, new KeyValuePair <Id <Leg>, Leg>[] { new KeyValuePair <Id <Leg>, Leg>(LegId(1), leg1), new KeyValuePair <Id <Leg>, Leg>(LegId(2), leg2), new KeyValuePair <Id <Leg>, Leg>(LegId(3), leg3), new KeyValuePair <Id <Leg>, Leg>(LegId(4), leg4), new KeyValuePair <Id <Leg>, Leg>(LegId(5), leg5), new KeyValuePair <Id <Leg>, Leg>(LegId(6), leg6) } ); }