Search in sources :

Example 11 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class GraphicsTransfer2D method transfer.

/**
	 * Transfers a {@link Polyline2D} into its {@link Shape} representative.
	 * @param polyline the polyline to be transferred.
	 * @return the transferred shape.
	 */
private static Shape transfer(Polyline2D polyline) {
    Path2D result = new java.awt.geom.Path2D.Double();
    Point2D[] vertexes = polyline.getVertexes();
    result.moveTo(vertexes[0].getX(), vertexes[0].getY());
    for (int i = 1; i < vertexes.length; i++) {
        result.lineTo(vertexes[i].getX(), vertexes[i].getY());
    }
    if (polyline.isClosed())
        result.closePath();
    return result;
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Path2D(java.awt.geom.Path2D)

Example 12 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class SVGGroupParser method parsePolyline.

/**
	 * Parses the current element as a polyline. This polyline is added to the {@code shapes} if it contains a valid points list.
	 */
private void parsePolyline() {
    String value = reader.getAttributeValue(null, POINTS_ATTRIBUTE);
    if (value != null) {
        String[] coords = value.split(POINTS_REGEX);
        if (coords.length >= 2 && coords.length % 2 == 0) {
            //otherwise something is wrong with the points list!
            Point2D[] vertexes = new Point2D[coords.length / 2];
            for (int i = 0; i < coords.length; i = i + 2) {
                vertexes[(i / 2) - 1] = new Point2D(parseNumber(coords[i]), parseNumber(coords[i + 1]));
            }
            IGeometric2D polyline = new Polyline2D(vertexes, false).transform(currentMatrix);
            shapes.add(polyline);
        }
    }
}
Also used : IGeometric2D(aima.core.util.math.geom.shapes.IGeometric2D) Polyline2D(aima.core.util.math.geom.shapes.Polyline2D) Point2D(aima.core.util.math.geom.shapes.Point2D)

Example 13 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class SVGGroupParser method parsePolygon.

/**
	 * Parses the current element as a polygon. This polygon is added to the {@code shapes} if it contains a valid points list.
	 */
private void parsePolygon() {
    String value = reader.getAttributeValue(null, POINTS_ATTRIBUTE);
    if (value != null) {
        String[] coords = value.split(POINTS_REGEX);
        if (coords.length >= 2 && coords.length % 2 == 0) {
            //otherwise something is wrong with the points list!
            Point2D[] vertexes = new Point2D[coords.length / 2];
            for (int i = 1; i < coords.length; i = i + 2) {
                vertexes[(i - 1) / 2] = new Point2D(parseNumber(coords[i - 1]), parseNumber(coords[i]));
            }
            IGeometric2D polygon = new Polyline2D(vertexes, true).transform(currentMatrix);
            shapes.add(polygon);
        }
    }
}
Also used : IGeometric2D(aima.core.util.math.geom.shapes.IGeometric2D) Polyline2D(aima.core.util.math.geom.shapes.Polyline2D) Point2D(aima.core.util.math.geom.shapes.Point2D)

Example 14 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class SVGGroupParser method parseEllipse.

/**
	 * Parses the current element as an ellipse. This ellipse is added to the {@code shapes} if it is rendered.
	 */
private void parseEllipse() {
    String value = reader.getAttributeValue(null, CX_ATTRIBUTE);
    final double cx = parseNumber(value);
    value = reader.getAttributeValue(null, CY_ATTRIBUTE);
    final double cy = parseNumber(value);
    value = reader.getAttributeValue(null, RX_ATTRIBUTE);
    final double rx = parseNumber(value);
    value = reader.getAttributeValue(null, RY_ATTRIBUTE);
    final double ry = parseNumber(value);
    if (rx != 0.0d && ry != 0.0d) {
        //SVG standard specifies that the radius is forced to have a value. Otherwise the rendering for this element is disabled.
        IGeometric2D elipse = new Ellipse2D(new Point2D(cx, cy), rx, ry).transform(currentMatrix);
        shapes.add(elipse);
    }
}
Also used : IGeometric2D(aima.core.util.math.geom.shapes.IGeometric2D) Point2D(aima.core.util.math.geom.shapes.Point2D) Ellipse2D(aima.core.util.math.geom.shapes.Ellipse2D)

Example 15 with Point2D

use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.

the class SVGGroupParser method parseCircle.

/**
	 * Parses the current element as a circle. This circle is added to the {@code shapes} if it is rendered.
	 */
private void parseCircle() {
    String value = reader.getAttributeValue(null, CX_ATTRIBUTE);
    final double cx = parseNumber(value);
    value = reader.getAttributeValue(null, CY_ATTRIBUTE);
    final double cy = parseNumber(value);
    value = reader.getAttributeValue(null, R_ATTRIBUTE);
    final double r = parseNumber(value);
    if (r != 0.0d) {
        //SVG standard specifies that the radius is forced to have a value. Otherwise the rendering for this element is disabled.
        IGeometric2D circle = new Circle2D(new Point2D(cx, cy), r).transform(currentMatrix);
        shapes.add(circle);
    }
}
Also used : IGeometric2D(aima.core.util.math.geom.shapes.IGeometric2D) Point2D(aima.core.util.math.geom.shapes.Point2D) Circle2D(aima.core.util.math.geom.shapes.Circle2D)

Aggregations

Point2D (aima.core.util.math.geom.shapes.Point2D)32 Map (aima.core.environment.map.Map)7 ArrayList (java.util.ArrayList)6 IGeometric2D (aima.core.util.math.geom.shapes.IGeometric2D)5 Before (org.junit.Before)5 Circle2D (aima.core.util.math.geom.shapes.Circle2D)4 Ellipse2D (aima.core.util.math.geom.shapes.Ellipse2D)4 Polyline2D (aima.core.util.math.geom.shapes.Polyline2D)4 Test (org.junit.Test)4 Line2D (aima.core.util.math.geom.shapes.Line2D)3 Ray2D (aima.core.util.math.geom.shapes.Ray2D)3 MapNode (aimax.osm.data.entities.MapNode)3 Agent (aima.core.agent.Agent)2 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)2 Circle (javafx.scene.shape.Circle)2 Line (javafx.scene.shape.Line)2 Text (javafx.scene.text.Text)2 aima.core.environment.map (aima.core.environment.map)1 MapAgent (aima.core.environment.map.MapAgent)1 MapEnvironment (aima.core.environment.map.MapEnvironment)1