Java Code Examples for sun.awt.geom.Curve#RECT_INTERSECTS

The following examples show how to use sun.awt.geom.Curve#RECT_INTERSECTS . 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: CubicCurve2D.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private int rectCrossings(double x, double y, double w, double h) {
    int crossings = 0;
    if (!(getX1() == getX2() && getY1() == getY2())) {
        crossings = Curve.rectCrossingsForLine(crossings,
                                               x, y,
                                               x+w, y+h,
                                               getX1(), getY1(),
                                               getX2(), getY2());
        if (crossings == Curve.RECT_INTERSECTS) {
            return crossings;
        }
    }
    // we call this with the curve's direction reversed, because we wanted
    // to call rectCrossingsForLine first, because it's cheaper.
    return Curve.rectCrossingsForCubic(crossings,
                                       x, y,
                                       x+w, y+h,
                                       getX2(), getY2(),
                                       getCtrlX2(), getCtrlY2(),
                                       getCtrlX1(), getCtrlY1(),
                                       getX1(), getY1(), 0);
}
 
Example 2
Source File: Path2D.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @since 1.6
 */
public final boolean intersects(double x, double y, double w, double h) {
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
    int crossings = rectCrossings(x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 3
Source File: CubicCurve2D.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private int rectCrossings(double x, double y, double w, double h) {
    int crossings = 0;
    if (!(getX1() == getX2() && getY1() == getY2())) {
        crossings = Curve.rectCrossingsForLine(crossings,
                                               x, y,
                                               x+w, y+h,
                                               getX1(), getY1(),
                                               getX2(), getY2());
        if (crossings == Curve.RECT_INTERSECTS) {
            return crossings;
        }
    }
    // we call this with the curve's direction reversed, because we wanted
    // to call rectCrossingsForLine first, because it's cheaper.
    return Curve.rectCrossingsForCubic(crossings,
                                       x, y,
                                       x+w, y+h,
                                       getX2(), getY2(),
                                       getCtrlX2(), getCtrlY2(),
                                       getCtrlX1(), getCtrlY1(),
                                       getX1(), getY1(), 0);
}
 
Example 4
Source File: Path2D.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @since 1.6
 */
public final boolean contains(double x, double y, double w, double h) {
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
    int crossings = rectCrossings(x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 5
Source File: CubicCurve2D.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private int rectCrossings(double x, double y, double w, double h) {
    int crossings = 0;
    if (!(getX1() == getX2() && getY1() == getY2())) {
        crossings = Curve.rectCrossingsForLine(crossings,
                                               x, y,
                                               x+w, y+h,
                                               getX1(), getY1(),
                                               getX2(), getY2());
        if (crossings == Curve.RECT_INTERSECTS) {
            return crossings;
        }
    }
    // we call this with the curve's direction reversed, because we wanted
    // to call rectCrossingsForLine first, because it's cheaper.
    return Curve.rectCrossingsForCubic(crossings,
                                       x, y,
                                       x+w, y+h,
                                       getX2(), getY2(),
                                       getCtrlX2(), getCtrlY2(),
                                       getCtrlX1(), getCtrlY1(),
                                       getX1(), getY1(), 0);
}
 
Example 6
Source File: Path2D.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @since 1.6
 */
public final boolean contains(double x, double y, double w, double h) {
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
    int crossings = rectCrossings(x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 7
Source File: Path2D.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @since 1.6
 */
public final boolean intersects(double x, double y, double w, double h) {
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
    int crossings = rectCrossings(x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 8
Source File: CubicCurve2D.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * @since 1.2
 */
public boolean contains(double x, double y, double w, double h) {
    if (w <= 0 || h <= 0) {
        return false;
    }

    int numCrossings = rectCrossings(x, y, w, h);
    return !(numCrossings == 0 || numCrossings == Curve.RECT_INTERSECTS);
}
 
Example 9
Source File: Path2D.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 10
Source File: Path2D.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the specified rectangular area is entirely inside the
 * closed boundary of the specified {@link PathIterator}.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#contains(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular area
 * @param h the height of the specified rectangular area
 * @return {@code true} if the specified {@code PathIterator} contains
 *         the specified rectangular area; {@code false} otherwise.
 * @since 1.6
 */
public static boolean contains(PathIterator pi,
                               double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 11
Source File: Path2D.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 12
Source File: Path2D.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if the specified rectangular area is entirely inside the
 * closed boundary of the specified {@link PathIterator}.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#contains(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular area
 * @param h the height of the specified rectangular area
 * @return {@code true} if the specified {@code PathIterator} contains
 *         the specified rectangluar area; {@code false} otherwise.
 * @since 1.6
 */
public static boolean contains(PathIterator pi,
                               double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 13
Source File: Path2D.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 14
Source File: Path2D.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 15
Source File: Path2D.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 16
Source File: Path2D.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the specified rectangular area is entirely inside the
 * closed boundary of the specified {@link PathIterator}.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#contains(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular area
 * @param h the height of the specified rectangular area
 * @return {@code true} if the specified {@code PathIterator} contains
 *         the specified rectangular area; {@code false} otherwise.
 * @since 1.6
 */
public static boolean contains(PathIterator pi,
                               double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 17
Source File: Path2D.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}
 
Example 18
Source File: Path2D.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests if the specified rectangular area is entirely inside the
 * closed boundary of the specified {@link PathIterator}.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#contains(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular area
 * @param h the height of the specified rectangular area
 * @return {@code true} if the specified {@code PathIterator} contains
 *         the specified rectangular area; {@code false} otherwise.
 * @since 1.6
 */
public static boolean contains(PathIterator pi,
                               double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 19
Source File: Path2D.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Tests if the specified rectangular area is entirely inside the
 * closed boundary of the specified {@link PathIterator}.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#contains(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return false in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such segments could lie entirely within the interior of the
 * path if they are part of a path with a {@link #WIND_NON_ZERO}
 * winding rule or if the segments are retraced in the reverse
 * direction such that the two sets of segments cancel each
 * other out without any exterior area falling between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular area
 * @param h the height of the specified rectangular area
 * @return {@code true} if the specified {@code PathIterator} contains
 *         the specified rectangular area; {@code false} otherwise.
 * @since 1.6
 */
public static boolean contains(PathIterator pi,
                               double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings != Curve.RECT_INTERSECTS &&
            (crossings & mask) != 0);
}
 
Example 20
Source File: Path2D.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if the interior of the specified {@link PathIterator}
 * intersects the interior of a specified set of rectangular
 * coordinates.
 * <p>
 * This method provides a basic facility for implementors of
 * the {@link Shape} interface to implement support for the
 * {@link Shape#intersects(double, double, double, double)} method.
 * <p>
 * This method object may conservatively return true in
 * cases where the specified rectangular area intersects a
 * segment of the path, but that segment does not represent a
 * boundary between the interior and exterior of the path.
 * Such a case may occur if some set of segments of the
 * path are retraced in the reverse direction such that the
 * two sets of segments cancel each other out without any
 * interior area between them.
 * To determine whether segments represent true boundaries of
 * the interior of the path would require extensive calculations
 * involving all of the segments of the path and the winding
 * rule and are thus beyond the scope of this implementation.
 *
 * @param pi the specified {@code PathIterator}
 * @param x the specified X coordinate
 * @param y the specified Y coordinate
 * @param w the width of the specified rectangular coordinates
 * @param h the height of the specified rectangular coordinates
 * @return {@code true} if the specified {@code PathIterator} and
 *         the interior of the specified set of rectangular
 *         coordinates intersect each other; {@code false} otherwise.
 * @since 1.6
 */
public static boolean intersects(PathIterator pi,
                                 double x, double y, double w, double h)
{
    if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
        /* [xy]+[wh] is NaN if any of those values are NaN,
         * or if adding the two together would produce NaN
         * by virtue of adding opposing Infinte values.
         * Since we need to add them below, their sum must
         * not be NaN.
         * We return false because NaN always produces a
         * negative response to tests
         */
        return false;
    }
    if (w <= 0 || h <= 0) {
        return false;
    }
    int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
    int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
    return (crossings == Curve.RECT_INTERSECTS ||
            (crossings & mask) != 0);
}