Commit 0e3e43c1 authored by mey's avatar mey
Browse files

added Rotation2D.java and test

added DirectionConstants
    moved direction constants from DirectionUtil
        updated imports in de.zmt.pathfinding
removed DirectionUtil
    made obsolete by Rotation2D
MathUtil.java
    moved normalizeAngle from DirectionUtil
parent 4e1f8ce3
package de.zmt.pathfinding; package de.zmt.pathfinding;
import static de.zmt.util.DirectionUtil.NEUTRAL; import static sim.util.DirectionConstants.NEUTRAL;
import sim.display.GUIState; import sim.display.GUIState;
import sim.field.grid.ObjectGrid2D; import sim.field.grid.ObjectGrid2D;
......
package de.zmt.pathfinding; package de.zmt.pathfinding;
import static de.zmt.util.DirectionUtil.NEUTRAL; import static sim.util.DirectionConstants.NEUTRAL;
import sim.util.Double2D; import sim.util.Double2D;
...@@ -52,15 +52,15 @@ public class FlowFromFlowsMap extends DerivedFlowMap<FlowMap> { ...@@ -52,15 +52,15 @@ public class FlowFromFlowsMap extends DerivedFlowMap<FlowMap> {
* the weight to associate the first map with * the weight to associate the first map with
*/ */
public FlowFromFlowsMap(FlowMap firstMap, double weight) { public FlowFromFlowsMap(FlowMap firstMap, double weight) {
super(firstMap.getWidth(), firstMap.getHeight()); super(firstMap.getWidth(), firstMap.getHeight());
// speedup if grid-backed // speedup if grid-backed
if (firstMap instanceof GridBackedFlowMap) { if (firstMap instanceof GridBackedFlowMap) {
addMapInternal(firstMap, weight); addMapInternal(firstMap, weight);
getMapGrid().setTo(((GridBackedFlowMap) firstMap).getMapGrid()); getMapGrid().setTo(((GridBackedFlowMap) firstMap).getMapGrid());
} else { } else {
addMap(firstMap); addMap(firstMap);
} }
} }
/** /**
......
package de.zmt.pathfinding; package de.zmt.pathfinding;
import static de.zmt.util.DirectionUtil.*; import static sim.util.DirectionConstants.*;
import java.util.logging.Logger; import java.util.logging.Logger;
......
...@@ -41,8 +41,8 @@ public interface MapChangeNotifier { ...@@ -41,8 +41,8 @@ public interface MapChangeNotifier {
* Changes are propagated when they are first requested. Listeners are * Changes are propagated when they are first requested. Listeners are
* marked dirty on changes. (Default) * marked dirty on changes. (Default)
*/ */
LAZY, LAZY,
/** /**
* Changes are immediately propagated when they happen. Update of * Changes are immediately propagated when they happen. Update of
* listeners is done immediately. * listeners is done immediately.
*/ */
......
...@@ -22,8 +22,8 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp { ...@@ -22,8 +22,8 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp {
} }
/** /**
* Constructs a new {@link AbstractGridFilteringOp}. For handling grid edges the * Constructs a new {@link AbstractGridFilteringOp}. For handling grid edges
* given {@link EdgeHandler} is used. * the given {@link EdgeHandler} is used.
* *
* @param edgeHandler * @param edgeHandler
* the edge handler to be used * the edge handler to be used
...@@ -43,7 +43,7 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp { ...@@ -43,7 +43,7 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp {
* @return the resulting grid * @return the resulting grid
*/ */
public DoubleGrid2D filter(DoubleGrid2D src) { public DoubleGrid2D filter(DoubleGrid2D src) {
return filter(src, null, null); return filter(src, null, null);
} }
/** /**
...@@ -58,7 +58,7 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp { ...@@ -58,7 +58,7 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp {
* @return the resulting grid {@code dest} * @return the resulting grid {@code dest}
*/ */
public DoubleGrid2D filter(DoubleGrid2D src, DoubleGrid2D dest) { public DoubleGrid2D filter(DoubleGrid2D src, DoubleGrid2D dest) {
return filter(src, dest, null); return filter(src, dest, null);
} }
/** /**
...@@ -92,30 +92,30 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp { ...@@ -92,30 +92,30 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp {
* @return the resulting grid {@code dest} * @return the resulting grid {@code dest}
*/ */
public DoubleGrid2D filter(DoubleGrid2D src, DoubleGrid2D dest, BooleanGrid selection) { public DoubleGrid2D filter(DoubleGrid2D src, DoubleGrid2D dest, BooleanGrid selection) {
if (src == dest) { if (src == dest) {
throw new IllegalArgumentException("Source and destination grids must be different objects."); throw new IllegalArgumentException("Source and destination grids must be different objects.");
} }
int width = src.getWidth(); int width = src.getWidth();
int height = src.getHeight(); int height = src.getHeight();
if (dest == null) { if (dest == null) {
dest = new DoubleGrid2D(src); dest = new DoubleGrid2D(src);
} }
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
if (selection == null || selection.get(x, y)) { if (selection == null || selection.get(x, y)) {
dest.set(x, y, filter(x, y, src)); dest.set(x, y, filter(x, y, src));
} }
// not selected, copy from source // not selected, copy from source
else { else {
dest.set(x, y, src.get(x, y)); dest.set(x, y, src.get(x, y));
} }
} }
} }
return dest; return dest;
} }
@Override @Override
...@@ -129,6 +129,6 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp { ...@@ -129,6 +129,6 @@ abstract class AbstractGridFilteringOp implements GridFilteringOp {
@Override @Override
public EdgeHandler getEdgeHandler() { public EdgeHandler getEdgeHandler() {
return edgeHandler; return edgeHandler;
} }
} }
\ No newline at end of file
...@@ -22,6 +22,7 @@ public class ConvolveOp extends AbstractGridFilteringOp implements Serializable ...@@ -22,6 +22,7 @@ public class ConvolveOp extends AbstractGridFilteringOp implements Serializable
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final Kernel kernel; private final Kernel kernel;
/** /**
* Constructs a new {@link ConvolveOp} with {@link EdgeHandler#getDefault()} * Constructs a new {@link ConvolveOp} with {@link EdgeHandler#getDefault()}
* . * .
...@@ -49,7 +50,7 @@ public class ConvolveOp extends AbstractGridFilteringOp implements Serializable ...@@ -49,7 +50,7 @@ public class ConvolveOp extends AbstractGridFilteringOp implements Serializable
} }
public Kernel getKernel() { public Kernel getKernel() {
return kernel; return kernel;
} }
@Override @Override
......
...@@ -215,7 +215,7 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends ...@@ -215,7 +215,7 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Graphics2D graphics2d = (Graphics2D) g; Graphics2D graphics2d = (Graphics2D) g;
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
DrawInfo2D drawInfo = getDrawInfo2D(scrollPane.getViewport().getViewRect()); DrawInfo2D drawInfo = getDrawInfo2D(scrollPane.getViewport().getViewRect());
...@@ -236,11 +236,11 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends ...@@ -236,11 +236,11 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends
// get location wrapper for objects at this location // get location wrapper for objects at this location
getPortrayal().hitObjects(displayComponent.getDrawInfo2D(clip), objectLocationWrapper); getPortrayal().hitObjects(displayComponent.getDrawInfo2D(clip), objectLocationWrapper);
if (objectLocationWrapper.size() > 0) { if (objectLocationWrapper.size() > 0) {
LocationWrapper wrapper = (LocationWrapper) objectLocationWrapper.get(0); LocationWrapper wrapper = (LocationWrapper) objectLocationWrapper.get(0);
Int2D location = (Int2D) wrapper.getLocation(); Int2D location = (Int2D) wrapper.getLocation();
infoField.setText("(" + location.getX() + "," + location.getY() + "): " + getObjectInfo(wrapper)); infoField.setText("(" + location.getX() + "," + location.getY() + "): " + getObjectInfo(wrapper));
} else { } else {
infoField.setText(DEFAULT_INFO_FIELD_TEXT); infoField.setText(DEFAULT_INFO_FIELD_TEXT);
} }
} }
...@@ -263,12 +263,12 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends ...@@ -263,12 +263,12 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends
*/ */
private class MyMouseMotionListener implements MouseMotionListener, Serializable { private class MyMouseMotionListener implements MouseMotionListener, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
displayObjectInfo(e.getX(), e.getY()); displayObjectInfo(e.getX(), e.getY());
} }
@Override @Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
} }
...@@ -286,20 +286,20 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends ...@@ -286,20 +286,20 @@ abstract class AbstractPathfindingMapInspector<T extends PathfindingMap> extends
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
displayObjectInfo(e.getX(), e.getY()); displayObjectInfo(e.getX(), e.getY());
} }
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
} }
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
} }
......
...@@ -34,7 +34,6 @@ public class PotentialMapInspector extends AbstractPathfindingMapInspector<Poten ...@@ -34,7 +34,6 @@ public class PotentialMapInspector extends AbstractPathfindingMapInspector<Poten
portrayal.setMap(ColorMapFactory.createForPotentials()); portrayal.setMap(ColorMapFactory.createForPotentials());
} }
/** /**
* Overrides default {@link ColorMap} with a custom one. * Overrides default {@link ColorMap} with a custom one.
* *
......
...@@ -36,7 +36,6 @@ public class FilteringPotentialMapTest { ...@@ -36,7 +36,6 @@ public class FilteringPotentialMapTest {
src.setTo(VALUE); src.setTo(VALUE);
map.markDirty(0, 0); map.markDirty(0, 0);
assertThat("Value in map should reflect changed source.", map.obtainPotential(0, 0), assertThat("Value in map should reflect changed source.", map.obtainPotential(0, 0), is(secondResult));
is(secondResult));
} }
} }
package de.zmt.pathfinding; package de.zmt.pathfinding;
import static de.zmt.util.DirectionUtil.*;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static sim.util.DirectionConstants.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -24,20 +24,20 @@ public class FlowFromFlowsMapTest { ...@@ -24,20 +24,20 @@ public class FlowFromFlowsMapTest {
@Test @Test
public void obtainDirectionOnEmpty() { public void obtainDirectionOnEmpty() {
assertThat(map.obtainDirection(0, 0), is(NEUTRAL)); assertThat(map.obtainDirection(0, 0), is(NEUTRAL));
} }
@Test @Test
public void obtainDirectionOnSingle() { public void obtainDirectionOnSingle() {
map.addMap(FLOW_MAP_SOUTH); map.addMap(FLOW_MAP_SOUTH);
assertThat(map.obtainDirection(0, 0), is(SOUTH)); assertThat(map.obtainDirection(0, 0), is(SOUTH));
} }
@Test @Test
public void obtainDirectionOnMulti() { public void obtainDirectionOnMulti() {
map.addMap(FLOW_MAP_SOUTH); map.addMap(FLOW_MAP_SOUTH);
map.addMap(FLOW_MAP_EAST); map.addMap(FLOW_MAP_EAST);
assertThat(map.obtainDirection(0, 0), is(SOUTHEAST)); assertThat(map.obtainDirection(0, 0), is(SOUTHEAST));
} }
@Test @Test
......
package de.zmt.pathfinding; package de.zmt.pathfinding;
import static de.zmt.util.DirectionUtil.*;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static sim.util.DirectionConstants.*;
import org.hamcrest.Double2DCloseTo; import org.hamcrest.Double2DCloseTo;
import org.junit.Before; import org.junit.Before;
...@@ -26,7 +26,7 @@ public class FlowFromPotentialsMapTest { ...@@ -26,7 +26,7 @@ public class FlowFromPotentialsMapTest {
@Test @Test
public void obtainDirectionOnEmpty() { public void obtainDirectionOnEmpty() {
assertThat(obtainDirectionAtMapCenter(), is(NEUTRAL)); assertThat(obtainDirectionAtMapCenter(), is(NEUTRAL));
} }
@Test @Test
...@@ -104,11 +104,11 @@ public class FlowFromPotentialsMapTest { ...@@ -104,11 +104,11 @@ public class FlowFromPotentialsMapTest {
* @return potential map * @return potential map
*/ */
private static PotentialMap createDirectedMap(Double2D direction) { private static PotentialMap createDirectedMap(Double2D direction) {
int x = (int) Math.round(direction.x) + 1; int x = (int) Math.round(direction.x) + 1;
int y = (int) Math.round(direction.y) + 1; int y = (int) Math.round(direction.y) + 1;
double[][] values = new double[3][3]; double[][] values = new double[3][3];
values[x][y] = 1; values[x][y] = 1;
return new SimplePotentialMap(values); return new SimplePotentialMap(values);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment