Commit 914db13b authored by Julian Zobel's avatar Julian Zobel
Browse files

Added a minimum distance between APs in the random AP generator

parent 2fdea5df
...@@ -98,6 +98,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa ...@@ -98,6 +98,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled
org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL,NORMAL,LOW org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL,NORMAL,LOW
......
...@@ -37,9 +37,12 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; ...@@ -37,9 +37,12 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* *
* Generates the given number of {@link AttractionPoint}s and sets the * Generates the given number of {@link AttractionPoint}s and sets the
* position randomly within the world dimensions. * position randomly within the world dimensions.
*
* v1.1: statically available attraction points [JZ]
* v1.2: added a minimum distance between attraction points [JZ]
* *
* @author Christoph Muenker, Julian Zobel * @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018 * @version 1.2, 11 2018
*/ */
public class RandomAttractionGenerator implements IAttractionGenerator { public class RandomAttractionGenerator implements IAttractionGenerator {
...@@ -51,6 +54,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator { ...@@ -51,6 +54,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private boolean numberOfAPsSet = false; private boolean numberOfAPsSet = false;
private double minimumDistance = 50;
@XMLConfigurableConstructor({"numberOfAttractionPoints"}) @XMLConfigurableConstructor({"numberOfAttractionPoints"})
public RandomAttractionGenerator(int numberOfAttractionPoints) { public RandomAttractionGenerator(int numberOfAttractionPoints) {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class); this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
...@@ -81,8 +86,17 @@ public class RandomAttractionGenerator implements IAttractionGenerator { ...@@ -81,8 +86,17 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private void createAttractionPoints() { private void createAttractionPoints() {
List<AttractionPoint> result = new LinkedList<AttractionPoint>(); List<AttractionPoint> result = new LinkedList<AttractionPoint>();
for (int i = 0; i < numberOfAttractionPoints; i++) {
create: for (int i = 0; i < numberOfAttractionPoints; i++) {
PositionVector posVec = createPosVec(); PositionVector posVec = createPosVec();
for (AttractionPoint ap : result) {
if(posVec.distanceTo(ap) < minimumDistance) {
i--;
continue create;
}
}
AttractionPoint aPoint = new AttractionPointImpl("AP"+i, posVec); AttractionPoint aPoint = new AttractionPointImpl("AP"+i, posVec);
result.add(aPoint); result.add(aPoint);
} }
...@@ -96,5 +110,12 @@ public class RandomAttractionGenerator implements IAttractionGenerator { ...@@ -96,5 +110,12 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
double y = rand.nextDouble() * worldDimension.getY(); double y = rand.nextDouble() * worldDimension.getY();
return new PositionVector(x, y); return new PositionVector(x, y);
} }
/**
* Set a minimum distance between the randomly generated attraction points
* @param distance
*/
public void setMinimumDistance(double distance) {
this.minimumDistance = distance;
}
} }
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