Commit 950ed83c authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Removed "VShape.copy()", renamed "AttributesAgentPsychology" to...

Removed "VShape.copy()", renamed "AttributesAgentPsychology" to "PsychologyStatus" and updated migration ""
parent d170372a
......@@ -15,8 +15,8 @@ import java.util.List;
* Rename following pedestrian attributes:
* - "targetOrientationAngleThreshold" to "walkingDirectionSameIfAngleLessOrEqual"
* - "angleCalculationType" to "walkingDirectionCalculation"
*
* Also adapt possible values for "walkingDirectionCalculation".
* Also adapt possible values for "walkingDirectionCalculation".
* - "psychology" to "psychologyStatus"
*/
@MigrationTransformation(targetVersionLabel = "1.6")
public class TargetVersionV1_6 extends SimpleJsonTransformation {
......@@ -29,6 +29,7 @@ public class TargetVersionV1_6 extends SimpleJsonTransformation {
protected void initDefaultHooks() {
addPostHookFirst(this::renameTargetOrientationAngleThreshold);
addPostHookFirst(this::renameAngleCalculationType);
addPostHookFirst(this::renamePsychology);
addPostHookLast(this::sort);
}
......@@ -56,6 +57,18 @@ public class TargetVersionV1_6 extends SimpleJsonTransformation {
return node;
}
public JsonNode renamePsychology(JsonNode node) throws MigrationException {
String oldName = "psychology";
String newName = "psychologyStatus";
renameInTopographyUnderAttributesPedestrian(node, oldName, newName);
renameInTopographyUnderAttributesCar(node, oldName, newName);
renameInMainModel(node, oldName, newName);
renameInDynamicElements(node, oldName, newName);
return node;
}
private void renameInTopographyUnderAttributesPedestrian(JsonNode node, String oldName, String newName) throws MigrationException {
JsonNode attributesPedestrianNode = pathMustExist(node, "scenario/topography/attributesPedestrian");
renameField((ObjectNode)attributesPedestrianNode, oldName, newName);
......
package org.vadere.state.attributes.scenario;
package org.vadere.state.psychology;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
public class AttributesAgentPsychology {
public class PsychologyStatus {
// Member Variables
private Stimulus mostImportantStimulus;
private SelfCategory selfCategory;
// Constructors
public AttributesAgentPsychology() {
public PsychologyStatus() {
this(null, SelfCategory.TARGET_ORIENTED);
}
public AttributesAgentPsychology(Stimulus mostImportantStimulus, SelfCategory selfCategory) {
public PsychologyStatus(Stimulus mostImportantStimulus, SelfCategory selfCategory) {
this.mostImportantStimulus = mostImportantStimulus;
this.selfCategory = selfCategory;
}
public PsychologyStatus(PsychologyStatus other) {
this.mostImportantStimulus = other.getMostImportantStimulus() != null ? other.getMostImportantStimulus().clone() : null;
this.selfCategory = other.getSelfCategory();
}
// Getter
public Stimulus getMostImportantStimulus() { return mostImportantStimulus; }
public SelfCategory getSelfCategory() { return selfCategory; }
......
......@@ -27,7 +27,10 @@ public class WaitInArea extends Stimulus {
public WaitInArea(WaitInArea other) {
super(other.time);
this.area = other.getArea().copy();
// According to BZ, "VShape" can be seen as immutable (i.e., usually
// they have only "final" fields). Therefore, use "other.getArea()" directly
// instead of cloning or allocating a new one.
this.area = other.getArea();
}
// Getter
......
package org.vadere.state.scenario;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesAgentPsychology;
import org.vadere.state.psychology.PsychologyStatus;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.simulation.FootStep;
......@@ -26,7 +26,8 @@ public class Pedestrian extends Agent {
private boolean isChild; // TODO should actually be an attribute or a member of a subclass
private boolean isLikelyInjured; // TODO should actually be an attribute or a member of a subclass
private AttributesAgentPsychology psychology;
private PsychologyStatus psychologyStatus;
private LinkedList<Integer> groupIds; // TODO should actually be an attribute or a member of a subclass
private LinkedList<Integer> groupSizes;
......@@ -60,7 +61,7 @@ public class Pedestrian extends Agent {
idAsTarget = -1;
isChild = false;
isLikelyInjured = false;
psychology = new AttributesAgentPsychology(null, SelfCategory.TARGET_ORIENTED);
psychologyStatus = new PsychologyStatus(null, SelfCategory.TARGET_ORIENTED);
groupIds = new LinkedList<>();
groupSizes = new LinkedList<>();
modelPedestrianMap = new HashMap<>();
......@@ -75,10 +76,7 @@ public class Pedestrian extends Agent {
isChild = other.isChild;
isLikelyInjured = other.isLikelyInjured;
psychology = new AttributesAgentPsychology(
other.getMostImportantStimulus() != null ? other.getMostImportantStimulus().clone() : null,
other.getSelfCategory()
);
psychologyStatus = new PsychologyStatus(other.psychologyStatus);
if (other.groupIds != null) {
groupIds = new LinkedList<>(other.groupIds);
......@@ -103,8 +101,8 @@ public class Pedestrian extends Agent {
public boolean isLikelyInjured() {
return isLikelyInjured;
}
public Stimulus getMostImportantStimulus() { return psychology.getMostImportantStimulus(); }
public SelfCategory getSelfCategory() { return psychology.getSelfCategory(); }
public Stimulus getMostImportantStimulus() { return psychologyStatus.getMostImportantStimulus(); }
public SelfCategory getSelfCategory() { return psychologyStatus.getSelfCategory(); }
public LinkedList<Integer> getGroupIds() { return groupIds; }
public LinkedList<Integer> getGroupSizes() {
return groupSizes;
......@@ -151,8 +149,8 @@ public class Pedestrian extends Agent {
public void setLikelyInjured(boolean likelyInjured) {
this.isLikelyInjured = likelyInjured;
}
public void setMostImportantStimulus(Stimulus mostImportantStimulus) { psychology.setMostImportantStimulus(mostImportantStimulus); }
public void setSelfCategory(SelfCategory selfCategory) { psychology.setSelfCategory(selfCategory); }
public void setMostImportantStimulus(Stimulus mostImportantStimulus) { psychologyStatus.setMostImportantStimulus(mostImportantStimulus); }
public void setSelfCategory(SelfCategory selfCategory) { psychologyStatus.setSelfCategory(selfCategory); }
public void setGroupIds(LinkedList<Integer> groupIds) {
this.groupIds = groupIds;
}
......
......@@ -195,9 +195,4 @@ public class DataTriangle extends VTriangle {
return dataPoints;
}
@Override
public DataTriangle copy() {
DataPoint measurePointCopy = new DataPoint(measurePoint.x, measurePoint.y, measurePoint.getData());
return new DataTriangle(p1.clone(), p2.clone(), p3.clone(), measurePointCopy);
}
}
......@@ -344,8 +344,4 @@ public class VCircle implements VShape, ICircleSector {
'}';
}
@Override
public VCircle copy() {
return new VCircle(center.clone(), radius);
}
}
......@@ -17,9 +17,4 @@ public class VDisc extends VCircle {
return getCenter().distance(pos) - getRadius();
}
@Override
public VDisc copy() {
return new VDisc(getCenter().clone(), getRadius());
}
}
......@@ -700,8 +700,4 @@ public class VPolygon extends Path2D.Double implements VShape {
return builder.toString();
}
@Override
public VPolygon copy() {
return new VPolygon(this);
}
}
......@@ -2,7 +2,6 @@ package org.vadere.util.geometry.shapes;
import org.vadere.util.geometry.GeometryUtils;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -208,9 +207,4 @@ public class VRectangle extends Rectangle2D.Double implements VShape {
return lines;
}
@Override
public VRectangle copy() {
return new VRectangle(x, y, width, height);
}
}
......@@ -254,9 +254,4 @@ public class VRing implements VShape {
throw new UnsupportedOperationException("not yet implemented.");
}
@Override
public VRing copy() {
return new VRing(center.clone(), radiusInnerCircle, radiusOuterCircle);
}
}
......@@ -29,14 +29,6 @@ public interface VShape extends Shape, Cloneable {
VShape scale(final double scalar);
/**
* Require a "copy()" method instead of the usual "clone() method
* because subclass {@link VPolygon} extends {@link Path2D.Double} which
* already provides a "clone()" that conflicts with this method signature
* (it does not return a (sub-) type VShape).
*/
VShape copy();
default boolean atBorder(final VPoint point){
VShape circle = new VCircle(new VPoint(point.getX(), point.getY()), BORDER_TOLERANCE);
return intersects(circle) && !containsShape(circle);
......
......@@ -246,8 +246,4 @@ public class VTriangle extends VPolygon {
return "["+p1 + "," + p2 + "," + p3 + "]";
}
@Override
public VTriangle copy() {
return new VTriangle(p1.clone(), p2.clone(), p3.clone());
}
}
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