public void testLinesDoIntesectT3() { var a0 = new Vector(-1, 0); var a1 = new Vector(0, 0); var b0 = new Vector(-1, -1); var b1 = new Vector(-1, 1); Assert.AreEqual(true, LevelLine.LinesIntersect(a0, a1, b0, b1)); Assert.AreEqual(true, LevelLine.LinesIntersect(a1, a0, b0, b1)); Assert.AreEqual(true, LevelLine.LinesIntersect(a0, a1, b1, b0)); Assert.AreEqual(true, LevelLine.LinesIntersect(a1, a0, b0, b1)); }
public void testLinesDontIntesectF2() { var a0 = new Vector(-4, 4); var a1 = new Vector(-2, 1); var b0 = new Vector(-2, 3); var b1 = new Vector(0, 0); Assert.AreEqual(false, LevelLine.LinesIntersect(a0, a1, b0, b1)); Assert.AreEqual(false, LevelLine.LinesIntersect(a1, a0, b0, b1)); Assert.AreEqual(false, LevelLine.LinesIntersect(a0, a1, b1, b0)); Assert.AreEqual(false, LevelLine.LinesIntersect(a1, a0, b0, b1)); }
public void testLinesDontIntesectF8() { var a0 = new Vector(0, 5); var a1 = new Vector(6, 1); var b0 = new Vector(2, 1); var b1 = new Vector(2, 2); Assert.AreEqual(false, LevelLine.LinesIntersect(a0, a1, b0, b1)); Assert.AreEqual(false, LevelLine.LinesIntersect(a1, a0, b0, b1)); Assert.AreEqual(false, LevelLine.LinesIntersect(a0, a1, b1, b0)); Assert.AreEqual(false, LevelLine.LinesIntersect(a1, a0, b0, b1)); }
public void testLinesDontIntesectF1() { var a0 = new Vector(0, 0); var a1 = new Vector(7, 7); var b0 = new Vector(3, 4); var b1 = new Vector(4, 5); Assert.AreEqual(false, LevelLine.LinesIntersect(a0, a1, b0, b1)); Assert.AreEqual(false, LevelLine.LinesIntersect(a1, a0, b0, b1)); Assert.AreEqual(false, LevelLine.LinesIntersect(a0, a1, b1, b0)); Assert.AreEqual(false, LevelLine.LinesIntersect(a1, a0, b0, b1)); }
public void IsPointOnLineTest() { var a0 = new Vector(0, 0); var a1 = new Vector(4, 4); var p = new Vector(3, 3); Assert.AreEqual(false, LevelLine.IsPointRightOfLine(a0, a1, p)); a0 = new Vector(0, 0); a1 = new Vector(4, 4); Assert.AreEqual(false, LevelLine.IsPointRightOfLine(a0, a1, p)); }
/* +-----------------------------+ | Hooke Jeeves method | +-----------------------------+ */ private void methodHookeJeeves(Double _startX1, Double _startX2, Double _step, Double _accuracy) { chart3.Series.Clear(); LevelLine ll = new LevelLine(chart3); HookeJeeves hookeJeeves = new HookeJeeves(); Extremums ec = hookeJeeves.extremumFunction(_startX1, _startX2, _step, _accuracy); String answer = "Экстремум " + ec.getExtremum().ToString() + " x1= " + ec.getX1() + " x2 = " + ec.getX2(); MessageBox.Show(answer); textBox1.Visible = true; textBox1.Text = answer; List <Extremums> extremumCoordinatesList = hookeJeeves.getExtremumsList(); Series series = new Series("way"); Series seriesPoint = new Series("point"); series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; series.Color = System.Drawing.Color.Black; series.BorderWidth = 3; dataGridView1.RowCount = extremumCoordinatesList.Count; dataGridView1.ColumnCount = 3; dataGridView1.Columns[0].HeaderText = "X1"; dataGridView1.Columns[1].HeaderText = "X2"; dataGridView1.Columns[2].HeaderText = "MIN"; for (double extremum = 0; extremum < 4; extremum += 0.25) { ll.drawLine(extremum); } for (int i = 0; i < extremumCoordinatesList.Count; i++) { dataGridView1.Rows[i].Cells[0].Value = extremumCoordinatesList[i].getX1(); dataGridView1.Rows[i].Cells[1].Value = extremumCoordinatesList[i].getX2(); dataGridView1.Rows[i].Cells[2].Value = extremumCoordinatesList[i].getExtremum(); double x1 = extremumCoordinatesList[i].getX1(); double x2 = extremumCoordinatesList[i].getX2(); series.Points.AddXY(x1, x2); if (extremumCoordinatesList[i].getExtremum() == ec.getExtremum()) { this.label1.Text = Math.Round(extremumCoordinatesList[i].getExtremum(), 2).ToString(); this.label2.Text = Math.Round(extremumCoordinatesList[i].getX1(), 2).ToString(); this.label3.Text = Math.Round(extremumCoordinatesList[i].getX2(), 2).ToString(); ll.pointExtremum(extremumCoordinatesList[i].getX1(), extremumCoordinatesList[i].getX2()); } } chart3.Series.Add(series); }
private Geometry CreateGeometry(LevelLine lineData) { var transform = Plotter2D.Viewport.Transform; StreamGeometry geometry = new StreamGeometry(); using (var context = geometry.Open()) { context.BeginFigure(lineData.StartPoint.DataToScreen(transform), false, false); context.PolyLineTo(lineData.OtherPoints.DataToScreenAsList(transform), true, true); } geometry.Freeze(); return(geometry); }
public void AddPointTest() { testDummy = new LevelLine(0.7); Assert.AreEqual(0.7, testDummy.Value, 0.001); testDummy.AddPoints(new double[][] { new double[] { -2, -3 }, new double[] { -2, -1 }, new double[] { -1, 1 }, new double[] { 1, 2 }, new double[] { 1, 3 }, new double[] { -1.5, 4 } }); Assert.AreEqual(6, testDummy.Count); }
LevelLine GetActiveLine() { LevelLine line = null; if (lineType == LevelLineTypes.FLOOR && selectedLine >= 0 && selectedLine < level.Floors.Count) { line = level.Floors[selectedLine]; } if (lineType == LevelLineTypes.WALL && selectedLine >= 0 && selectedLine < level.Walls.Count) { line = level.Walls[selectedLine]; } return(line); }
public void Clear() { if (Floors != null) { for (int i = 0; i < Floors.Count; ++i) { Floors[i].Clear(); } Floors.Clear(); } if (Walls != null) { for (int i = 0; i < Walls.Count; ++i) { Walls[i].Clear(); } Walls.Clear(); } if (bottomEdge != null) { bottomEdge.Clear(); bottomEdge = null; } if (topEdge != null) { topEdge.Clear(); topEdge = null; } if (leftEdge != null) { leftEdge.Clear(); leftEdge = null; } if (rightEdge != null) { rightEdge.Clear(); rightEdge = null; } if (linesParent == null) { linesParent = transform.Find("Lines").gameObject; } for (int i = linesParent.transform.childCount - 1; i >= 0; --i) { DestroyImmediate(linesParent.transform.GetChild(i).gameObject); } }
public bool CheckIntersection(LatLonAlt location) { if (layers.Count == 0) { return(false); } if (layers[layers.Count - 1] == null) { return(false); } WarpedDataSource2D <double> dataSource = null;//layers[layers.Count - 1].dataSource; if (dataSource == null) { return(false); } double isolineLayer; bool foundVal = Search(dataSource, new Point(location.LongitudeDegrees, location.LatitudeDegrees), out isolineLayer); if (foundVal) { host.Geometry.RemoveGeometry("RunningLine", "rl"); IsolineCollection collection = isolineBuilder.Build(isolineLayer); LevelLine segment = collection.Lines[0]; //runningIsoline.LineColor = palette.GetColor(segment.Value01); //runningIsoline.Segment = segment; //List<Coordinate2D> points = new List<Coordinate2D>(); //points.Add(new Coordinate2D(segment.StartPoint.X, segment.StartPoint.Y)); //foreach (Point point in segment.OtherPoints) //{ // points.Add(new Coordinate2D(point.X, point.Y)); //} //PolyInfo style = PolyInfo.DefaultPolyline; //style.LineColor = palette.GetColor(segment.Value01); //style.LineWidth = 5; //runningLine = new PolylineGeometry("RunningLine", "rl", new Polyline2(Wgs84CoordinateReferenceSystem.Instance, // Coordinate2DCollection.CreateUnsafe(points.ToArray())), style); } return(foundVal); }
public void testLinesDoIntesectT6() { for (int i = 0; i < 50; i++) { var rnd = new Random(); double ax = rnd.NextDouble(); double ay = rnd.NextDouble(); double bx = rnd.NextDouble(); double by = rnd.NextDouble(); var a0 = new Vector(ax, ay); var a1 = new Vector(bx, by); var b0 = new Vector(ax, ay); var b1 = new Vector(bx, by); Assert.AreEqual(true, LevelLine.LinesIntersect(a0, a1, b0, b1)); Assert.AreEqual(true, LevelLine.LinesIntersect(a1, a0, b0, b1)); Assert.AreEqual(true, LevelLine.LinesIntersect(a0, a1, b1, b0)); Assert.AreEqual(true, LevelLine.LinesIntersect(a1, a0, b0, b1)); } }
public void CrossProductTest() { var l = new List <Vector>(52); l.Add(new Vector(0, 0)); l.Add(new Vector(1, 1)); var rnd = new Random(); for (int i = 0; i < 50; i++) { l.Add(new Vector(rnd.NextDouble(), rnd.NextDouble())); } foreach (var p1 in l) { foreach (var p2 in l) { double diff = LevelLine.CrossProduct(p1, p2) + LevelLine.CrossProduct(p2, p1); Assert.AreEqual(0, diff, LevelLine.EPSILON); } } }
private void updateLevelLine(MouseEventArgs e) { Point mousePosition = e.GetPosition(LevelLineContainer); if (mousePosition.Y < 0 || mousePosition.Y > LevelLineContainer.ActualHeight) { hideLevelLine(); return; } double level = 1 - mousePosition.Y / LevelLineContainer.ActualHeight; LevelLine.SetValue(Canvas.TopProperty, mousePosition.Y); LevelTextBorder.SetValue(Canvas.TopProperty, mousePosition.Y - LevelTextBorder.ActualHeight - 1); LevelTextBorder.SetValue(Canvas.LeftProperty, mousePosition.X); LevelText.Text = Math.Round(level * 100, 2).ToString() + " %"; if (currentDictionary != null) { updateColumnsTransparency(level); } }
public void BoundingBoxesIntersectTest() { Vector v1 = new Vector(-2, 3); Vector v2 = new Vector(0, 3); Vector v3 = new Vector(2, 3); Vector v4 = new Vector(3, 3); Vector v5 = new Vector(-2, 2); Vector v6 = new Vector(0, 2); Vector v7 = new Vector(2, 2); Vector v8 = new Vector(3, 2); Vector v9 = new Vector(-2, 1); Vector v10 = new Vector(0, 1); Vector v11 = new Vector(2, 1); Vector v12 = new Vector(3, 1); Vector v13 = new Vector(-2, 0); Vector v14 = new Vector(0, 0); Vector v15 = new Vector(2, 0); Vector v16 = new Vector(3, 0); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v1, v11, v14, v8)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v5, v8, v14, v3)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v11, v1, v8, v14)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v8, v5, v3, v14)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v1, v16, v7, v10)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v3, v10, v7, v5)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v14, v8, v9, v3)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v3, v3, v3, v3)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v1, v6, v6, v11)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v4, v10, v9, v14)); Assert.AreEqual(true, LevelLine.BoundingBoxesIntersect(v4, v10, v14, v9)); Assert.AreEqual(false, LevelLine.BoundingBoxesIntersect(v1, v6, v16, v11)); Assert.AreEqual(false, LevelLine.BoundingBoxesIntersect(v10, v13, v11, v16)); Assert.AreEqual(false, LevelLine.BoundingBoxesIntersect(v1, v1, v8, v14)); Assert.AreEqual(false, LevelLine.BoundingBoxesIntersect(v7, v4, v12, v13)); }
public override void OnInspectorGUI() { if (Application.isPlaying) { return; } if (GUILayout.Button("Clear")) { level.Clear(); return; } level.Floor = (GameObject)EditorGUILayout.ObjectField("Floor", level.Floor, typeof(GameObject), true); level.Wall = (GameObject)EditorGUILayout.ObjectField("Wall", level.Wall, typeof(GameObject), true); Vector2 size = level.Size; EditorGUI.BeginChangeCheck(); size = EditorGUILayout.Vector2Field("Level Size", size); if (EditorGUI.EndChangeCheck()) { level.Size = size; EditorUtility.SetDirty(level); } lineType = (LevelLineTypes)EditorGUILayout.EnumPopup(lineType); if ((lineType == LevelLineTypes.FLOOR && level.Floors.Count > 0) || (lineType == LevelLineTypes.WALL && level.Walls.Count > 0)) { selectedLine = EditorGUILayout.IntSlider(selectedLine, 0, lineType == LevelLineTypes.FLOOR ? level.Floors.Count - 1 : level.Walls.Count - 1); } else { selectedLine = -1; } if (GUILayout.Button("Add Line")) { level.AddLine(Vector2.zero, lineType); } LevelLine line = GetActiveLine(); if (line == null) { return; } if (GUILayout.Button("Remove Line")) { level.RemoveLine(lineType, selectedLine); return; } Vector2 anchor = line.Anchor; EditorGUI.BeginChangeCheck(); anchor = EditorGUILayout.Vector2Field("Line Anchor", anchor); if (EditorGUI.EndChangeCheck()) { line.Anchor = anchor; } float lineSize = line.Size; EditorGUI.BeginChangeCheck(); lineSize = EditorGUILayout.FloatField("Line Size", lineSize); if (EditorGUI.EndChangeCheck()) { line.Size = lineSize; } }
private void UpdateUIRepresentation() { foreach (var path in linePaths) { LevelLine line = (LevelLine)path.Tag; path.Data = CreateGeometry(line); } var transform = Plotter2D.Viewport.Transform; Rect output = Plotter2D.Viewport.Output; DataRect visible = Plotter2D.Viewport.Visible; if (rebuildText) { foreach (var text in textBlocks) { if (text.Visibility == Visibility.Visible) { content.Children.Remove(text); } } textBlocks.Clear(); double wayBeforeText = new Rect(new Size(100, 100)).ScreenToData(transform).Width; Annotater.WayBeforeText = wayBeforeText; var textLabels = Annotater.Annotate(Collection, Plotter2D.Viewport.Visible); foreach (var textLabel in textLabels) { TextBlock text = CreateTextLabel(textLabel); textBlocks.Add(text); if (visible.Contains(textLabel.Position)) { content.Children.Add(text); } else { text.Visibility = Visibility.Hidden; } } } else { foreach (var text in textBlocks) { IsolineTextLabel label = (IsolineTextLabel)text.Tag; Point screenPos = label.Position.DataToScreen(transform); Size textSize = text.DesiredSize; Point position = new Point(screenPos.X - textSize.Width / 2, screenPos.Y - textSize.Height / 2); if (output.Contains(position)) { Canvas.SetLeft(text, position.X); Canvas.SetTop(text, position.Y); if (text.Visibility == Visibility.Hidden) { text.Visibility = Visibility.Visible; content.Children.Add(text); } } else if (text.Visibility == Visibility.Visible) { text.Visibility = Visibility.Hidden; content.Children.Remove(text); } } } }
public void GetVTest() { var testDummy = new PotentGraff2P(); var testLine = new LevelLine(0); testLine.AddPoint(2, 0); testLine.AddPoint(1.5, 1.5); testLine.AddPoint(0, 2); testLine.AddPoint(0, 5); testDummy.AddElement(testLine.Value, testLine); testLine = new LevelLine(1); testLine.AddPoint(2.5, 0); testLine.AddPoint(2, 2); testLine.AddPoint(1, 3); testLine.AddPoint(0.5, 5); testDummy.AddElement(testLine.Value, testLine); testLine = new LevelLine(2); testLine.AddPoint(3, 0); testLine.AddPoint(3, 2); testLine.AddPoint(2.5, 3); testLine.AddPoint(3.5, 4); testLine.AddPoint(6, 5); testDummy.AddElement(testLine.Value, testLine); testLine = new LevelLine(3); testLine.AddPoint(3.5, 0); testLine.AddPoint(4, 2); testLine.AddPoint(5, 2.5); testLine.AddPoint(6, 1.5); testDummy.AddElement(testLine.Value, testLine); testLine = new LevelLine(4); testLine.AddPoint(4, 0); testLine.AddPoint(5, 1); testLine.AddPoint(6, 0.5); testDummy.AddElement(testLine.Value, testLine); testLine = new LevelLine(5); testLine.AddPoint(4.5, 0); testLine.AddPoint(5, 0.5); testLine.AddPoint(6, 0); testDummy.AddElement(testLine.Value, testLine); Assert.AreEqual(6, testDummy.Count); Assert.AreEqual(0, testDummy.GetV(0, 0), 0.0001); Assert.AreEqual(0, testDummy.GetV(1, 1), 0.0001); Assert.AreEqual(0.5, testDummy.GetV(0.5, 3), 0.1); Assert.AreEqual(0.2, testDummy.GetV(1, 2), 0.2); Assert.AreEqual(1.8, testDummy.GetV(2.5, 4), 0.15); Assert.AreEqual(2.5, testDummy.GetV(5, 3.5), 0.15); Assert.AreEqual(2.9, testDummy.GetV(4.5, 2.5), 0.15); Assert.AreEqual(2, testDummy.GetV(2.5, 3), 0.001); Assert.AreEqual(5, testDummy.GetV(5, 0), 0.0001); Assert.AreEqual(true, testDummy.ValidData()); testLine = new LevelLine(6); testLine.AddPoint(5, 0); testLine.AddPoint(6, 1); testDummy.AddElement(testLine.Value, testLine); Assert.AreEqual(false, testDummy.ValidData()); }