Search in sources :

Example 6 with Point2D

use of java.awt.geom.Point2D in project openblocks by mikaelhg.

the class BlockShape method makeBottomSide.

//------------------------
//DRAW BOTTOM OF THE BLOCK
//------------------------
// drawn counter-clockwise
// bottom-left conrner, bottom edge, and bottom-right corner
protected void makeBottomSide() {
    //start bottom-right
    setEndPoint(gpBottom, botLeftCorner, topLeftCorner, true);
    //curve down and right
    BlockShapeUtil.cornerTo(gpBottom, botLeftCorner, botRightCorner, blockCornerRadius);
    //if (block.isCommandBlock() && block.hasAfterConnector()) {
    if (block.hasAfterConnector() && !rb.isCollapsed()) {
        //control connector if necessary
        // Trying left-aligned ports
        Point2D p = BCS.addControlConnectorShape(gpBottom, (float) COMMAND_PORT_OFFSET + blockCornerRadius, true);
        rb.updateSocketPoint(block.getAfterConnector(), p);
    }
    //curve right and up
    BlockShapeUtil.cornerTo(gpBottom, botRightCorner, topRightCorner, blockCornerRadius);
    //end bottom
    setEndPoint(gpBottom, botRightCorner, topRightCorner, false);
}
Also used : Point2D(java.awt.geom.Point2D)

Example 7 with Point2D

use of java.awt.geom.Point2D in project openblocks by mikaelhg.

the class BlockShapeUtil method makeCornerTo.

/**
     * Draws a corner relative to the current point of the GeneralPath.  Note the radius denotes the 
     * distance from the cornerPoint to where the curve starts on the line formed from the cornerPoint to the
     * current point on the gp and where the curve ends on the line from the cornerPoint to the nextCornerPoint.
     * In other words, 
     */
private static void makeCornerTo(GeneralPath gp, Point2D cornerPoint, Point2D nextCornerPoint, float radius) {
    Point2D currentPoint = gp.getCurrentPoint();
    //get fractional to the corner where the line first starts to curve
    double distance = currentPoint.distance(cornerPoint);
    double fraction = (distance - radius) / distance;
    //calculate these distance from the current point
    double xDistance = (cornerPoint.getX() - currentPoint.getX()) * fraction;
    double yDistance = (cornerPoint.getY() - currentPoint.getY()) * fraction;
    //draw a line to the point where the line first starts to curve
    lineToRelative(gp, (float) xDistance, (float) yDistance);
    Point2D startCurvePoint = gp.getCurrentPoint();
    //get fractional to the corner where the line first starts to curve
    double distanceFromCornerToNextCorner = cornerPoint.distance(nextCornerPoint);
    double fractionToNextCorner = radius / distanceFromCornerToNextCorner;
    //calculate these distance from the current point
    double xDistanceFromCornerToEndCurve = (nextCornerPoint.getX() - cornerPoint.getX()) * fractionToNextCorner;
    double yDistanceFromCornerToEndCurve = (nextCornerPoint.getY() - cornerPoint.getY()) * fractionToNextCorner;
    Point2D endCurvePoint = new Point2D.Double(cornerPoint.getX() + xDistanceFromCornerToEndCurve, cornerPoint.getY() + yDistanceFromCornerToEndCurve);
    //finally draw the cornerShape
    cornerShape(gp, //start at:
    (float) startCurvePoint.getX(), (float) startCurvePoint.getY(), //corner at:
    (float) cornerPoint.getX(), (float) cornerPoint.getY(), //end at:
    (float) endCurvePoint.getX(), (float) endCurvePoint.getY());
}
Also used : Point2D(java.awt.geom.Point2D)

Example 8 with Point2D

use of java.awt.geom.Point2D in project openblocks by mikaelhg.

the class BlockShapeUtil method curveTo.

/**
     * Draws a curve segment relative to the current point of the GeneralPath.
     * 
     * Adds a curved segment, defined by three new points, to the path by
     * drawing a Bézier curve that intersects both the current coordinates and
     * the coordinates (x3, y3), using the specified points (x1, y1) and (x2,
     * y2) as Bézier control points.
     */
public static void curveTo(GeneralPath gp, float x1, float y1, float x2, float y2, float x3, float y3) {
    Point2D currentPoint = gp.getCurrentPoint();
    gp.curveTo(x1 + (float) currentPoint.getX(), y1 + (float) currentPoint.getY(), x2 + (float) currentPoint.getX(), y2 + (float) currentPoint.getY(), x3 + (float) currentPoint.getX(), y3 + (float) currentPoint.getY());
}
Also used : Point2D(java.awt.geom.Point2D)

Example 9 with Point2D

use of java.awt.geom.Point2D in project openblocks by mikaelhg.

the class BlockShapeUtil method lineToRelative.

/**
     * Draws a line segment relative to the current point of the GeneralPath.
     */
public static void lineToRelative(GeneralPath gp, float x, float y) {
    Point2D currentPoint = gp.getCurrentPoint();
    gp.lineTo((float) currentPoint.getX() + x, (float) currentPoint.getY() + y);
}
Also used : Point2D(java.awt.geom.Point2D)

Example 10 with Point2D

use of java.awt.geom.Point2D in project traffic-engine by opentraffic.

the class OSMDataStore method createTripLine.

public TripLine createTripLine(StreetSegment streetSegment, int triplineIndex, LengthIndexedLine lengthIndexedLine, double lengthIndex, double dist) {
    double l1Bearing = OSMDataStore.getBearing(lengthIndexedLine, lengthIndex);
    synchronized (OSMDataStore.gc) {
        Coordinate p1 = lengthIndexedLine.extractPoint(lengthIndex);
        gc.setStartingGeographicPoint(p1.x, p1.y);
        gc.setDirection(clampAzimuth(l1Bearing + 90), TRIPLINE_RADIUS);
        Point2D tlRight = gc.getDestinationGeographicPoint();
        gc.setDirection(clampAzimuth(l1Bearing - 90), TRIPLINE_RADIUS);
        Point2D tlLeft = gc.getDestinationGeographicPoint();
        Coordinate[] coords = new Coordinate[2];
        coords[0] = new Coordinate(tlLeft.getX(), tlLeft.getY());
        coords[1] = new Coordinate(tlRight.getX(), tlRight.getY());
        TripLine tl = new TripLine(this.triplines.getNextId(), coords, streetSegment.id, triplineIndex, dist);
        return tl;
    }
}
Also used : Point2D(java.awt.geom.Point2D) TripLine(io.opentraffic.engine.geom.TripLine)

Aggregations

Point2D (java.awt.geom.Point2D)159 Rectangle2D (java.awt.geom.Rectangle2D)18 Color (java.awt.Color)12 RadialGradientPaint (java.awt.RadialGradientPaint)10 AffineTransform (java.awt.geom.AffineTransform)10 Line2D (java.awt.geom.Line2D)9 Paint (java.awt.Paint)8 Graphics2D (java.awt.Graphics2D)7 BufferedImage (java.awt.image.BufferedImage)7 Element (org.jdom2.Element)6 BasicStroke (java.awt.BasicStroke)5 IOException (java.io.IOException)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 Point (java.awt.Point)4 Rectangle (java.awt.Rectangle)4 NodeRef (dr.evolution.tree.NodeRef)3 RenderableBlock (edu.mit.blocks.renderable.RenderableBlock)3 Arc2D (java.awt.geom.Arc2D)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2