src/share/classes/java/awt/geom/Path2D.java

Print this page


   1 /*
   2  * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 788          * an integer indicating the total number of coordinates to follow (NC)
 789          * or -1 to indicate an unknown number of coordinates follows
 790          * (NC should always be even since coordinates always appear in pairs
 791          *  representing an x,y pair)
 792          * <li>followed by
 793          * a byte indicating the winding rule
 794          * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
 795          *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
 796          * <li>followed by
 797          * {@code NP} (or unlimited if {@code NP < 0}) sets of values consisting of
 798          * a single byte indicating a path segment type
 799          * followed by one or more pairs of float or double
 800          * values representing the coordinates of the path segment
 801          * <li>followed by
 802          * a byte indicating the end of the path (SERIAL_PATH_END).
 803          * </ol>
 804          * <p>
 805          * The following byte value constants are used in the serialized form
 806          * of {@code Path2D} objects:
 807          * <table>

 808          * <tr>
 809          * <th>Constant Name</th>
 810          * <th>Byte Value</th>
 811          * <th>Followed by</th>
 812          * <th>Description</th>
 813          * </tr>
 814          * <tr>
 815          * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
 816          * <td>0x30</td>
 817          * <td></td>
 818          * <td>A hint that the original {@code Path2D} object stored
 819          * the coordinates in a Java array of floats.</td>
 820          * </tr>
 821          * <tr>
 822          * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
 823          * <td>0x31</td>
 824          * <td></td>
 825          * <td>A hint that the original {@code Path2D} object stored
 826          * the coordinates in a Java array of doubles.</td>
 827          * </tr>


1514          * an integer indicating the total number of coordinates to follow (NC)
1515          * or -1 to indicate an unknown number of coordinates follows
1516          * (NC should always be even since coordinates always appear in pairs
1517          *  representing an x,y pair)
1518          * <li>followed by
1519          * a byte indicating the winding rule
1520          * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
1521          *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
1522          * <li>followed by
1523          * {@code NP} (or unlimited if {@code NP < 0}) sets of values consisting of
1524          * a single byte indicating a path segment type
1525          * followed by one or more pairs of float or double
1526          * values representing the coordinates of the path segment
1527          * <li>followed by
1528          * a byte indicating the end of the path (SERIAL_PATH_END).
1529          * </ol>
1530          * <p>
1531          * The following byte value constants are used in the serialized form
1532          * of {@code Path2D} objects:
1533          * <table>

1534          * <tr>
1535          * <th>Constant Name</th>
1536          * <th>Byte Value</th>
1537          * <th>Followed by</th>
1538          * <th>Description</th>
1539          * </tr>
1540          * <tr>
1541          * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
1542          * <td>0x30</td>
1543          * <td></td>
1544          * <td>A hint that the original {@code Path2D} object stored
1545          * the coordinates in a Java array of floats.</td>
1546          * </tr>
1547          * <tr>
1548          * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
1549          * <td>0x31</td>
1550          * <td></td>
1551          * <td>A hint that the original {@code Path2D} object stored
1552          * the coordinates in a Java array of doubles.</td>
1553          * </tr>


1909      * Transforms the geometry of this path using the specified
1910      * {@link AffineTransform}.
1911      * The geometry is transformed in place, which permanently changes the
1912      * boundary defined by this object.
1913      *
1914      * @param at the {@code AffineTransform} used to transform the area
1915      * @since 1.6
1916      */
1917     public abstract void transform(AffineTransform at);
1918 
1919     /**
1920      * Returns a new {@code Shape} representing a transformed version
1921      * of this {@code Path2D}.
1922      * Note that the exact type and coordinate precision of the return
1923      * value is not specified for this method.
1924      * The method will return a Shape that contains no less precision
1925      * for the transformed geometry than this {@code Path2D} currently
1926      * maintains, but it may contain no more precision either.
1927      * If the tradeoff of precision vs. storage size in the result is
1928      * important then the convenience constructors in the
1929      * {@link Path2D.Float#Path2D.Float(Shape, AffineTransform) Path2D.Float}
1930      * and
1931      * {@link Path2D.Double#Path2D.Double(Shape, AffineTransform) Path2D.Double}
1932      * subclasses should be used to make the choice explicit.
1933      *
1934      * @param at the {@code AffineTransform} used to transform a
1935      *           new {@code Shape}.
1936      * @return a new {@code Shape}, transformed with the specified
1937      *         {@code AffineTransform}.
1938      * @since 1.6
1939      */
1940     public final synchronized Shape createTransformedShape(AffineTransform at) {
1941         Path2D p2d = (Path2D) clone();
1942         if (at != null) {
1943             p2d.transform(at);
1944         }
1945         return p2d;
1946     }
1947 
1948     /**
1949      * {@inheritDoc}
1950      * @since 1.6
1951      */


   1 /*
   2  * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 788          * an integer indicating the total number of coordinates to follow (NC)
 789          * or -1 to indicate an unknown number of coordinates follows
 790          * (NC should always be even since coordinates always appear in pairs
 791          *  representing an x,y pair)
 792          * <li>followed by
 793          * a byte indicating the winding rule
 794          * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
 795          *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
 796          * <li>followed by
 797          * {@code NP} (or unlimited if {@code NP < 0}) sets of values consisting of
 798          * a single byte indicating a path segment type
 799          * followed by one or more pairs of float or double
 800          * values representing the coordinates of the path segment
 801          * <li>followed by
 802          * a byte indicating the end of the path (SERIAL_PATH_END).
 803          * </ol>
 804          * <p>
 805          * The following byte value constants are used in the serialized form
 806          * of {@code Path2D} objects:
 807          * <table>
 808          * <caption></caption>
 809          * <tr>
 810          * <th>Constant Name</th>
 811          * <th>Byte Value</th>
 812          * <th>Followed by</th>
 813          * <th>Description</th>
 814          * </tr>
 815          * <tr>
 816          * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
 817          * <td>0x30</td>
 818          * <td></td>
 819          * <td>A hint that the original {@code Path2D} object stored
 820          * the coordinates in a Java array of floats.</td>
 821          * </tr>
 822          * <tr>
 823          * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
 824          * <td>0x31</td>
 825          * <td></td>
 826          * <td>A hint that the original {@code Path2D} object stored
 827          * the coordinates in a Java array of doubles.</td>
 828          * </tr>


1515          * an integer indicating the total number of coordinates to follow (NC)
1516          * or -1 to indicate an unknown number of coordinates follows
1517          * (NC should always be even since coordinates always appear in pairs
1518          *  representing an x,y pair)
1519          * <li>followed by
1520          * a byte indicating the winding rule
1521          * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
1522          *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
1523          * <li>followed by
1524          * {@code NP} (or unlimited if {@code NP < 0}) sets of values consisting of
1525          * a single byte indicating a path segment type
1526          * followed by one or more pairs of float or double
1527          * values representing the coordinates of the path segment
1528          * <li>followed by
1529          * a byte indicating the end of the path (SERIAL_PATH_END).
1530          * </ol>
1531          * <p>
1532          * The following byte value constants are used in the serialized form
1533          * of {@code Path2D} objects:
1534          * <table>
1535          * <caption></caption>
1536          * <tr>
1537          * <th>Constant Name</th>
1538          * <th>Byte Value</th>
1539          * <th>Followed by</th>
1540          * <th>Description</th>
1541          * </tr>
1542          * <tr>
1543          * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
1544          * <td>0x30</td>
1545          * <td></td>
1546          * <td>A hint that the original {@code Path2D} object stored
1547          * the coordinates in a Java array of floats.</td>
1548          * </tr>
1549          * <tr>
1550          * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
1551          * <td>0x31</td>
1552          * <td></td>
1553          * <td>A hint that the original {@code Path2D} object stored
1554          * the coordinates in a Java array of doubles.</td>
1555          * </tr>


1911      * Transforms the geometry of this path using the specified
1912      * {@link AffineTransform}.
1913      * The geometry is transformed in place, which permanently changes the
1914      * boundary defined by this object.
1915      *
1916      * @param at the {@code AffineTransform} used to transform the area
1917      * @since 1.6
1918      */
1919     public abstract void transform(AffineTransform at);
1920 
1921     /**
1922      * Returns a new {@code Shape} representing a transformed version
1923      * of this {@code Path2D}.
1924      * Note that the exact type and coordinate precision of the return
1925      * value is not specified for this method.
1926      * The method will return a Shape that contains no less precision
1927      * for the transformed geometry than this {@code Path2D} currently
1928      * maintains, but it may contain no more precision either.
1929      * If the tradeoff of precision vs. storage size in the result is
1930      * important then the convenience constructors in the
1931      * {@link Path2D.Float#Float(Shape, AffineTransform) Path2D.Float}
1932      * and
1933      * {@link Path2D.Double#Double(Shape, AffineTransform) Path2D.Double}
1934      * subclasses should be used to make the choice explicit.
1935      *
1936      * @param at the {@code AffineTransform} used to transform a
1937      *           new {@code Shape}.
1938      * @return a new {@code Shape}, transformed with the specified
1939      *         {@code AffineTransform}.
1940      * @since 1.6
1941      */
1942     public final synchronized Shape createTransformedShape(AffineTransform at) {
1943         Path2D p2d = (Path2D) clone();
1944         if (at != null) {
1945             p2d.transform(at);
1946         }
1947         return p2d;
1948     }
1949 
1950     /**
1951      * {@inheritDoc}
1952      * @since 1.6
1953      */