public void OpenRegion(Point2 _site) { SlopeRegion _regionHi = SlopeRegion.Pool.Take.SetValue(_site, _site.m_left); var _toLeft = _site.m_left.getValue() - _site.getValue(); _regionHi.m_slope = SlopeOf(_toLeft); SlopeRegion _regionLow = SlopeRegion.Pool.Take.SetValue(_site, _site.m_right); var _toRight = _site.m_right.getValue() - _site.getValue(); _regionLow.m_slope = SlopeOf(_toRight); if (_toLeft.y < _toRight.y) { var _temp = _regionHi; _regionHi = _regionLow; _regionLow = _temp; } CheckAddRegion(_regionHi); CheckAddRegion(_regionLow); SetSweepTo(_site.x); }
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); }
public void TurnReion(Point2 _site) { Point2 _right; if (_site.m_right.x > _site.m_left.x) { _right = _site.m_right; } else { _right = _site.m_left; } RemoveEndwith(_site); var _toRight = _right.getValue() - _site.getValue(); SlopeRegion _region = SlopeRegion.Pool.Take.SetValue(_site, _right); _region.m_slope = SlopeOf(_toRight); CheckAddRegion(_region); SetSweepTo(_site.x); }
public bool CrossWith(SimplePolygon _polygon1, SimplePolygon _polygon2) { // _polygon1.ValidateLoop(); // _polygon2.ValidateLoop(); m_rowPoints.Clear(); List <Point2> _polygon1Points = _polygon1.Points; int len1 = _polygon1Points.Count; for (int i = 0; i < len1; i++) { var _pI = _polygon1Points[i]; _pI.m_polygonFlag = 0; m_rowPoints.Add(_pI); } List <Point2> _polygon2Points = _polygon2.Points; int len2 = _polygon2Points.Count; for (int i = 0; i < len2; i++) { var _pI = _polygon2Points[i]; _pI.m_polygonFlag = 1; m_rowPoints.Add(_pI); } //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]; var _sweepLineCheck = _pI.m_polygonFlag == 0 ? m_sweepLine1 : m_sweepLine0; if (_sweepLineCheck.InoutOf(_pI) == InOut.In) { _sweepLineCheck.InoutOf(_pI); _result = true; break; } var _sweepLineStep = _pI.m_polygonFlag == 0 ? m_sweepLine0 : m_sweepLine1; 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 { _sweepLineStep.OpenRegion(_pI); } else if (_toLeft.x < 0 && _toRight.x < 0) //Close Site,remove double slopes { _sweepLineStep.CloseRegion(_pI, _toLeft, _toRight); } else //Turn Site,add single slope { _sweepLineStep.TurnReion(_pI); } } m_rowPoints.Clear(); m_sweepLine0.Clear(); m_sweepLine1.Clear(); return(_result); }