Skip to content

Commit

Permalink
Corrected check for line in vertical bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 23, 2020
1 parent 1de836a commit 5e4a32e
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) {
// more than 1 color
if (dataSet.getColors().size() > 1) {

if (mLineBuffer.length <= pointsPerEntryPair * 2)
mLineBuffer = new float[pointsPerEntryPair * 4];
int numberOfFloats = pointsPerEntryPair * 2;

if (mLineBuffer.length <= numberOfFloats)
mLineBuffer = new float[numberOfFloats * 2];

int max = mXBounds.min + mXBounds.range;

Expand Down Expand Up @@ -359,16 +361,26 @@ protected void drawLinear(Canvas c, ILineDataSet dataSet) {
mLineBuffer[3] = mLineBuffer[1];
}

// Determine the start and end coordinates of the line, and make sure they differ.
float firstCoordinateX = mLineBuffer[0];
float firstCoordinateY = mLineBuffer[1];
float lastCoordinateX = mLineBuffer[numberOfFloats - 2];
float lastCoordinateY = mLineBuffer[numberOfFloats - 1];

if (firstCoordinateX == lastCoordinateX &&
firstCoordinateY == lastCoordinateY)
continue;

trans.pointValuesToPixel(mLineBuffer);

if (!mViewPortHandler.isInBoundsRight(mLineBuffer[0]))
if (!mViewPortHandler.isInBoundsRight(firstCoordinateX))
break;

// make sure the lines don't do shitty things outside
// bounds
if (!mViewPortHandler.isInBoundsLeft(mLineBuffer[2])
|| (!mViewPortHandler.isInBoundsTop(mLineBuffer[1]) && !mViewPortHandler
.isInBoundsBottom(mLineBuffer[3])))
if (!mViewPortHandler.isInBoundsLeft(lastCoordinateX) ||
!mViewPortHandler.isInBoundsTop(lastCoordinateY) ||
!mViewPortHandler.isInBoundsBottom(firstCoordinateY))
continue;

// get the color that is set for this line-segment
Expand Down

0 comments on commit 5e4a32e

Please sign in to comment.