use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class Line2DTest method setUp.
@Before
public void setUp() throws Exception {
testLine = new Line2D(2.0d, 3.0d, 4.0d, 5.0d);
testLine2 = new Line2D(6.0d, 4.0d, 6.0d, -3.0d);
testLine3 = new Line2D(6.0d, -3.0d, 2.0d, 2.0d);
testLine4 = new Line2D(3.0d, 4.0d, 6.0d, 4.0d);
zeroPoint = new Point2D(0.0d, 0.0d);
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class Polyline2DTest method testRandomPoint.
@Test
public final void testRandomPoint() {
Point2D randomPoint = testPolylineOpen.randomPoint();
for (int i = 0; i < 1000; i++) {
randomPoint = testPolylineOpen.randomPoint();
assertTrue("Random point on polyline.", testPolylineOpen.isInsideBorder(randomPoint));
}
for (int i = 0; i < 1000; i++) {
randomPoint = testPolylineClosed.randomPoint();
assertTrue("Random point in polygon.", testPolylineClosed.isInsideBorder(testPolylineClosed.randomPoint()));
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class MapAgentView method paintTrack.
/** The track of the agent is visualized with red lines. */
private void paintTrack(java.awt.Graphics2D g2, Agent a) {
Map map = getMapEnv().getMap();
Point2D lastPt = null;
g2.setColor(Color.red);
for (String loc : getTrack(a)) {
Point2D pt = map.getPosition(loc);
if (pt != null && lastPt != null) {
g2.drawLine(x(pt), y(pt), x(lastPt), y(lastPt));
}
lastPt = pt;
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class ExtendedMapAgentView method paintLoc.
/** Displays a map location. */
protected void paintLoc(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 (scenario != null && scenario.getInitAgentLocation().equals(loc)) {
g2.setColor(Color.red);
g2.fillOval(x - 7, y - 7, 14, 14);
}
if (getAgentLocs().contains(loc)) {
g2.setColor(Color.red);
g2.fillOval(x - 4, y - 4, 8, 8);
}
// else
if (destinations != null && destinations.contains(loc))
g2.setColor(Color.green);
else if (track.contains(loc))
g2.setColor(Color.black);
else
g2.setColor(Color.gray);
g2.drawString(loc + info, x, y);
}
}
use of aima.core.util.math.geom.shapes.Point2D in project aima-java by aimacode.
the class MapAgentView method paintMap.
/**
* Represents roads by lines and locations by name-labeled points.
*/
protected void paintMap(java.awt.Graphics2D g2) {
Map envMap = getMapEnv().getMap();
for (String l1 : envMap.getLocations()) {
Point2D pt1 = envMap.getPosition(l1);
List<String> linkedLocs = envMap.getPossibleNextLocations(l1);
for (String l2 : linkedLocs) {
Point2D pt2 = envMap.getPosition(l2);
g2.setColor(Color.lightGray);
g2.drawLine(x(pt1), y(pt1), x(pt2), y(pt2));
}
}
}
Aggregations