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