Java Code Examples for java.awt.Point#Float

The following examples show how to use java.awt.Point#Float . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set new knot location
 * @param index point index
 * @param p normalized point data
 */
public void setKnotPosition(int index, Point.Float p){
    int lastIndex = curve.x.length - 1;

    if (index <0 || index > lastIndex) {
        return;
    }

    // check prev/next index - knots can't change they index
    if (index > 0 && p.x < curve.x[index-1]) {
        p.x = curve.x[index-1];
    } else if (index < lastIndex && p.x > curve.x[index+1]) {
        p.x = curve.x[index+1];
    }

    curve.x[index] = ImageMath.clamp(p.x, 0, 1);
    curve.y[index] = ImageMath.clamp(p.y, 0, 1);
    isDirty = true;
}
 
Example 2
Source File: ToneCurvesPanel.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
    Point.Float mousePos = getNormalizedMousePos(e);
    ToneCurve activeCurve = toneCurves.getActiveCurve();
    if (activeCurve.isOverKnot(mousePos)) {
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else if (ToneCurve.isOverChart(mousePos)) {
        setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    } else {
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }
}
 
Example 3
Source File: ToneCurvesPanel.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    if (e.getClickCount() > 1 || e.isConsumed()) {
        return;
    }

    Point.Float mousePos = getNormalizedMousePos(e);
    mouseKnotIndex = toneCurves.getActiveCurve().getKnotIndexAt(mousePos);

    if (mouseKnotIndex < 0) {
        e.consume();
        mouseKnotIndex = toneCurves.getActiveCurve().addKnot(mousePos, true);
        stateChanged();
    }
}
 
Example 4
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isClose(Point.Float p, Point.Float q) {
    if(Math.abs(p.x - q.x) < NEARBY_RADIUS) {
        if(Math.abs(p.y - q.y) < NEARBY_RADIUS) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public int addKnot(Point.Float p, boolean allowReplace) {
    // clamp to boundaries [0,1]
    clampPoint(p);

    int lastIndex = curve.x.length - 1;
    int index = curve.findKnotPos(p.x);

    // Can't add knot at first/last position
    if (index <=0 || index > lastIndex) {
        return -1;
    }

    // if point is too close to next/prev knot -> replace the nearest
    // this protect against placing two knots too close to each other
    if (allowReplace) {
        int prevIndex = index-1;
        if (isClose(p, new Point.Float(curve.x[prevIndex], curve.y[prevIndex]))) {
            setKnotPosition(prevIndex, p);
            return prevIndex;
        } else if (isClose(p, new Point.Float(curve.x[index], curve.y[index]))) {
            setKnotPosition(index, p);
            return index;
        }
    }

    // check for max knot limit
    if (curve.x.length >= MAX_KNOTS) {
        return -1;
    }

    isDirty = true;
    return curve.addKnot(p.x, p.y);
}
 
Example 6
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if point p is out of index range (check prev/next knot)
 * @param index knot index
 * @param p normalized point data
 */
public boolean isDraggedOff(int index, Point.Float p) {
    if (index <=0 || index >= curve.x.length - 1) {
        return false;
    }

    if (p.x > curve.x[index+1] + 0.02F || p.x < curve.x[index-1] - 0.02F) {
        return true;
    }

    return false;
}
 
Example 7
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if point p is allowed to put at given index
 * @param index knot index
 * @param p normalized point data
 */
public boolean isDraggedIn(int index, Point.Float p) {
    if (index <=0 || index > curve.x.length - 1) {
        return false;
    }

    if (p.x < curve.x[index] && p.x > curve.x[index-1]) {
        return true;
    }

    return false;
}
 
Example 8
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public boolean isOverKnot(int index) {
    var p = new Point.Float(curve.x[index], curve.y[index]);
    for (int i = 0; i < curve.x.length; i++) {
        if (i != index && isOver(p, new Point.Float(curve.x[i], curve.y[i]))) {
            return true;
        }
    }

    return false;
}
 
Example 9
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public int getKnotIndexAt(Point.Float p) {
    for (int i = 0; i < curve.x.length; i++) {
        if (isOver(p, new Point.Float(curve.x[i], curve.y[i]))) {
            return i;
        }
    }

    return -1;
}
 
Example 10
Source File: ToneCurves.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
public void normalizePoint(Point.Float p) {
    p.x -= CURVE_PADDING + AXIS_PADDING;
    p.y -= CURVE_PADDING;

    p.y = curveHeight - p.y;
    p.x /= curveWidth;
    p.y /= curveHeight;
}
 
Example 11
Source File: Type1CharString.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Flex (via OtherSubrs)
 * @param num OtherSubrs entry number
 */
private void callothersubr(int num)
{
    if (num == 0)
    {
        // end flex
        isFlex = false;

        if (flexPoints.size() < 7)
        {
            LOG.warn("flex without moveTo in font " + fontName + ", glyph " + glyphName +
                     ", command " + commandCount);
            return;
        }

        // reference point is relative to start point
        Point.Float reference = flexPoints.get(0);
        reference.setLocation(current.getX() + reference.getX(),
                              current.getY() + reference.getY());

        // first point is relative to reference point
        Point.Float first = flexPoints.get(1);
        first.setLocation(reference.getX() + first.getX(), reference.getY() + first.getY());

        // make the first point relative to the start point
        first.setLocation(first.getX() - current.getX(), first.getY() - current.getY());

        rrcurveTo(flexPoints.get(1).getX(), flexPoints.get(1).getY(),
                  flexPoints.get(2).getX(), flexPoints.get(2).getY(),
                  flexPoints.get(3).getX(), flexPoints.get(3).getY());

        rrcurveTo(flexPoints.get(4).getX(), flexPoints.get(4).getY(),
                  flexPoints.get(5).getX(), flexPoints.get(5).getY(),
                  flexPoints.get(6).getX(), flexPoints.get(6).getY());

        flexPoints.clear();
    }
    else if (num == 1)
    {
        // begin flex
        isFlex = true;
    }
    else
    {
        // indicates a PDFBox bug
        throw new IllegalArgumentException("Unexpected other subroutine: " + num);
    }
}
 
Example 12
Source File: ToneCurvesPanel.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
private Point.Float getNormalizedMousePos(MouseEvent e) {
    var mousePos = new Point.Float(e.getX(), e.getY());
    toneCurves.normalizePoint(mousePos);
    return mousePos;
}
 
Example 13
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
private static void clampPoint(Point.Float p) {
    p.x = ImageMath.clamp(p.x, 0, 1);
    p.y = ImageMath.clamp(p.y, 0, 1);
}
 
Example 14
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isOver(Point.Float p, Point.Float q) {
    if (Math.abs(p.x - q.x) < KNOT_RADIUS) {
        return Math.abs(p.y - q.y) < KNOT_RADIUS;
    }
    return false;
}
 
Example 15
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
public boolean isOverKnot(Point.Float p) {
    return getKnotIndexAt(p) >= 0;
}
 
Example 16
Source File: ToneCurve.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isOverChart(Point.Float p) {
    return p.x >= 0 && p.x <= 1 && p.y >= 0 && p.y <= 1;
}