Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This works (in all situations, I believe), but it might require more thorough testing: </p> <pre><code>Area area; // The value is set elsewhere in the code ArrayList&lt;double[]&gt; areaPoints = new ArrayList&lt;double[]&gt;(); ArrayList&lt;Line2D.Double&gt; areaSegments = new ArrayList&lt;Line2D.Double&gt;(); double[] coords = new double[6]; for (PathIterator pi = area.getPathIterator(null); !pi.isDone(); pi.next()) { // The type will be SEG_LINETO, SEG_MOVETO, or SEG_CLOSE // Because the Area is composed of straight lines int type = pi.currentSegment(coords); // We record a double array of {segment type, x coord, y coord} double[] pathIteratorCoords = {type, coords[0], coords[1]}; areaPoints.add(pathIteratorCoords); } double[] start = new double[3]; // To record where each polygon starts for (int i = 0; i &lt; areaPoints.size(); i++) { // If we're not on the last point, return a line from this point to the next double[] currentElement = areaPoints.get(i); // We need a default value in case we've reached the end of the ArrayList double[] nextElement = {-1, -1, -1}; if (i &lt; areaPoints.size() - 1) { nextElement = areaPoints.get(i + 1); } // Make the lines if (currentElement[0] == PathIterator.SEG_MOVETO) { start = currentElement; // Record where the polygon started to close it later } if (nextElement[0] == PathIterator.SEG_LINETO) { areaSegments.add( new Line2D.Double( currentElement[1], currentElement[2], nextElement[1], nextElement[2] ) ); } else if (nextElement[0] == PathIterator.SEG_CLOSE) { areaSegments.add( new Line2D.Double( currentElement[1], currentElement[2], start[1], start[2] ) ); } } // areaSegments now contains all the line segments </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload