private void btnApply_Click(object sender, EventArgs e) { if (activeParcour != null && comboBoxPoint.SelectedItem != null) { if (activeParcour.Line.Count(p => p.Type == (int)comboBoxPoint.SelectedItem) == 1) { Line l = activeParcour.Line.First(p => p.Type == (int)comboBoxPoint.SelectedItem); Vector a = new Vector(l.A.longitude, l.A.latitude, 0); Vector b = new Vector(l.B.longitude, l.B.latitude, 0); Vector m = Vector.Middle(a, b); Vector neu = new Vector((double)manualPointLongitude.Value, (double)manualPointLatitude.Value, 0); Vector diff = neu - m; l.A.longitude += diff.X; l.A.latitude += diff.Y; l.O.longitude += diff.X; l.O.latitude += diff.Y; l.B.longitude += diff.X; l.B.latitude += diff.Y; List<Point> connectedPoints = findConnectedPoints(activeParcour.Line, l.A, l); foreach (Point p in connectedPoints) { if (p != l.A && p != l.B && p != l.O) { p.longitude += diff.X; p.latitude += diff.Y; } } PictureBox1.Invalidate(); btnRecalc_Click(null, null); } } }
public ParcourChannel(Vector Start, Vector End, LineType type, List<Line> lines, Converter c) { this.Start = Start; this.End = End; List<Line> pointLine = lines.Where(p => p.Type == (int)LineType.Point).ToList(); int i = 0; if (type == LineType.START_B) { i = 9; } else if (type == LineType.START_C) { i = 18; } else if (type == LineType.START_D) { i = 27; } List<Line> corridorPoints = new List<Line>(); for (int j = 0; j < 9; j++) { corridorPoints.Add(pointLine[i + j]); } foreach (Line l in corridorPoints) { Vector v = ParcourModel.getVector(c, l.A); if (isEdited(l)) { ImmutablePoints.Add(v); } LinearCombinations.Add(v); } LinearCombinations.Add(End); }
public void AbsTest() { Vector a = new Vector(0,3,4); double expected = 5F; double actual; actual = Vector.Abs(a); Assert.AreEqual(expected, actual); }
public void AngleClockwiseTest3() { Vector a = new Vector(0, 10, 0); Vector b = new Vector(0, 0, 0); Vector c = new Vector(10, 0, 0); double expected = Math.PI / 2; double actual; actual = Vector.AngleClockwise(a, b, c); Assert.AreEqual(expected, actual); }
public ParcourChannelSingle(ParcourChannelSingle pc) { this.Start = pc.Start; this.End = pc.End; foreach (Vector v in pc.LinearCombinations) { Vector vec = new Vector(v); LinearCombinations.Add(vec); if (pc.ImmutablePoints.Contains(v)) { ImmutablePoints.Add(vec); } } }
public ParcourChannelSingle(Vector Start, Vector End, Converter c) { this.Start = Start; this.End = End; Vector StartEnd = Vector.Direction(Start, End); for (int i = 0; i < 10; i++) { Vector linComb = Start + (StartEnd * (i / 9.0)); LinearCombinations.Add(linComb); } double dist = getDistance(c); double straightDist = getDistanceStraight(c); if (dist - straightDist > 0.1) { System.Console.Out.WriteLine("ERROR"); } }
public void VectorConstructorTest() { Vector v = new Vector(1,2,3); Vector target = new Vector(v); Assert.AreEqual(v,target); }
public void op_SubtractionTest() { Vector a = new Vector(30,40,50); Vector b = new Vector(2,3,4); Vector expected = new Vector(28,37,46); Vector actual; actual = (a - b); Assert.AreEqual(expected, actual); }
public void op_MultiplyTest() { Vector a = new Vector(2,3,4); Vector b = new Vector(2, 3, 4); double expected = 2*2+3*3+4*4; double actual; actual = (a * b); Assert.AreEqual(expected, actual); }
public void MinDistanceTest() { Vector Start = new Vector(0, 0, 0); Vector End = new Vector(2, 0, 0); Vector Point = new Vector(1, 0, 2); Vector expected = new Vector(0, 0, 2); Vector actual; actual = Vector.MinDistance(Start, End, Point); Assert.AreEqual(expected, actual); }
public void AngleTest2() { Vector a = new Vector(0, 10, 0); Vector b = new Vector(0, 0, 0); Vector c = Vector.Middle(a, new Vector(10, 0, 0)); double expected = Math.PI / 4; double actual; actual = Vector.Angle(a, b, c); Assert.IsTrue(Math.Abs(expected - actual) < 0.00000000001); }
private void PictureBox1_MouseMove(object sender, MouseEventArgs e) { fldCursorX.Text = e.X.ToString(); fldCursorY.Text = e.Y.ToString(); if (c != null) { double latitude = c.YtoLatitude(e.Y); double longitude = c.XtoLongitude(e.X); fldLatitude.Text = latitude.ToString(); fldLongitude.Text = longitude.ToString(); if (drag && (hoverPoint != null || dragPoint != null)) { if (dragPoint == null) { dragPoint = hoverPoint; } double newLatitude = c.YtoLatitude(e.Y); double newLongitude = c.XtoLongitude(e.X); double oldLat = dragPoint.latitude; double oldLong = dragPoint.longitude; dragPoint.latitude = newLatitude; dragPoint.longitude = newLongitude; //TODO dragPoint.edited = true; foreach (Point p in gluePoints) { p.latitude = newLatitude; p.longitude = newLongitude; //TODO p.edited = true; } foreach (Point p in connectedPoints) { if (p != dragPoint) { p.latitude = dragPoint.latitude + (p.latitude - oldLat); p.longitude = dragPoint.longitude + (p.longitude - oldLong); //TODO p.edited = true; } } PictureBox1.Invalidate(); } else { dragPoint = null; bool pointSet = false; lock (activeParcour) { foreach (Line l in activeParcour.Line) { int startX = c.getStartX(l); int startY = c.getStartY(l); int endX = c.getEndX(l); int endY = c.getEndY(l); int midX = startX + (endX - startX) / 2; int midY = startY + (endY - startY) / 2; int orientationX = c.getOrientationX(l); int orientationY = c.getOrientationY(l); Vector mousePos = new Vector(e.X, e.Y, 0); if (Vector.Abs(mousePos - new Vector(startX, startY, 0)) < 3) { SetHoverPoint(l.A, l); gluePoints.Clear(); gluePoints.AddRange(findGluePoints(activeParcour.Line, l.A)); connectedPoints.Clear(); connectedPoints.AddRange(findConnectedPoints(activeParcour.Line, l.A, l)); pointSet = true; PictureBox1.Cursor = move; break; } else if (Vector.Abs(mousePos - new Vector(endX, endY, 0)) < 3) { SetHoverPoint(l.B, l); gluePoints.Clear(); gluePoints.AddRange(findGluePoints(activeParcour.Line, l.B)); connectedPoints.Clear(); connectedPoints.AddRange(findConnectedPoints(activeParcour.Line, l.B, l)); pointSet = true; PictureBox1.Cursor = move; break; } else if (Vector.Abs(mousePos - new Vector(orientationX, orientationY, 0)) < 3) { SetHoverPoint(l.O, l); gluePoints.Clear(); gluePoints.AddRange(findGluePoints(activeParcour.Line, l.O)); connectedPoints.Clear(); connectedPoints.AddRange(findConnectedPoints(activeParcour.Line, l.O, l)); pointSet = true; PictureBox1.Cursor = move; break; } } } if (!pointSet) { SetHoverPoint(null, null); PictureBox1.Cursor = select; } } } }
private void comboBoxPoint_SelectedIndexChanged(object sender, EventArgs e) { if (activeParcour != null && comboBoxPoint.SelectedItem != null) { if (activeParcour.Line.Count(p => p.Type == (int)comboBoxPoint.SelectedItem) == 1) { Line l = activeParcour.Line.First(p => p.Type == (int)comboBoxPoint.SelectedItem); Vector a = new Vector(l.A.longitude, l.A.latitude, 0); Vector b = new Vector(l.B.longitude, l.B.latitude, 0); Vector m = Vector.Middle(a, b); manualPointLatitude.Value = (decimal)m.Y; manualPointLongitude.Value = (decimal)m.X; } else { manualPointLatitude.Value = 0; manualPointLongitude.Value = 0; } } }
private void PaintParcourAndData(PaintEventArgs pe, bool rescale) { if (Image == null) { return; } float lineThickness = 2f; if (pe != null && pe.ClipRectangle.Bottom == -4) { lineThickness = 7f; } Pen.Width = lineThickness; #region parcour if (Parcour != null && c != null) { int y0 = 0; int x0 = 0; double factor = 1; if (rescale) { double widthFactor = (double)Width / Image.Width; double heightFactor = (double)Height / Image.Height; factor = Math.Min(widthFactor, heightFactor); double factorDiff = Math.Abs(widthFactor - heightFactor); if (widthFactor < heightFactor) { y0 = (int)((Height - (Image.Height * factor)) / 2); } else { x0 = (int)((Width - (Image.Width * factor)) / 2); } } lock (Parcour) { ICollection<Line> lines = Parcour.Line; List<Line> linespenalty = lines.Where(p => p.Type == (int)LineType.PENALTYZONE).ToList(); foreach (Line l in linespenalty) { int startXp = x0 + (int)(c.getStartX(l) * factor); int startYp = y0 + (int)(c.getStartY(l) * factor); int endXp = x0 + (int)(c.getEndX(l) * factor); int endYp = y0 + (int)(c.getEndY(l) * factor); int orientationXp = x0 + (int)(c.getOrientationX(l) * factor); int orientationYp = y0 + (int)(c.getOrientationY(l) * factor); try { pe.Graphics.FillPolygon(Brush, new System.Drawing.Point[] { new System.Drawing.Point(startXp, startYp), new System.Drawing.Point(endXp, endYp), new System.Drawing.Point(orientationXp, orientationYp) }); } catch { //TODO } } foreach (Line l in lines) { if (l.A != null && l.B != null & l.O != null) { int startX = x0 + (int)(c.getStartX(l) * factor); int startY = y0 + (int)(c.getStartY(l) * factor); int endX = x0 + (int)(c.getEndX(l) * factor); int endY = y0 + (int)(c.getEndY(l) * factor); int orientationX = x0 + (int)(c.getOrientationX(l) * factor); int orientationY = y0 + (int)(c.getOrientationY(l) * factor); int midX = startX + (endX - startX) / 2; int midY = startY + (endY - startY) / 2; Vector start = new Vector(startX, startY, 0); Vector midv = new Vector(midX, midY, 0); float radius = (float)Vector.Abs(midv - start); try { if (l.Type != (int)LineType.PENALTYZONE && l.Type != (int)LineType.Point && l.Type != (int)LineType.LINEOFNORETURN) { //Start_X/End_X if (((int)l.Type) >= 3 && ((int)l.Type) <= 10) { pe.Graphics.DrawEllipse(Pen, midX - radius, midY - radius, radius * 2, radius * 2); } pe.Graphics.DrawLine(Pen, new System.Drawing.Point(startX, startY), new System.Drawing.Point(endX, endY)); pe.Graphics.DrawLine(Pen, new System.Drawing.Point(midX, midY), new System.Drawing.Point(orientationX, orientationY)); pe.Graphics.DrawEllipse(Pen, orientationX - 1, orientationY - 1, 2, 2); } } catch { //TODO } } } } } #endregion if (flights != null) { int y0 = 0; int x0 = 0; double factor = 1; if (rescale) { double widthFactor = (double)Width / Image.Width; double heightFactor = (double)Height / Image.Height; factor = Math.Min(widthFactor, heightFactor); double factorDiff = Math.Abs(widthFactor - heightFactor); if (widthFactor < heightFactor) { y0 = (int)((Height - (Image.Height * factor)) / 2); } else { x0 = (int)((Width - (Image.Width * factor)) / 2); } } foreach (Flight flight in flights) { //Color Color = Color.FromName(flight.Team.Color); Color Color = Color.Black; List<System.Drawing.Point> points = new List<System.Drawing.Point>(); foreach (Point gd in flight.Point) { int startXp = x0 + (int)(c.LongitudeToX(gd.longitude) * factor); int startYp = y0 + (int)(c.LatitudeToY(gd.latitude) * factor); points.Add(new System.Drawing.Point(startXp, startYp)); } if (points.Count > 2) { pe.Graphics.DrawLines(new Pen(new SolidBrush(Color), lineThickness), points.ToArray()); } } } }
private void PictureBox1_MouseMove(object sender, MouseEventArgs e) { fldCursorX.Text = e.X.ToString(); fldCursorY.Text = e.Y.ToString(); if (c != null) { double latitude = c.YtoLatitude(e.Y); double longitude = c.XtoLongitude(e.X); fldLatitude.Text = latitude.ToString(); fldLongitude.Text = longitude.ToString(); if (activeLine != null) { PictureBox1.SetSelectedLine(null); #region activeLine != null switch (ap) { case ActivePoint.A: { Point a = Factory.newGPSPoint(longitude, latitude, 0); Point b = Factory.newGPSPoint(a.longitude, a.latitude, a.altitude); Point o = Factory.newGPSPoint(a.longitude, a.latitude, a.altitude); activeLine.A = a; activeLine.B = b; activeLine.O = o; PictureBox1.Invalidate(); break; } case ActivePoint.B: { Point b = Factory.newGPSPoint(longitude, latitude, 0); Point o = Factory.newGPSPoint(b.longitude, b.latitude, b.altitude); activeLine.B = b; activeLine.O = o; PictureBox1.Invalidate(); break; } case ActivePoint.O: { Point o = Factory.newGPSPoint(longitude, latitude, 0); activeLine.O = o; PictureBox1.Invalidate(); break; } case ActivePoint.NONE: { break; } } #endregion } else { bool lineSet = false; lock (activeParcour) { foreach (Line l in activeParcour.Line) { int startX = c.getStartX(l); int startY = c.getStartY(l); int endX = c.getEndX(l); int endY = c.getEndY(l); int midX = startX + (endX - startX) / 2; int midY = startY + (endY - startY) / 2; int orientationX = c.getOrientationX(l); int orientationY = c.getOrientationY(l); Vector mousePos = new Vector(e.X, e.Y, 0); if (Vector.Abs(Vector.MinDistance(new Vector(startX, startY, 0), new Vector(endX, endY, 0), mousePos)) < 3 || Vector.Abs(Vector.MinDistance(new Vector(midX, midY, 0), new Vector(orientationX, orientationY, 0), mousePos)) < 3) { SetHoverLine(l); lineSet = true; break; } } } if (!lineSet) { SetHoverLine(null); } } } }
public void LotInterceptionTest() { Vector Start = new Vector(0,0,0); Vector End = new Vector(2,0,0); Vector Point = new Vector(1,0,2); Vector expected = new Vector(1,0,0); Vector actual; actual = Vector.LotInterception(Start, End, Point); Assert.AreEqual(expected, actual); }
public void MiddleTest() { Vector a = new Vector(10,10,10); Vector b = new Vector(20,20,20); Vector expected = new Vector(15,15,15); Vector actual; actual = Vector.Middle(a, b); Assert.AreEqual(expected, actual); }
public void AngleTest4() { Vector a = new Vector(10, 0, 0); Vector b = new Vector(0, 0, 0); Vector c = new Vector(-10, 0, 0); double expected = Math.PI; double actual; actual = Vector.Angle(a, b, c); Assert.AreEqual(expected, actual); }
public void op_AdditionTest() { Vector a = new Vector(100,99,29); Vector b = new Vector(2,1,2); Vector expected = new Vector(102,100,31); Vector actual; actual = (a + b); Assert.AreEqual(expected, actual); }
public void DirectionTest() { Vector startPoint = new Vector(1,2,3); Vector endPoint = new Vector(2,3,4); Vector expected = new Vector(1,1,1); Vector actual; actual = Vector.Direction(startPoint, endPoint); Assert.AreEqual(expected, actual); }
public void op_DivisionTest() { Vector a = new Vector(100,100,100); double b = 0.5F; Vector expected = new Vector(200, 200, 200); Vector actual; actual = (a / b); Assert.AreEqual(expected, actual); }
public void EqualsTest() { Vector v = new Vector(8,99,234); Vector target = new Vector(8, 99, 234); object obj = v; bool expected = true; bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); }
public void op_MultiplyTest1() { Vector a = new Vector(100,100,100); double b = 100; Vector expected = new Vector(10000,10000,10000); Vector actual; actual = (a * b); Assert.AreEqual(expected, actual); }
public void GetHashCodeTest() { Vector v = new Vector(8, 99, 234); Vector target = new Vector(8, 99, 234); int expected = v.GetHashCode(); int actual; actual = target.GetHashCode(); Assert.AreEqual(expected, actual); }
public void OrthogonalTest() { Vector a = new Vector(10,5,0); Vector expected = new Vector(-5,10,0); Vector actual; actual = Vector.Orthogonal(a); Assert.AreEqual(expected, actual); }
public void InterceptionTest() { Vector LineA_A = new Vector(2, 2, 2); Vector LineA_B = new Vector(-2, -2, -2); Vector LineB_A = new Vector(1, 2, 1); Vector LineB_B = new Vector(1, -1, 1); Vector expected = new Vector(1, 1, 1); Vector actual; actual = Vector.Interception(LineA_A, LineA_B, LineB_A, LineB_B); Assert.AreEqual(expected, actual); }
public void VectorConstructorTest1() { double X = 1F; double Y = 3F; double Z = 2F; Vector target = new Vector(X, Y, Z); Assert.AreEqual(X, target.X); Assert.AreEqual(Y, target.Y); Assert.AreEqual(Z, target.Z); }
public void InterceptionTest2() { Vector LineA_A = new Vector(2, 2, 2); Vector LineA_B = new Vector(-2, -2, -2); Vector LineB_A = new Vector(3, -3, 3); Vector LineB_B = new Vector(-3, 3, -3); Vector expected = new Vector(0, 0, 0); Vector actual; actual = Vector.Interception(LineA_A, LineA_B, LineB_A, LineB_B); Assert.AreEqual(expected, actual); }
public void AngleClockwiseTest4() { Vector a1 = new Vector(9, -11, 0); Vector b1 = new Vector(10, -10, 0); Vector c1 = new Vector(2, -9, 0); double angle1 = Vector.AngleClockwise(a1, b1, c1); Vector a2 = new Vector(9, -11, 0); Vector b2 = new Vector(10, -10, 0); Vector c2 = new Vector(3, 3, 0); double angle2 = Vector.AngleClockwise(a2, b2, c2); Assert.IsTrue(angle1 < angle2); Vector a3 = new Vector(9, -11, 0); Vector b3 = new Vector(10, -10, 0); Vector c3 = new Vector(-10, 5, 0); double angle3 = Vector.AngleClockwise(a3, b3, c3); Assert.IsTrue(angle1 < angle3); Vector a4 = new Vector(9, -11, 0); Vector b4 = new Vector(10, -10, 0); Vector c4 = new Vector(11, -9, 0); double angle4 = Vector.AngleClockwise(a4, b4, c4); Assert.IsTrue(angle1 < angle4); }
public void InterceptionTest4() { Vector LineA_A = new Vector(-2, -2, -2); Vector LineA_B = new Vector(2, 2, 2); Vector LineB_A = new Vector(9, 8, 10); Vector LineB_B = new Vector(8, 8, 10); Vector expected = null; Vector actual; actual = Vector.Interception(LineA_A, LineA_B, LineB_A, LineB_B); Assert.AreEqual(expected, actual); }