Repository: danielgindi/Charts
File: Source/Charts/Renderers/LineChartRenderer.swift (Swift)

Code before:
                else
                {
                    _lineSegments[1] = CGPoint(x: CGFloat(e.x), y: CGFloat(e.y * phaseY))
                }
            }
            else
            {
                _lineSegments[1] = _lineSegments[0]
            }

            for i in 0..<_lineSegments.count
            {
                _lineSegments[i] = _lineSegments[i].applying(valueToPixelMatrix)
            }
            
            // Determine the start and end coordinates of the line, and make sure they differ.
            guard
                let firstCoordinate = _lineSegments.first,
                let lastCoordinate = _lineSegments.last,
                firstCoordinate != lastCoordinate else { continue }
            
            // If both points lie left of viewport, skip stroking.
            if !viewPortHandler.isInBoundsLeft(firstCoordinate.x) && !viewPortHandler.isInBoundsLeft(lastCoordinate.x) { continue }
            
            // If both points lie right of the viewport, break out early.
            if !viewPortHandler.isInBoundsRight(firstCoordinate.x) && !viewPortHandler.isInBoundsRight(lastCoordinate.x) { break }
            
            // Only stroke the line if it intersects with the viewport.
            guard viewPortHandler.isIntersectingLine(from: firstCoordinate, to: lastCoordinate) else { continue }
            
            // get the color that is set for this line-segment
            context.setStrokeColor(dataSet.color(atIndex: j).cgColor)
            context.strokeLineSegments(between: _lineSegments)
        }
        
        context.restoreGState()
    }
    
    open func drawLinearFill(context: CGContext, dataSet: ILineChartDataSet, trans: Transformer, bounds: XBounds)
    {
        guard let dataProvider = dataProvider else { return }
        
        let filled = generateFilledPath(
            dataSet: dataSet,
            fillMin: dataSet.fillFormatter?.getFillLinePosition(dataSet: dataSet, dataProvider: dataProvider) ?? 0.0,
            bounds: bounds,
            matrix: trans.valueToPixelMatrix)
        
        if dataSet.fill != nil
        {
            drawFilledPath(context: context, path: filled, fill: dataSet.fill!, fillAlpha: dataSet.fillAlpha)

Review comment (suggestion):
I'm not sure if we need to check `&& !viewPortHandler.isInBoundsLeft(lastCoordinate.x)` as well if `firstCoordinate.x` is not `isInBoundsRight`, as we'd expect `firstCoordinate.x` is always <= `lastCoordinate.x`?

note previously implementation only checks
>if (!viewPortHandler.isInBoundsRight(_lineSegments[0].x))

Did you find out that we need to check both points? for BoundsRight?

this question also applies to above ` // If both points lie left of viewport, skip stroking.`

Code after:
                }
                else
                {
                    _lineSegments[1] = CGPoint(x: CGFloat(e.x), y: CGFloat(e.y * phaseY))
                }
            }
            else
            {
                _lineSegments[1] = _lineSegments[0]
            }

            for i in 0..<_lineSegments.count
            {
                _lineSegments[i] = _lineSegments[i].applying(valueToPixelMatrix)
            }
            
            // Determine the start and end coordinates of the line, and make sure they differ.
            guard
                let firstCoordinate = _lineSegments.first,
                let lastCoordinate = _lineSegments.last,
                firstCoordinate != lastCoordinate else { continue }
            
            // If both points lie left of viewport, skip stroking.
            if !viewPortHandler.isInBoundsLeft(lastCoordinate.x) { continue }
            
            // If both points lie right of the viewport, break out early.
            if !viewPortHandler.isInBoundsRight(firstCoordinate.x) { break }
            
            // Only stroke the line if it intersects with the viewport.
            guard viewPortHandler.isIntersectingLine(from: firstCoordinate, to: lastCoordinate) else { continue }
            
            // get the color that is set for this line-segment
            context.setStrokeColor(dataSet.color(atIndex: j).cgColor)
            context.strokeLineSegments(between: _lineSegments)
        }
        
        context.restoreGState()
    }
    
    open func drawLinearFill(context: CGContext, dataSet: ILineChartDataSet, trans: Transformer, bounds: XBounds)
    {
        guard let dataProvider = dataProvider else { return }
        
        let filled = generateFilledPath(
            dataSet: dataSet,
            fillMin: dataSet.fillFormatter?.getFillLinePosition(dataSet: dataSet, dataProvider: dataProvider) ?? 0.0,
            bounds: bounds,
            matrix: trans.valueToPixelMatrix)
        
        if dataSet.fill != nil
        {