Exemplo n.º 1
0
 private void UpdateSiblingConvexDeleting(LinkedListNode <MappedPoint> node)
 {
     if (!IsVertConvex(
             LinkedListExtensions.Previous(node).Value,
             node.Value,
             LinkedListExtensions.Next(node).Value))
     {
         _earsVerts.Remove(node);
         _reflexVerts.Add(node);
         _convexVerts.Remove(node);
     }
     else
     {
         if (!ShouldAddConvexToEar(node))
         {
             _earsVerts.Remove(node);
         }
         else
         {
             if (!_earsVerts.Contains(node))
             {
                 _earsVerts.Add(node);
             }
         }
     }
 }
Exemplo n.º 2
0
        public List <Triangle> Triangulate()
        {
            for (var p = _pointsN.First; p != null; p = p.Next)
            {
                if (IsVertConvex(LinkedListExtensions.Previous(p).Value, p.Value, LinkedListExtensions.Next(p).Value))
                {
                    _convexVerts.Add(p);
                }
                else
                {
                    _reflexVerts.Add(p);
                }
            }

            foreach (var node in _convexVerts)
            {
                if (ShouldAddConvexToEar(node))
                {
                    _earsVerts.Add(node);
                }
            }

            while (_earsVerts.Any())
            {
                CreateTriangle();
            }

            return(_triangles);
        }
Exemplo n.º 3
0
        private List <Edge> IntersectedEdges(Vector2 edgeStart, SliceHierarchy father, Vector2 edgeEnd)
        {
            var interEdges = new List <Edge>();

            for (var p = father.Points.First; p != null; p = p.Next)
            {
                if (p.Value.v2.Equals(edgeStart))
                {
                    continue;
                }

                var areIntersect = WholeSlicePlane.LineSegmentsIntersection(
                    edgeStart,
                    edgeEnd,
                    p.Value.v2,
                    LinkedListExtensions.Next(p).Value.v2, out var interPoint);

                //intersection point with father(outer) points
                if (areIntersect)
                {
                    var point = p.Value.v2.x > LinkedListExtensions.Next(p).Value.v2.x ? p : LinkedListExtensions.Next(p);

                    var edge = new Edge {
                        FDiscret = p, SDiscret = LinkedListExtensions.Next(p), MaxXdiscret = point, Inter = interPoint
                    };
                    interEdges.Add(edge);
                }
            }

            return(interEdges);
        }
Exemplo n.º 4
0
        private void UnionFatherAndChildPoints(SliceHierarchy child, SliceHierarchy father,
                                               LinkedListNode <MappedPoint> childStartPoint, LinkedListNode <MappedPoint> fatherStartPoint)
        {
            var prev = fatherStartPoint;

            for (var p3 = childStartPoint; p3 != LinkedListExtensions.Previous(childStartPoint); p3 = LinkedListExtensions.Next(p3))
            {
                prev = father.Points.AddAfter(prev, p3.Value);
            }

            prev = father.Points
                   .AddAfter(prev, LinkedListExtensions.Previous(childStartPoint).Value);
            prev = father.Points.AddAfter(prev, childStartPoint.Value);
            father.Points.AddAfter(prev, fatherStartPoint.Value);

            father.MaxX = Mathf.Max(father.MaxX, child.MaxX);
        }
Exemplo n.º 5
0
 private void ReverseIfShould(SliceHierarchy sliceHierarchy)
 {
     if (sliceHierarchy.Level % 2 == 0)
     {
         if (!ArePointsCounterClockwise(sliceHierarchy.Points))
         {
             sliceHierarchy.Points = LinkedListExtensions.ReversedLinkedList(sliceHierarchy.Points);
         }
     }
     else
     {
         if (ArePointsCounterClockwise(sliceHierarchy.Points))
         {
             sliceHierarchy.Points = LinkedListExtensions.ReversedLinkedList(sliceHierarchy.Points);
         }
     }
 }
Exemplo n.º 6
0
        private bool ArePolygonsIntersect(SliceHierarchy pol1, SliceHierarchy pol2)
        {
            for (var p1 = pol1.Points.First; p1 != null; p1 = p1.Next)
            {
                for (var p2 = pol2.Points.First; p2 != null; p2 = p2.Next)
                {
                    var areIntersect = LineSegmentsIntersection(p1.Value.v2, LinkedListExtensions.Next(p1).Value.v2, p2.Value.v2,
                                                                LinkedListExtensions.Next(p2).Value.v2, out var interPoint);

                    if (areIntersect)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 7
0
        private int IntersectionCount(SliceHierarchy outerPoints, MappedPoint point)
        {
            var intersectionCount = 0;

            for (var p = outerPoints.Points.First; p != null; p = p.Next)
            {
                var end = new Vector2(1000000f, 0);

                var areIntersect = LineSegmentsIntersection(point.v2,
                                                            end,
                                                            p.Value.v2,
                                                            LinkedListExtensions.Next(p).Value.v2, out var intersection);

                if (areIntersect)
                {
                    intersectionCount++;
                }
            }

            return(intersectionCount);
        }
Exemplo n.º 8
0
        private bool ShouldAddConvexToEar(LinkedListNode <MappedPoint> node)
        {
            for (var p = _pointsN.First; p != null; p = p.Next)
            {
                if (
                    !LinkedListExtensions.Previous(node).Value.v2.Equals(p.Value.v2) &&
                    !node.Value.v2.Equals(p.Value.v2) &&
                    !LinkedListExtensions.Next(node).Value.v2.Equals(p.Value.v2)
                    )
                {
                    if (IsPointInTriangle(
                            p.Value,
                            LinkedListExtensions.Previous(node).Value,
                            node.Value,
                            LinkedListExtensions.Next(node).Value)
                        )
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        private void CreateTriangle()
        {
            var node     = _earsVerts.First();
            var prevNode = LinkedListExtensions.Previous(node);
            var nextNode = LinkedListExtensions.Next(node);

            _earsVerts.Remove(node);
            _triangles.Add(new Triangle(prevNode.Value, node.Value, nextNode.Value));
            _pointsN.Remove(node);

            ////// update convex and reflex and points
            if (_convexVerts.Contains(prevNode))
            {
                UpdateSiblingConvexDeleting(prevNode);
            }

            if (_convexVerts.Contains(nextNode))
            {
                UpdateSiblingConvexDeleting(nextNode);
            }

            if (_convexVerts.Contains(node))
            {
                _convexVerts.Remove(node);
            }

            if (_reflexVerts.Contains(prevNode))
            {
                UpdateSiblingReflexDeleting(prevNode);
            }

            if (_reflexVerts.Contains(nextNode))
            {
                UpdateSiblingReflexDeleting(nextNode);
            }
        }