Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with Point2D

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

the class CspViewCtrl method visualize.

protected void visualize(VAR var) {
    Point2D pos = getPosition(var);
    String label = var.getName();
    VAL value = null;
    Color fillColor = null;
    if (assignment != null)
        value = assignment.getValue(var);
    if (value != null) {
        label += " = " + value;
        fillColor = colorMapping.get(value);
    }
    Circle circle = new Circle(pos.getX(), pos.getY(), 20);
    circle.setStroke(Color.BLACK);
    circle.setFill(fillColor != null ? fillColor : Color.WHITE);
    Text t1 = new Text(pos.getX() + 25, pos.getY(), label);
    t1.setTextOrigin(VPos.CENTER);
    Text t2 = new Text(pos.getX(), pos.getY() + 40, csp.getDomain(var).toString());
    pane.getChildren().addAll(circle, t1, t2);
}
Also used : Circle(javafx.scene.shape.Circle) Point2D(aima.core.util.math.geom.shapes.Point2D) Color(javafx.scene.paint.Color) Text(javafx.scene.text.Text)

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