Exemple #1
0
        public bool ContainsPoint(List <Point2> _polygon, Point2 _target)
        {
            int len = _polygon.Count;

            for (int i = 0; i < len; i++)
            {
                m_rowPoints.Add(_polygon[i]);
            }
            //ShowPoints("-----polygon points-----");
            m_rowPoints.Add(_target);
            //sort from left to right
            m_rowPoints.QuickSort();
            //ShowPoints("-----sorted points-----");
            //sweep from left to right
            int  _bufLen = m_rowPoints.Count;
            bool _result = false;

            for (int i = 0; i < _bufLen; i++)
            {
                Point2 _pI = m_rowPoints[i];
                if (_pI == _target)
                {
                    _result = m_sweepLine0.InoutOf(_target) == InOut.In;
                    break;
                }

                Point2  _pIL     = _pI.m_left;
                Point2  _pIR     = _pI.m_right;
                Vector2 _pIV     = _pI.getValue();
                Vector2 _toLeft  = _pIL.getValue() - _pIV;
                Vector2 _toRight = _pIR.getValue() - _pIV;
                if (_toLeft.x > 0 && _toRight.x > 0)      //Open Site,add double slope
                {
                    m_sweepLine0.OpenRegion(_pI);
                }
                else if (_toLeft.x < 0 && _toRight.x < 0) //Close Site,remove double slopes
                {
                    m_sweepLine0.CloseRegion(_pI, _toLeft, _toRight);
                }
                else //Turn Site,add single slope
                {
                    m_sweepLine0.TurnReion(_pI);
                }
            }

            m_rowPoints.Clear();
            m_sweepLine0.Clear();
            return(_result);
        }
Exemple #2
0
 public void SetSweepTo(float x)
 {
     for (int i = 0; i < m_sweepRegions.Count; i++)
     {
         m_sweepRegions[i].SweepTo(x);
     }
     m_sweepRegions.QuickSort();
 }