Skip to content

Commit

Permalink
Refactor getDestination -> interpolatePositions
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Dec 12, 2019
1 parent a3411ca commit db0adfc
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Cohesion<T, P : Position<P>>(

override fun group(): List<Pedestrian<T>> = pedestrian.membershipGroup.members

override fun getDestination(current: P, target: P, maxWalk: Double): P = super.getDestination(
override fun interpolatePositions(current: P, target: P, maxWalk: Double): P = super.interpolatePositions(
target,
centroid() - current,
maxWalk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ class Combine<T, P : Position<P>>(
pedestrian,
TargetSelectionStrategy { steerStrategy.computeTarget(actions) }
) {
override fun getDestination(current: P, target: P, maxWalk: Double): P = steerStrategy.computeNextPosition(actions)
override fun interpolatePositions(current: P, target: P, maxWalk: Double): P = steerStrategy.computeNextPosition(actions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ open class Flee<T, P : Position<P>>(
vararg coords: Double
) : Seek<T, P>(env, reaction, pedestrian, *coords) {

override fun getDestination(current: P, target: P, maxWalk: Double): P = super.getDestination(target, current, maxWalk)
override fun interpolatePositions(current: P, target: P, maxWalk: Double): P = super.interpolatePositions(target, current, maxWalk)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class FlowFieldSteeringAction<T>(
}
}
) {
override fun getDestination(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double) =
override fun interpolatePositions(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double) =
current.surrounding(env, maxWalk)
.filter { env.canNodeFitPosition(pedestrian, it) }
.formula(targetMolecule) - current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class ObstacleAvoidance<W : Obstacle2D, T, P : Position2D<P>>(
} }
) {

override fun getDestination(current: P, target: P, maxWalk: Double): P =
super.getDestination(
override fun interpolatePositions(current: P, target: P, maxWalk: Double): P =
super.interpolatePositions(
current,
env.getObstaclesInRange(current.x, current.y, proximityRange)
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Separation<T>(
.filterIsInstance<Pedestrian<T>>()
.plusElement(pedestrian)

override fun getDestination(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double): Euclidean2DPosition =
super.getDestination(
override fun interpolatePositions(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double): Euclidean2DPosition =
super.interpolatePositions(
target,
centroid(),
maxWalk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class SteeringActionImpl<T, P : Position<P>> @JvmOverloads constructor(
override fun cloneAction(n: Node<T>?, r: Reaction<T>?) =
SteeringActionImpl(env, r!!, n as Pedestrian<T>, target, speed, routing)

override fun getDestination(current: P, target: P, maxWalk: Double): P = with(current.getDistanceTo(target)) {
override fun interpolatePositions(current: P, target: P, maxWalk: Double): P = with(current.getDistanceTo(target)) {
if (this < maxWalk)
target
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ open class Wander<T>(
}
}

override fun getDestination(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double) =
super.getDestination(
override fun interpolatePositions(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double) =
super.interpolatePositions(
env.origin(),
heading().asAngle()
.let { Euclidean2DPosition(offset * cos(it), offset * sin(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public final P getNextPosition() {
}
if (route.size() < 1) {
resetRoute();
return getDestination(curPos, end, maxWalk);
return interpolatePositions(curPos, end, maxWalk);
}
do {
final P target = route.getPoint(curStep);
Expand All @@ -118,7 +118,7 @@ public final P getNextPosition() {
/*
* I can arrive at most at maxWalk
*/
return getDestination(curPos, target, maxWalk);
return interpolatePositions(curPos, target, maxWalk);
}
curStep++;
maxWalk -= toWalk;
Expand All @@ -128,7 +128,7 @@ public final P getNextPosition() {
* I've followed the whole route
*/
resetRoute();
return getDestination(curPos, end, maxWalk);
return interpolatePositions(curPos, end, maxWalk);
}

/**
Expand All @@ -140,7 +140,7 @@ public final P getNextPosition() {
* @param maxWalk how far the node can move
* @return the position that the node reaches
*/
protected abstract P getDestination(P current, P target, double maxWalk);
protected abstract P interpolatePositions(P current, P target, double maxWalk);

/**
* @return the current target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public MoveToTarget<T, P> cloneAction(final Node<T> n, final Reaction<T> r) {
}

@Override
protected P getDestination(final P current, final P target, final double maxWalk) {
protected P interpolatePositions(final P current, final P target, final double maxWalk) {
final P vector = target.minus(current);
if (current.getDistanceTo(target) < maxWalk) {
return vector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public MoveOnMap<T> cloneAction(final Node<T> n, final Reaction<T> r) {
}

@Override
protected final GeoPosition getDestination(final GeoPosition current, final GeoPosition target, final double maxWalk) {
protected final GeoPosition interpolatePositions(final GeoPosition current, final GeoPosition target, final double maxWalk) {
return MapUtils.getDestinationLocation(current, target, maxWalk);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlin.math.cos
import kotlin.math.sin

/**
* It's an [AbstractConfigurableMoveNode] for [Euclidean2DPosition] which provides a default [getDestination] that is
* It's an [AbstractConfigurableMoveNode] for [Euclidean2DPosition] which provides a default [interpolatePositions] that is
* accurate in regards to the target given and the current maximum speed.
*/
abstract class AbstractConfigurableMoveNodeWithAccurateEuclideanDestination<T>(
Expand All @@ -25,7 +25,7 @@ abstract class AbstractConfigurableMoveNodeWithAccurateEuclideanDestination<T>(
* If [maxWalk] is greater than the speed needed to reach [target] then it positions precisely on [target] without going
* farther.
*/
override fun getDestination(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double): Euclidean2DPosition =
override fun interpolatePositions(current: Euclidean2DPosition, target: Euclidean2DPosition, maxWalk: Double): Euclidean2DPosition =
with(target - current) {
if (getDistanceTo(current) < maxWalk) {
this
Expand Down

0 comments on commit db0adfc

Please sign in to comment.