Exemple #1
0
        private void ComputeCrossPoints()
        {
            int  preIdx     = 0;
            bool preIsRight = _originalPoints[preIdx].X >= _X;
            bool isRight    = false;

            for (int i = 1; i < _originalPoints.Count; i++)
            {
                preIsRight = _originalPoints[preIdx].X >= _X;
                isRight    = _originalPoints[i].X >= _X;
                if (isRight ^ preIsRight)
                {
                    CrossPoint pt = new CrossPoint(new ShapePoint(_X, (_originalPoints[preIdx].Y + _originalPoints[i].Y) / 2d), -1);//unsort
                    _crossPoints.Add(pt);
                }
                preIdx = i;
            }
            if (_crossPoints.Count > 0)
            {
                _crossPoints.Sort();
                for (int i = 0; i < _crossPoints.Count; i++)
                {
                    _crossPoints[i].Index = i;
                }
            }
        }
Exemple #2
0
        private void GetActivePart(ShapePoint pt, ShapePoint prePoint)
        {
            CrossPoint crossPt = null;

            //获取跨分割线的交点
            if (prePoint != null)
            {
                crossPt = GetCrossPoint(pt, prePoint);
                if (crossPt == null)
                {
                    throw new Exception("获取一对点的交点失败。"); //不会出现这样的错误。
                }
            }
            //
            if (_activePartCollection.Count == 0)
            {
                _activePart = new PartStatus();
                _activePartCollection.Add(_activePart);
                goto endLine;
            }
            else
            {
                //获取相邻的环
                foreach (PartStatus part in _activePartCollection)
                {
                    bool isLessThan = false;
                    if (part.IsNear(crossPt.Index, out isLessThan))//相邻
                    {
                        if (_activePartCollection.Equals(_leftParts) && isLessThan)
                        {
                            _activePart = part;
                            goto endLine;
                        }
                        if ((_activePartCollection.Equals(_rightParts) && !isLessThan))
                        {
                            _activePart = part;
                            goto endLine;
                        }
                    }
                }
                _activePart = new PartStatus();
                //将新建的环加入活动环集合
                _activePartCollection.Add(_activePart);
                goto endLine;
            }
endLine:
            //将当前交点与活动环关联
            if (crossPt != null)
            {
                if (_prePartStatus != null)
                {
                    _prePartStatus.AddLinkeCrossPointIndex(crossPt.Index);
                }
            }
            _prePartStatus = _activePart;
        }