Source code for PathDrawing.java

What follows is the highlighted source code with comments. You can also download this file directly: PathDrawing.java.

/*
 * Copyright (C) 2012 W. Patrick Hooper <wphooper@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package graphics;

import geometry.LineSegment;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import path.EdgeIterator;
import path.PolygonalPath;

/**
 * This class contains a static method for drawing a polygonal path.
 *
 * @author W. Patrick Hooper <wphooper@gmail.com>
 */
public class PathDrawing {

    /**
     * Draw the image of the polygonal path p under the affine transform t.
     */
    public static void drawPolygonalPath(Graphics2D g, AffineTransform t, PolygonalPath p) {
        // We now iterate over the segments in the path. 
        EdgeIterator it = p.iterator();
        while (it.hasNext()) {
            LineSegment s = it.next();
            // Constuct a Line2D with the same start and end points.
            // The advantage of this object is that it can be drawn.
            Line2D line_segment = new Line2D.Double(s.startingPoint().re(),
                    s.startingPoint().im(),
                    s.endingPoint().re(),
                    s.endingPoint().im());
            // Convert the line segment into screen coordinates, then draw it.
            g.draw(t.createTransformedShape(line_segment));
        }
    }
}
HOOPER >>>>> JAVA TUTORIAL
Last modified on August 25, 2021.
[check html] [check css]