Exemplo n.º 1
0
 private static void CheckFace(
     SubdivisionEdge edge, PointD[] polygon, double area, PointD centroid)
 {
     CollectionAssert.AreEqual(polygon, edge.CyclePolygon);
     Assert.AreEqual(area, edge.CycleArea);
     Assert.AreEqual((area == 0), edge.IsCycleAreaZero);
     if (area != 0)
     {
         Assert.AreEqual(centroid, edge.CycleCentroid);
     }
 }
Exemplo n.º 2
0
        private void OnTimerTick(object sender, EventArgs args)
        {
            if (_division == null)
            {
                return;
            }

            // clear current selections, if any
            if (_nearestEdge >= 0)
            {
                SetNearestEdge(null, 0);
            }
            if (_selectedEdge >= 0)
            {
                SetSelectedEdge(-1);
            }
            if (_selectedVertex >= 0)
            {
                SetSelectedVertex(-1);
            }

            // check if mouse cursor is over subdivision
            Point cursor = Mouse.GetPosition(OutputBox);

            if (cursor.X < 0 || cursor.X >= OutputBox.Width ||
                cursor.Y < 0 || cursor.Y >= OutputBox.Height)
            {
                return;
            }

            // show nearest half-edge, if any
            PointD          q = cursor.ToPointD();
            double          distance;
            SubdivisionEdge edge = _division.FindNearestEdge(q, out distance);

            if (edge != null)
            {
                SetNearestEdge(edge, distance);
                if (distance <= 30)
                {
                    SetSelectedEdge(edge.Key);
                }
            }

            // show nearest vertex, if any
            var vertices = _division.Vertices;

            if (vertices.Count > 0)
            {
                var vertexComparer = (PointDComparerY)vertices.Comparer;
                int index          = vertexComparer.FindNearest(vertices.Keys, q);
                SetSelectedVertex(index);
            }
        }
Exemplo n.º 3
0
        private void SetNearestEdge(SubdivisionEdge edge, double distance)
        {
            NearestDistance.Content = distance.ToString("##0.00");

            if (edge == null)
            {
                _nearestEdge        = -1;
                NearestEdge.Content = -1;
                NearestFace.Content = -1;
            }
            else
            {
                _nearestEdge        = edge.Key;
                NearestEdge.Content = edge.Key;
                NearestFace.Content = edge.Face.Key;
            }
        }