Exemplo n.º 1
0
        public VoronoiDiagram(Vector3[] inputPoints, VBorder border)
        {
            m_border    = border;
            m_parabolas = new List <VParabola>();
            Edges       = new List <VEdge>();
            Vertices    = new List <Vector3>();

            m_eventQueues = new List <VEvent>();
            for (int i = 0; i < inputPoints.Length; i++)
            {
                m_eventQueues.Add(new VEvent(inputPoints[i], true));
            }
            SortEventQueues();

            while (m_eventQueues.Count > 0)
            {
                VEvent currentEvent = m_eventQueues[0];
                m_eventQueues.RemoveAt(0);

                m_ly = currentEvent.Site.z;

                if (currentEvent.IsSiteEvent)
                {
                    AddSiteEvent(currentEvent.Site, m_ly);
                }
                else
                {
                    AddCircleEvent(currentEvent);
                }
            }

            FinishEdge();
        }
Exemplo n.º 2
0
        public void Finish(VBorder border)
        {
            if (!m_hasVertex)
            {
                float x = 0;

                if (m_direction == Direction.Left)
                {
                    x = -border.HalfWidth;
                }
                else
                {
                    x = border.HalfWidth;
                }

                if (!IsInfinityLerp())
                {
                    float z = m_lerp * x + m_intercept;

                    if (z > border.HalfHeight || z < -border.HalfHeight)
                    {
                        z = Mathf.Clamp(z, -border.HalfHeight, border.HalfHeight);
                        x = (z - m_intercept) / m_lerp;
                    }

                    SetVertexPoint(new Vector3(x, 0, z));
                }
                else
                {
                    SetVertexPoint(new Vector3(EndPoint.x, 0, -border.HalfHeight));
                }
            }

            if (StartPoint.x < -border.HalfWidth ||
                StartPoint.x > border.HalfWidth ||
                StartPoint.z < -border.HalfHeight ||
                StartPoint.z > border.HalfHeight)
            {
                if (StartPoint.x < -border.HalfWidth || StartPoint.x > border.HalfWidth)
                {
                    StartPoint.x = Mathf.Clamp(StartPoint.x, -border.HalfWidth, border.HalfWidth);

                    if (!IsInfinityLerp())
                    {
                        StartPoint.z = m_lerp * StartPoint.x + m_intercept;

                        if (StartPoint.z < -border.HalfHeight || StartPoint.z > border.HalfHeight)
                        {
                            StartPoint.z = Mathf.Clamp(StartPoint.z, -border.HalfHeight, border.HalfHeight);
                            StartPoint.x = (StartPoint.z - m_intercept) / m_lerp;
                        }
                    }
                }
                else
                {
                    StartPoint.z = Mathf.Clamp(StartPoint.z, -border.HalfHeight, border.HalfHeight);
                    StartPoint.x = (StartPoint.z - m_intercept) / m_lerp;

                    if (StartPoint.x < -border.HalfWidth || StartPoint.x > border.HalfWidth)
                    {
                        StartPoint.x = Mathf.Clamp(StartPoint.x, -border.HalfWidth, border.HalfWidth);
                        StartPoint.z = m_lerp * StartPoint.x + m_intercept;
                    }
                }
            }

            if (VertexPoint.x < -border.HalfWidth ||
                VertexPoint.x > border.HalfWidth ||
                VertexPoint.z < -border.HalfHeight ||
                VertexPoint.z > border.HalfHeight)
            {
                if (VertexPoint.x < -border.HalfWidth || VertexPoint.x > border.HalfWidth)
                {
                    VertexPoint.x = Mathf.Clamp(VertexPoint.x, -border.HalfWidth, border.HalfWidth);

                    if (!IsInfinityLerp())
                    {
                        VertexPoint.z = m_lerp * VertexPoint.x + m_intercept;

                        if (VertexPoint.z < -border.HalfHeight || VertexPoint.z > border.HalfHeight)
                        {
                            VertexPoint.z = Mathf.Clamp(VertexPoint.z, -border.HalfHeight, border.HalfHeight);
                            VertexPoint.x = (VertexPoint.z - m_intercept) / m_lerp;
                        }
                    }
                }
                else
                {
                    VertexPoint.z = Mathf.Clamp(VertexPoint.z, -border.HalfHeight, border.HalfHeight);
                    VertexPoint.x = (VertexPoint.z - m_intercept) / m_lerp;

                    if (VertexPoint.x < -border.HalfWidth || VertexPoint.x > border.HalfWidth)
                    {
                        VertexPoint.x = Mathf.Clamp(VertexPoint.x, -border.HalfWidth, border.HalfWidth);
                        VertexPoint.z = m_lerp * VertexPoint.x + m_intercept;
                    }
                }
            }
        }