Ejemplo n.º 1
0
 @Override
 public Point normalize(Point p) {
   if (isOnField(p)) {
     return p;
   }
   double x = Math.min(Math.max(botSize, p.x()), width - botSize);
   double y = Math.min(Math.max(botSize, p.y()), height - botSize);
   return new Point(x, y);
 }
Ejemplo n.º 2
0
 @Override
 public Point closestBorderPoint(Point point) {
   Point p = normalize(point);
   Point a, b;
   if (p.x() < width / 2) {
     // on left side
     a = new Point(0, p.y());
   } else {
     // on right side
     a = new Point(width, p.y());
   }
   if (p.y() < height / 2) {
     b = new Point(p.x(), 0);
   } else {
     b = new Point(p.x(), height);
   }
   return p.bearingTo(a).distance() < p.bearingTo(b).distance() ? a : b;
 }
Ejemplo n.º 3
0
 @Override
 public boolean isOnField(Point p) {
   return !(p.x() < 0 || p.y() < 0 || p.x() > width || p.y() > height);
 }