Exemplo n.º 1
0
        // This is where the real work is done.
        public void AddLine(double x, double y, double?z, double?m)
        {
            // To unify code for ascending and descending measures - clipPointMeasure
            double?clipPointMeasure = GetClipPointMeasure(m);
            double newX, newY;

            // If current measure is between start measure and end measure,
            // we should add segment to the result linestring
            if (m.IsWithinRange(_clipStartMeasure, _clipEndMeasure))
            {
                // if the geometry is started, just add the point to line
                if (_started)
                {
                    _target.AddLine(x, y, z, m);
                }
                // Else we need to begin the geom figure first
                else
                {
                    var isShapePoint = false;
                    // if clip point is shape point measure then add the point without computation
                    if (m.EqualsTo(clipPointMeasure))
                    {
                        _target.BeginFigure(x, y, null, m);
                        isShapePoint = true;
                    }
                    else
                    {
                        ComputePointCoordinates(clipPointMeasure, m, x, y, out newX, out newY);

                        // if computed point is within tolerance of last point then begin figure with last point
                        if (Ext.IsWithinTolerance(_previousX, _previousY, newX, newY, _tolerance))
                        {
                            _target.BeginFigure(_previousX, _previousY, null, _retainClipMeasure ? _clipStartMeasure : _previousM);
                        }

                        // check with current point against new computed point
                        else if (Ext.IsWithinTolerance(x, y, newX, newY, _tolerance))
                        {
                            _target.BeginFigure(x, y, null, m);
                            isShapePoint = true;
                        }

                        // else begin figure with clipped point
                        else
                        {
                            _target.BeginFigure(newX, newY, null, clipPointMeasure);
                        }
                    }

                    _started = true;
                    if (_clipStartMeasure.EqualsTo(_clipEndMeasure) || isShapePoint)
                    {
                        UpdateLastPoint(x, y, m);
                        return;
                    }

                    _target.AddLine(x, y, z, m);
                }
            }
            // We may still need to add last segment,
            // if current point is the first one after we passed range of interest
            else
            {
                if (!_started)
                {
                    var isShapePoint = false;
                    if (clipPointMeasure.IsWithinRange(m, _previousM))
                    {
                        ComputePointCoordinates(clipPointMeasure, m, x, y, out newX, out newY);

                        // if computed point is within tolerance of last point then begin figure with last point
                        if (Ext.IsWithinTolerance(_previousX, _previousY, newX, newY, _tolerance))
                        {
                            _target.BeginFigure(_previousX, _previousY, null, _retainClipMeasure ? clipPointMeasure : _previousM);
                        }
                        // check with current point against new computed point
                        else if (Ext.IsWithinTolerance(x, y, newX, newY, _tolerance))
                        {
                            _target.BeginFigure(x, y, null, _retainClipMeasure ? clipPointMeasure : m);
                            isShapePoint = true;
                        }
                        // else begin figure with clipped point
                        else
                        {
                            _target.BeginFigure(newX, newY, null, clipPointMeasure);
                        }

                        _started = true;
                        if (_clipStartMeasure.EqualsTo(_clipEndMeasure) || isShapePoint)
                        {
                            UpdateLastPoint(x, y, m);
                            return;
                        }
                    }
                }
                if (_started && !_finished)
                {
                    // re calculate clip point measure as it can be changed from above condition.
                    clipPointMeasure = GetClipPointMeasure(m);

                    if (clipPointMeasure.IsWithinRange(m, _previousM))
                    {
                        ComputePointCoordinates(clipPointMeasure, m, x, y, out newX, out newY);

                        var isWithinLastPoint    = Ext.IsWithinTolerance(_previousX, _previousY, newX, newY, _tolerance);
                        var isWithinCurrentPoint = Ext.IsWithinTolerance(x, y, newX, newY, _tolerance);

                        // if computed point is within tolerance of last point then skip
                        if (!isWithinLastPoint)
                        {
                            // if within current point then add current point
                            if (isWithinCurrentPoint)
                            {
                                _target.AddLine(x, y, null, _retainClipMeasure ? clipPointMeasure : m);
                            }
                            // else add computed point
                            else
                            {
                                _target.AddLine(newX, newY, null, clipPointMeasure);
                            }
                        }

                        _finished = true;
                    }
                }
            }

            // re-assign the current co-ordinates to match for next iteration.
            UpdateLastPoint(x, y, m);
        }