Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08201817 authored by Darren Salt's avatar Darren Salt
Browse files

Spline: limit control point X co-ordinates to the graph area.

This fixes an oversight in the control point handling which allows
the X co-ordinate to be outside the range 0..1 if the width of the
graph (including margins) is less than the width of the display.

On my Nexus 4, without this fix, this problem occurs in landscape
mode when dragging a control point outside the graph area,
effectively onto the system buttons area. This bad X co-ordinate and
a lack of bounds checking causes an 'index out of range' exception to
be thrown from within Spline.getAppliedCurve().

The Y co-ordinate is already suitably handled; this commit copies and
adapts that handling for the X co-ordinate. It also adds the
necessary bounds checking to Spline.getAppliedCurve().

Change-Id: I325a1b6837927a6dd050b30209a7beeadf76d089
parent 1a9cc7ce
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -174,9 +174,16 @@ public class ImageCurves extends ImageSlave {

    @Override
    public synchronized boolean onTouchEvent(MotionEvent e) {
        float posX = e.getX() / getWidth();
        float posX = e.getX();
        float posY = e.getY();
        float margin = Spline.curveHandleSize() / 2;
        if (posX < margin) {
            posX = margin;
        }
        if (posX > getWidth() - margin) {
            posX = getWidth() - margin;
        }
        posX = (posX - margin) / (getWidth() - 2 * margin);
        if (posY < margin) {
            posY = margin;
        }
+2 −2
Original line number Diff line number Diff line
@@ -127,10 +127,10 @@ public class Spline {
        double[] derivatives = solveSystem(points);
        int start = 0;
        int end = 256;
        if (points[0].x != 0) {
        if (points[0].x >= 0) {
            start = (int) (points[0].x * 256);
        }
        if (points[points.length - 1].x != 1) {
        if (points[points.length - 1].x <= 1) {
            end = (int) (points[points.length - 1].x * 256);
        }
        for (int i = 0; i < start; i++) {