Search in sources :

Example 21 with Point2D

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

the class ExtendedMapAgentView method paintMap.

/**
	 * Represents roads by lines and locations by name-labeled points.
	 */
protected void paintMap(java.awt.Graphics2D g2) {
    Map envMap = getMapEnv().getMap();
    Map aMap = (agentMap != null) ? agentMap : envMap;
    List<Roadblock> roadblocks = new ArrayList<Roadblock>();
    for (String l1 : envMap.getLocations()) {
        Point2D pt1 = envMap.getPosition(l1);
        List<String> linkedLocs = envMap.getPossibleNextLocations(l1);
        for (String l2 : aMap.getPossibleNextLocations(l1)) if (!linkedLocs.contains(l2))
            linkedLocs.add(l2);
        for (String l2 : linkedLocs) {
            Point2D pt2 = envMap.getPosition(l2);
            g2.setColor(Color.lightGray);
            g2.drawLine(x(pt1), y(pt1), x(pt2), y(pt2));
            boolean blockedInEnv = !envMap.getPossibleNextLocations(l2).contains(l1);
            boolean blockedInAgent = !aMap.getPossibleNextLocations(l2).contains(l1);
            roadblocks.add(new Roadblock(pt1, pt2, blockedInEnv, blockedInAgent));
            if (blockedInEnv && blockedInAgent) {
                boolean blockedInEnvOtherDir = !envMap.getPossibleNextLocations(l1).contains(l2);
                boolean blockedInAgentOtherDir = !aMap.getPossibleNextLocations(l1).contains(l2);
                roadblocks.add(new Roadblock(pt2, pt1, blockedInEnvOtherDir, blockedInAgentOtherDir));
            }
        }
    }
    for (Roadblock block : roadblocks) paintRoadblock(g2, block);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) ArrayList(java.util.ArrayList) Map(aima.core.environment.map.Map)

Example 22 with Point2D

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

the class MapAgentView method adjustTransformation.

/**
	 * Adjusts offsets and scale so that the whole map fits on the view without
	 * scrolling.
	 */
private void adjustTransformation() {
    Map map = getMapEnv().getMap();
    List<String> locs = map.getLocations();
    // adjust coordinates relative to the left upper corner of the graph
    // area
    double minX = Double.POSITIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    for (String loc : locs) {
        Point2D xy = map.getPosition(loc);
        if (xy.getX() < minX)
            minX = xy.getX();
        if (xy.getY() < minY)
            minY = xy.getY();
        if (xy.getX() > maxX)
            maxX = xy.getX();
        if (xy.getY() > maxY)
            maxY = xy.getY();
    }
    this.setBorder(20, 20, 20, 100);
    adjustTransformation(minX, minY, maxX, maxY);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Map(aima.core.environment.map.Map)

Example 23 with Point2D

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

the class MapAgentView method paintLoc.

protected void paintLoc(java.awt.Graphics2D g2, String loc) {
    Map map = getMapEnv().getMap();
    Point2D pt = map.getPosition(loc);
    if (pt != null) {
        int x = x(pt);
        int y = y(pt);
        String info = "";
        List<String> track = new ArrayList<String>();
        if (!env.getAgents().isEmpty())
            // show details only for track of first agent...
            track = getTrack(env.getAgents().get(0));
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < track.size(); i++) if (track.get(i).equals(loc))
            list.add(i + 1);
        if (!list.isEmpty())
            info = list.toString();
        if (getAgentLocs().contains(loc)) {
            g2.setColor(Color.red);
            g2.fillOval(x - 4, y - 4, 8, 8);
        }
        if (track.contains(loc))
            g2.setColor(Color.black);
        else
            g2.setColor(Color.gray);
        g2.drawString(loc + info, x, y);
    }
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) ArrayList(java.util.ArrayList) Map(aima.core.environment.map.Map)

Example 24 with Point2D

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

the class CspViewCtrl method getPosition.

/**
     * Provides a 2D-position for each variable. If no mapping is given, a simple grid position is computed.
     */
protected Point2D getPosition(VAR var) {
    int[] pos = positionMapping.get(var);
    if (pos != null)
        return new Point2D(pos[0], pos[1]);
    else {
        int vIndex = csp.indexOf(var);
        int rows = Math.max((int) (pane.getHeight() / 100), 1);
        int x = (vIndex / rows) * 160 + 40;
        int y = (vIndex % rows) * 100 + 40;
        return new Point2D(x, y);
    }
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Constraint(aima.core.search.csp.Constraint)

Example 25 with Point2D

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

the class MapEnvironmentViewCtrl method adjustTransform.

/**
	 * Computes transforms (translations and scaling) and applies them to the
	 * environment state view. Those transforms map location positions in the
	 * map to screen positions in the viewer pane.
	 * @return The scale value.
	 */
private double adjustTransform() {
    double xMin = Double.POSITIVE_INFINITY;
    double xMax = Double.NEGATIVE_INFINITY;
    double yMin = Double.POSITIVE_INFINITY;
    double yMax = Double.NEGATIVE_INFINITY;
    for (String loc : env.getMap().getLocations()) {
        Point2D point = env.getMap().getPosition(loc);
        xMin = Math.min(xMin, point.getX());
        xMax = Math.max(xMax, point.getX());
        yMin = Math.min(yMin, point.getY());
        yMax = Math.max(yMax, point.getY());
    }
    double scale = Math.min((envStateView.getWidth() - 150) / (xMax - xMin), (envStateView.getHeight() - 60) / (yMax - yMin));
    envStateView.setTranslateX((scale * (envStateView.getWidth() - xMin - xMax) / 2.0 - 30));
    envStateView.setTranslateY((scale * (envStateView.getHeight() - yMin - yMax) / 2.0 - 10));
    envStateView.setScaleX(scale);
    envStateView.setScaleY(scale);
    return scale;
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D)

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