Skip to content

Instantly share code, notes, and snippets.

@kornicameister
Last active December 16, 2015 09:59
Show Gist options
  • Save kornicameister/5417303 to your computer and use it in GitHub Desktop.
Save kornicameister/5417303 to your computer and use it in GitHub Desktop.
movePoint
private void movePoint(final Point toBeMoved) {
Point nearestPoint = Solution.getNearest(this.points, toBeMoved);
switch (this.mode) {
case ORDINARY:
Solution.moveToPoint(nearestPoint, toBeMoved);
break;
case ORDINARY_RECT_NEIGH_0_15: {
Solution.moveToPoint(nearestPoint, toBeMoved);
final ValueDistance distance = new ValueDistance(0.15);
List<Point> inAreaPoints = Solution.getMultiNearest(this.points, toBeMoved, distance);
for (Point point : inAreaPoints) {
Solution.moveToPoint(point, toBeMoved, 1.0 / 6.0);
}
}
break;
case ORDINARY_RECT_NEIGHT_16: {
Solution.moveToPoint(nearestPoint, toBeMoved);
final ValueDistance distance = new ValueDistance(16.0);
List<Point> inAreaPoints = Solution.getMultiNearest(this.points, toBeMoved, distance);
for (Point point : inAreaPoints) {
Solution.moveToPoint(point, toBeMoved, 1.0 / 6.0);
}
}
break;
case ORDINARY_GAUSS: {
Solution.moveToPoint(nearestPoint, toBeMoved);
final ValueDistance distance = new GaussDistance(-1.0);
List<Point> inAreaPoints = Solution.getMultiNearest(this.points, toBeMoved);
for (Point point : inAreaPoints) {
Solution.moveToPoint(point, toBeMoved, distance);
}
}
}
}
/***************************************************************************/
public class GaussDistance extends ValueDistance {
final Double alpha = 0.5;
final Double gamma = 0.8;
public GaussDistance(final Double distance) {
super(distance);
}
@Override
public Double distance() {
return this.alpha * Math.exp(this.distance / this.gamma);
}
}
/**************************************************************************/
public static void moveToPoint(Point move, Point moveTo, Distances distance) {
distance.setInitDistance(Solution.distance(move, moveTo));
Double alpha = distance.distance();
move.appendX(alpha * (moveTo.getX() - move.getX()));
move.appendY(alpha * (moveTo.getY() - move.getY()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment