예제 #1
0
 @Override
 public int hitByPoint(JEnvironment env, JRequest req, Point2D point) {
   if (isLocked() || !isVisible()) return JRequest.HIT_NON;
   Shape s = getShape();
   if (s.contains(point)) {
     req.hitObjects.add(this);
     return (req.hitResult = JRequest.HIT_OBJECT);
   }
   double radius = JEnvironment.PATH_SELECTOR_SIZE / 2 / env.getToScreenRatio();
   Rectangle2D.Double sr = new Rectangle2D.Double(0, 0, radius * 2, radius * 2);
   PathIterator path = s.getPathIterator(null);
   double[] coords = new double[6];
   while (!path.isDone()) {
     int type = path.currentSegment(coords);
     if (type == path.SEG_LINETO || type == path.SEG_MOVETO) {
       sr.x = coords[0] - radius;
       sr.y = coords[1] - radius;
       if (sr.contains(point)) {
         req.hitObjects.add(this);
         return (req.hitResult = JRequest.HIT_OBJECT);
       }
     }
     path.next();
   }
   return JRequest.HIT_NON;
 }
예제 #2
0
파일: Geoset.java 프로젝트: Retera/JWC3
 public ArrayList<Vertex> getVertecesInArea(Rectangle2D.Double area, byte dim1, byte dim2) {
   ArrayList<Vertex> temp = new ArrayList<Vertex>();
   for (Vertex ver : vertex) {
     //             Point2D.Double p = new Point(ver.getCoords(dim1),ver.getCoords(dim2))
     if (area.contains(ver.getCoord(dim1), ver.getCoord(dim2))) {
       temp.add(ver);
     }
   }
   return temp;
 }
예제 #3
0
파일: Geoset.java 프로젝트: Retera/JWC3
 public ArrayList<TVertex> getTVertecesInArea(Rectangle2D.Double area, int layerId) {
   ArrayList<TVertex> temp = new ArrayList<TVertex>();
   for (int i = 0; i < vertex.size(); i++) {
     TVertex ver = vertex.get(i).getTVertex(layerId);
     //             Point2D.Double p = new Point(ver.getCoords(dim1),ver.getCoords(dim2))
     if (area.contains(ver.getX(), ver.getY())) {
       temp.add(ver);
     }
   }
   return temp;
 }
 public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) {
   LinkedList<Figure> contained = new LinkedList<Figure>();
   for (Figure f : children) {
     Rectangle2D r = f.getBounds();
     if (AttributeKeys.TRANSFORM.get(f) != null) {
       r = AttributeKeys.TRANSFORM.get(f).createTransformedShape(r).getBounds2D();
     }
     if (f.isVisible() && bounds.contains(r)) {
       contained.add(f);
     }
   }
   return contained;
 }
예제 #5
0
 public void mousePressed(MouseEvent e) {
   if (e.isPopupTrigger()) {
     showPopup(e);
     return;
   }
   if (stack == null && layer != null) stack = layer.getLookup().lookup(ShapeStack.class);
   List<Primitive> l = stack.getPrimitives();
   Rectangle2D.Double scratch = new Rectangle2D.Double(0, 0, 0, 0);
   Point point = mousePressPoint = e.getPoint();
   if (shape != null) {
     ControlPoint[] p = new ControlPointFactory().getControlPoints((Adjustable) shape, this);
     for (int i = 0; i < p.length; i++) {
       ControlPoint pt = p[i];
       if (pt.hit(point.x, point.y)) {
         setSelectedControlPoint(pt);
         return;
       }
     }
   }
   boolean found = false;
   for (Primitive p : l) {
     if (p instanceof Vector) {
       Vector vector = (Vector) p;
       Shape shape = vector.toShape();
       if (shape.contains(point.x, point.y)) {
         setSelectedShape(p);
         found = true;
       }
     } else if (p instanceof Volume) {
       Volume volume = (Volume) p;
       volume.getBounds(scratch);
       System.err.println(p);
       if (scratch.contains(point.x, point.y)) {
         setSelectedShape(p);
         found = true;
       }
     }
   }
   if (!found) {
     setSelectedShape(null);
   }
 }
예제 #6
0
 private void showPopup(MouseEvent e) {
   Point point = e.getPoint();
   List<Primitive> l = stack.getPrimitives();
   Rectangle2D.Double scratch = new Rectangle2D.Double(0, 0, 0, 0);
   List<Primitive> shapes = new ArrayList<Primitive>();
   List<Vector> vectors = new ArrayList<Vector>();
   Primitive topMost = null;
   for (Primitive p : l) {
     if (p instanceof Vector) {
       Vector vector = (Vector) p;
       Shape shape = vector.toShape();
       System.err.println(shape);
       if (shape.contains(point.x, point.y)) {
         topMost = vector;
         shapes.add(vector);
         vectors.add(vector);
       }
     } else if (p instanceof Volume) {
       Volume volume = (Volume) p;
       volume.getBounds(scratch);
       System.err.println(p);
       if (scratch.contains(point.x, point.y)) {
         topMost = volume;
         shapes.add(volume);
       }
     }
   }
   if (!shapes.isEmpty()) {
     assert topMost != null;
     JPopupMenu menu = new JPopupMenu();
     menu.add(new FrontBackAction(true, topMost, stack));
     menu.add(new FrontBackAction(false, topMost, stack));
     menu.add(new CSGAction(UNION, vectors, stack));
     menu.add(new CSGAction(INTERSECTION, vectors, stack));
     menu.add(new CSGAction(SUBTRACTION, vectors, stack));
     menu.add(new CSGAction(XOR, vectors, stack));
     menu.show(repainter.getDialogParent(), point.x, point.y);
   }
 }
예제 #7
0
  public void onScannedRobot(ScannedRobotEvent e) {

    /*-------- setup data -----*/
    if (enemyName == null) {

      enemyName = e.getName();
    }
    Point2D.Double robotLocation = new Point2D.Double(bot.getX(), bot.getY());
    double theta;
    final double enemyAbsoluteBearing = bot.getHeadingRadians() + e.getBearingRadians();
    final double enemyDistance = e.getDistance();
    enemyLocation = projectMotion(robotLocation, enemyAbsoluteBearing, enemyDistance);
    final double enemyEnergy = e.getEnergy();

    Rectangle2D.Double BF = new Rectangle2D.Double(18, 18, 764, 564);

    /*
        To explain the below; if the enemy's absolute acceleration is
        zero then we segment on time since last velocity change, lateral
        acceleration and lateral velocity.
        If their absolute acceleration is non zero then we segment on absolute
        acceleration and absolute velocity.
        Regardless we segment on walls (near/far approach to walls) and distance.
        I'm trying to have my cake and eat it, basically. :-)
    */
    MicroWave w = new MicroWave();

    final double lastLatVel = enemyLatVel;
    double lastVelocity = enemyVelocity;
    enemyLatVel =
        (enemyVelocity = e.getVelocity()) * Math.sin(e.getHeadingRadians() - enemyAbsoluteBearing);

    int distanceIndex = (int) enemyDistance / 140;

    double bulletPower = distanceIndex == 0 ? 3 : 2;
    theta = Math.min(bot.getEnergy() / 4, Math.min(enemyEnergy / 4, bulletPower));
    if (theta == bulletPower) bot.addCustomEvent(w);
    bulletPower = theta;
    w.bulletVelocity = 20D - 3D * bulletPower;

    int accelIndex = (int) Math.round(Math.abs(enemyLatVel) - Math.abs(lastLatVel));

    if (enemyLatVel != 0) bearingDirection = enemyLatVel > 0 ? 1 : -1;
    w.bearingDirection = bearingDirection * Math.asin(8D / w.bulletVelocity) / GF_ZERO;

    double moveTime = w.bulletVelocity * lastVChangeTime++ / enemyDistance;
    int bestGF = moveTime < .1 ? 1 : moveTime < .3 ? 2 : moveTime < 1 ? 3 : 4;

    int vIndex = (int) Math.abs(enemyLatVel / 3);

    if (Math.abs(Math.abs(enemyVelocity) - Math.abs(lastVelocity)) > .6) {
      lastVChangeTime = 0;
      bestGF = 0;

      accelIndex = (int) Math.round(Math.abs(enemyVelocity) - Math.abs(lastVelocity));
      vIndex = (int) Math.abs(enemyVelocity / 3);
    }

    if (accelIndex != 0) accelIndex = accelIndex > 0 ? 1 : 2;

    w.firePosition = robotLocation;
    w.enemyAbsBearing = enemyAbsoluteBearing;
    // now using PEZ' near-wall segment
    w.waveGuessFactors =
        guessFactors[accelIndex][bestGF][vIndex][
            BF.contains(
                    projectMotion(
                        robotLocation,
                        enemyAbsoluteBearing + w.bearingDirection * GF_ZERO,
                        enemyDistance))
                ? 0
                : BF.contains(
                        projectMotion(
                            robotLocation,
                            enemyAbsoluteBearing + .5 * w.bearingDirection * GF_ZERO,
                            enemyDistance))
                    ? 1
                    : 2][
            distanceIndex];

    bestGF = GF_ZERO;

    for (int gf = GF_ONE; gf >= 0 && enemyEnergy > 0; gf--)
      if (w.waveGuessFactors[gf] > w.waveGuessFactors[bestGF]) bestGF = gf;

    bot.setTurnGunRightRadians(
        Utils.normalRelativeAngle(
            enemyAbsoluteBearing
                - bot.getGunHeadingRadians()
                + w.bearingDirection * (bestGF - GF_ZERO)));

    if (bot.getEnergy() > 1 || distanceIndex == 0) bot.setFire(bulletPower);

    bot.setTurnRadarRightRadians(
        Utils.normalRelativeAngle(enemyAbsoluteBearing - bot.getRadarHeadingRadians()) * 2);
  }
 /** Ensures that the robot does not make contact with the wall */
 public static double wallSmoothing(Point2D.Double location, double angle, int orientation) {
   while (!worldApproximation.contains(project(location, angle, WALL_STICK))) {
     angle += orientation * 0.05;
   }
   return angle;
 }
예제 #9
0
 @Override
 public boolean contains(Point2D.Double p) {
   return rec.contains(p);
 }