public TestType1CFont(InputStream is) throws IOException {
   super();
   setPreferredSize(new Dimension(800, 800));
   addKeyListener(this);
   BufferedInputStream bis = new BufferedInputStream(is);
   int count = 0;
   ArrayList<byte[]> al = new ArrayList<byte[]>();
   byte b[] = new byte[32000];
   int len;
   while ((len = bis.read(b, 0, b.length)) >= 0) {
     byte[] c = new byte[len];
     System.arraycopy(b, 0, c, 0, len);
     al.add(c);
     count += len;
     b = new byte[32000];
   }
   data = new byte[count];
   len = 0;
   for (int i = 0; i < al.size(); i++) {
     byte from[] = al.get(i);
     System.arraycopy(from, 0, data, len, from.length);
     len += from.length;
   }
   pos = 0;
   //	printData();
   parse();
   // TODO: free up (set to null) unused structures (data, subrs, stack)
 }
Exemplo n.º 2
0
  public int cleanUpTaxiwayParking() {
    ArrayList arrayList = new ArrayList();
    Iterator iterator = taxiwayParkingHM.keySet().iterator();
    do {
      if (!iterator.hasNext()) break;
      int index = ((Integer) iterator.next()).intValue();
      boolean found = false;
      int i = taxiwayPathAL.size() - 1;
      do {
        if (i < 0) break;
        TaxiwayPathModel taxiwayPathModel = (TaxiwayPathModel) taxiwayPathAL.get(i);
        if (taxiwayPathModel.getType().equals("PARKING") && taxiwayPathModel.getEnd() == index) {
          found = true;
          break;
        }
        i--;
      } while (true);
      if (!found) arrayList.add(taxiwayParkingHM.get(new Integer(index)));
    } while (true);
    int totalDeleted = arrayList.size();
    for (int i = arrayList.size() - 1; i >= 0; i--)
      removeTaxiwayParkingModel((TaxiwayParkingModel) arrayList.get(i));

    return totalDeleted;
  }
Exemplo n.º 3
0
  public ArrayList getILSModels() {
    ArrayList arrayList = new ArrayList();
    for (int i = runwayAL.size() - 1; i >= 0; i--)
      arrayList.addAll(((RunwayModel) runwayAL.get(i)).getILSAL());

    return arrayList;
  }
 public void bringToFront(Figure figure) {
   if (children.remove(figure)) {
     children.add(figure);
     needsSorting = true;
     fireAreaInvalidated(figure.getDrawingArea());
   }
 }
Exemplo n.º 5
0
  /* -------------------------------------------------------------*/
  private void objectCollision(ArrayList movingObjects) {
    for (int i = 0; i < movingObjects.size(); i++) {
      // make sure not testing if collided with yourself :P
      if (((SpaceObject) movingObjects.get(i)).getObjCount() != objectNum) {
        SpaceObject object = (SpaceObject) movingObjects.get(i);

        // find distance vector between two objects
        int x = pos_x - object.getXPos();
        int y = pos_y - object.getYPos();

        double distance = Math.sqrt(x * x + y * y);

        // has it collided with the object?
        if (distance < (radius + object.getRadius())) {
          // has it collided with a BULLET (or MISSILE)?
          if (object.isBullet()) {
            // do nothing
          }
          // is it another SPACESHIP? (INSTANT DEATH)
          else if (object.isSpaceShip()) {
            // do nothing
          }
          // collided with anything else (e.g PLANET): (INSTANT DEATH)
          else {
            collision.play();
            kill(movingObjects); // object has died
          }
        }
      }
    } // end for loop
  }
 public void sendToBack(Figure figure) {
   if (children.remove(figure)) {
     children.add(0, figure);
     needsSorting = true;
     fireAreaInvalidated(figure.getDrawingArea());
   }
 }
Exemplo n.º 7
0
 public void addObstacle(PolygonObstacle obstacle) {
   ArrayList<Mat> vertices = new ArrayList<Mat>();
   for (Point2D.Double vert : obstacle.getVertices()) {
     vertices.add(Mat.encodePoint(vert.x, vert.y));
   }
   addObstacle(new Polygon(vertices));
 }
Exemplo n.º 8
0
  /* -------------------------------------------------------------*/
  private void gravityEffect(ArrayList movingObjects) {
    // find effect of gravity on this objects from all other objects
    for (int i = 0; i < movingObjects.size(); i++) {
      // reset variables
      double add_vx = 0.0;
      double add_vy = 0.0;

      SpaceObject object = (SpaceObject) movingObjects.get(i);

      if (object.getObjCount() != objectNum
          && // ignore yourself (distance = 0!)
          !object.isBullet()
          && // ignore bullets
          !object.isSpaceShip()) // ignore spaceships
      {

        // find distance vector between planet and ball
        int x = pos_x - object.getXPos();
        int y = pos_y - object.getYPos();

        double distance = Math.sqrt(x * x + y * y);

        // find effect of planet on velocity
        double add_vec = (SpaceObject.G * k * object.getMass() * ballMass) / (distance * distance);

        add_vx = -(x / distance) * add_vec;
        add_vy = -(y / distance) * add_vec;

        // add objects speeds onto spaceship speed (clip speed if too large)
        x_speed += add_vx;
        y_speed += add_vy;
      }
    }
  }
Exemplo n.º 9
0
    public static boolean pointInPolygon(Polygon poly, Mat point) {
      ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>();
      for (Mat v : poly.vertices) {
        points.add(new Point2D.Double(v.data[0][0], v.data[1][0]));
      }
      PolygonObstacle po = GeomUtils.convexHull(points);
      return po.contains(point.data[0][0], point.data[1][0]);

      /*Mat farPoint = Mat.encodePoint(0, 0);
      double maxDist = -1;
      double dist;

      for (Mat vertex : poly.vertices) {
      	dist = Mat.dist(point, vertex);
      	if (maxDist < dist) {
      		maxDist = dist;
      	}
      }

      farPoint = Mat.add(point, Mat.mul(maxDist + 1, Mat.encodePoint(1, 0)));

      int size = poly.vertices.size();
      int intersections = 0;
      for (int i = 0; i < size; i++) {
      	if (lineSegIntersect(point, farPoint, poly.vertices.get(i), poly.vertices.get((i + 1) % size))) {
      		intersections++;
      	}
      }

      return ((intersections % 2) == 1);*/
    }
Exemplo n.º 10
0
 public ArrayList<Polygon> getCSObstacles() {
   ArrayList<Polygon> csObstacles = new ArrayList<Polygon>();
   for (Polygon obstacle : obstacles) {
     csObstacles.add(Polygon.minkowskiSumSimple(obstacle, reflectedRobot));
   }
   return csObstacles;
 }
Exemplo n.º 11
0
 // Transform a polygon by a matrix
 public static Polygon mul(Mat matrix, Polygon poly) {
   ArrayList<Mat> newVertices = new ArrayList<Mat>();
   for (Mat vertex : poly.vertices) {
     newVertices.add(Mat.mul(matrix, vertex));
   }
   return new Polygon(newVertices);
 }
Exemplo n.º 12
0
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Decorations
 public void newDecos() {
   int prob = (int) (Math.random() * 100); // randomly spawnst he decoration
   if (prob == 1) {
     if (decoList.size() < 1) {
       int prob2 = (int) (Math.random() * 2);
       if (prob2 == 1) { // right side or left side
         decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, false));
       } else {
         decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, true));
       }
     }
   }
   Boolean check = true;
   for (Decorations i : decoList) {
     if (i.getYTop() >= 2000) {
       check = false;
       break;
     }
   }
   if (check == false
       && decoList.size()
           > 0) { // theres only on in the lsit but for consitency we kept it as a list
     decoList.remove(0);
   }
 }
Exemplo n.º 13
0
 public void checkStarCollision() {
   for (Star s : starList) {
     if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides
       if (s.checkCollision(
           s.getPics().get(s.getCounter()),
           player1)) { // if the player collides with the star we remove it then change the
         // velosity to the distance that the star provides
         sRemove.add(s); // remove star once you collide with it
         player1.setVelo(s.getDist()); // changes the velocity
         player1.setInvi(true); // sets the player invisble for a few seconds
         score += s.getPoints(); // points increase by the star type
         if (musicOn) {
           starSound.play(); // playthe star sound
         }
       }
     } else {
       sRemove.add(s); // remove the star if its not on the screen
     }
   }
   for (Star s : sRemove) {
     poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect
     starList.remove(s);
   }
   sRemove = new ArrayList<Star>();
 }
Exemplo n.º 14
0
 public void checkEnemyCollision() {
   for (Enemy e : enemyList) {
     if (e.getOnScreen()) { // can be removed later on
       // goes through all the enemies and checks if they collide
       if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) {
         if (player1.getInvi() == false) {
           // If the player is not invisble then you get spiked.
           if (player1.getVelocity() > 0) { // if the player hits it from the bottom
             player1.setSpikeVelo();
             loseCoins();
           } else {
             player1.setVelo(
                 50); // if the player is on top instead the player bounces off the enemy
             if (musicOn) {
               bounce.play();
             }
           }
         }
         eRemove.add(e); // once we hit, we remove the enemy
       }
     } else {
       eRemove.add(e); // if the enemy goes of the screen, we remove
     }
   }
   for (Enemy e : eRemove) {
     poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies
     enemyList.remove(e);
   }
   eRemove = new ArrayList<Enemy>();
 }
Exemplo n.º 15
0
    // Generates a new polygon by dragging a polygon by a vector and taking all the points it
    // touched.
    public static Polygon stroke(double x, double y, Polygon poly) {
      Polygon polyTrans = mul(Mat.translation(x, y), poly);
      ArrayList<Mat> vertices = new ArrayList<Mat>();
      ArrayList<TreeSet<Integer>> edgesTo = new ArrayList<TreeSet<Integer>>();
      int size = poly.vertices.size();

      // The list of possible vertices of the extrusion
      vertices.addAll(poly.vertices);
      vertices.addAll(polyTrans.vertices);

      // pre-compute some information that will make it easy to find the actual perimeter of the
      // extrusion
      for (int i = 0; i < 2 * size; i++) {
        edgesTo.add(new TreeSet<Integer>());
      }

      for (int i = 0; i < size; i++) {
        edgesTo.get(i).add(new Integer((i + 1) % size));
        edgesTo.get((i + 1) % size).add(new Integer(i));

        edgesTo.get(i + size).add(new Integer(((i + 1) % size) + size));
        edgesTo.get(((i + 1) % size) + size).add(new Integer(i + size));

        edgesTo.get(i).add(new Integer(i + size));
        edgesTo.get(i + size).add(new Integer(i));
      }

      return perimeter(vertices, edgesTo);
    }
Exemplo n.º 16
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Exemplo n.º 17
0
 public Figure basicRemoveChild(int index) {
   Figure figure = children.get(index);
   children.remove(index);
   quadTree.remove(figure);
   figure.removeFigureListener(figureHandler);
   needsSorting = true;
   return figure;
 }
Exemplo n.º 18
0
  /**
   * Returns the list of selected points.
   *
   * @return list of selected points
   */
  public List<WhiteboardPoint> getSelectionPoints() {
    ArrayList<WhiteboardPoint> selectionPoints = new ArrayList<WhiteboardPoint>();

    selectionPoints.add(startPoint);
    selectionPoints.add(endPoint);

    return selectionPoints;
  }
 public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) {
   gp.curveTo(x1, y1, x2, y2, x3, y3);
   this.x = x3;
   this.y = y3;
   points.add(new GlyphPoint(x1, y1, true));
   points.add(new GlyphPoint(x2, y2, true));
   points.add(new GlyphPoint(x3, y3, false));
 }
Exemplo n.º 20
0
  public ArrayList getVORdmeModels() {
    ArrayList arrayList = new ArrayList();
    for (int i = vorAL.size() - 1; i >= 0; i--) {
      VORModel vorModel = (VORModel) vorAL.get(i);
      if (vorModel.getDme()) arrayList.add(vorModel.getDMEModel());
    }

    return arrayList;
  }
Exemplo n.º 21
0
 public void removeILSModel(ILSModel ilsModel) {
   for (int i = runwayAL.size() - 1; i >= 0; i--) {
     ArrayList arrayList = ((RunwayModel) runwayAL.get(i)).getILSAL();
     if (arrayList.contains(ilsModel)) {
       ((RunwayModel) runwayAL.get(i)).removeILSModel(ilsModel);
       return;
     }
   }
 }
Exemplo n.º 22
0
    // Generates a new polygon by dragging a polygon through an angle, and taking all the points it
    // touched (and a few extras for overestimation)
    // Only valid for convex polygons, and small rotations (20 degrees or less)
    // stroke from theta1 to theta2
    public static Polygon strokeRot(double theta1, double theta2, Polygon poly) {
      Polygon poly1 = mul(Mat.rotation(theta1), poly);
      Polygon poly2 = mul(Mat.rotation(theta2), poly);
      Polygon stroked = combine(poly1, poly2);
      ArrayList<Mat> cornerVerts;
      Polygon corner;
      int thisVertex, prevVertex, nextVertex;
      Mat origin = Mat.encodePoint(0, 0);
      Mat cornerVert1a, cornerVert1b;
      Mat cornerVert2a, cornerVert2b;
      double actualDist, desiredDist;
      Mat cornerTransform;
      for (thisVertex = 0; thisVertex < poly.vertices.size(); thisVertex++) {
        if (thisVertex == 0) {
          prevVertex = poly.vertices.size() - 1;
        } else {
          prevVertex = thisVertex - 1;
        }

        if (thisVertex == poly.vertices.size() - 1) {
          nextVertex = 0;
        } else {
          nextVertex = thisVertex + 1;
        }

        cornerVerts = new ArrayList<Mat>();
        cornerVerts.add(poly2.vertices.get(nextVertex));
        cornerVerts.add(origin);
        cornerVerts.add(poly1.vertices.get(prevVertex));

        cornerVert1a = poly1.vertices.get(thisVertex);
        cornerVert2a = poly2.vertices.get(thisVertex);

        actualDist = ptSegDistance(cornerVert1a, cornerVert2a, origin);
        desiredDist = Mat.dist(cornerVert1a, Mat.encodePoint(0, 0));

        cornerTransform = Mat.mul(desiredDist / actualDist, Mat.eye(4));
        cornerVert1b = Mat.mul(cornerTransform, cornerVert1a);
        cornerVert2b = Mat.mul(cornerTransform, cornerVert2a);

        cornerVert1b =
            lineSegIntersection(
                cornerVert1b, cornerVert2b, poly1.vertices.get(prevVertex), cornerVert1a);
        cornerVert2b =
            lineSegIntersection(
                cornerVert1b, cornerVert2b, poly2.vertices.get(nextVertex), cornerVert2a);

        cornerVerts.add(cornerVert1b);
        cornerVerts.add(cornerVert2b);

        corner = new Polygon(cornerVerts);
        stroked = combine(stroked, corner);
      }

      return stroked;
    }
Exemplo n.º 23
0
 protected Iterable<? extends LatLon> computeDrawLocations(
     DrawContext dc, SurfaceTileDrawContext sdc) {
   ArrayList<LatLon> drawList = new ArrayList<LatLon>();
   double safeDistanceDegreesSquared = Math.pow(this.computeSafeRadius(dc, sdc).degrees, 2);
   for (LatLon location : this.getLocations()) {
     if (this.computeLocationDistanceDegreesSquared(sdc.getSector(), location)
         <= safeDistanceDegreesSquared) drawList.add(location);
   }
   return drawList;
 }
Exemplo n.º 24
0
 /** Implementation note: Sorting can not be done for orphaned children. */
 public java.util.List<Figure> sort(Collection<Figure> c) {
   ensureSorted();
   ArrayList<Figure> sorted = new ArrayList<Figure>(c.size());
   for (Figure f : children) {
     if (c.contains(f)) {
       sorted.add(f);
     }
   }
   return sorted;
 }
Exemplo n.º 25
0
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Patterns
 public void newPattern() {
   int prob = (int) (Math.random() * probs.get(level - 1) + 1);
   Pattern p = new Pattern(0, -300, prob, (int) (backy * 0.1));
   if (checkSpawn(new Rectangle(p.getX(), p.getY(), p.getWidth(), p.getHeight())) == true) {
     for (Coin i : p.getCoins()) {
       coinList.add(i);
     }
     for (Star i : p.getStars()) {
       starList.add(i);
     }
     for (Box i : p.getBoxes()) {
       boxList.add(i);
     }
     for (Jumper i : p.getJumpers()) {
       jumperList.add(i);
     }
     for (Enemy i : p.getEnemies()) {
       enemyList.add(i);
     }
     for (Spikes i : p.getSpikes()) {
       spikeList.add(i);
     }
     for (Powerup i : p.getPowerUps()) {
       pupList.add(i);
     }
     for (Rectangle i : p.getRects()) {
       rectList.add(i);
     }
   }
 }
Exemplo n.º 26
0
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Poofs
 public void removePoof() { // once the poof animation is the poof is removed from the list
   for (Poof p : poofList) {
     if (p.isDone()) {
       pRemove.add(p);
     }
   }
   for (Poof p : pRemove) {
     poofList.remove(p);
   }
   pRemove = new ArrayList<Poof>();
 }
Exemplo n.º 27
0
  /**
   * Recalculates the selection points coordinates and adds the new selection points to the list of
   * selection points.
   */
  private void recalculateSelectionPoints() {
    selectionPoints.clear();

    selectionPoints.add(new WhiteboardPoint(point.getX(), point.getY()));

    selectionPoints.add(new WhiteboardPoint(point.getX() + width, point.getY()));

    selectionPoints.add(new WhiteboardPoint(point.getX(), point.getY() + height));

    selectionPoints.add(new WhiteboardPoint(point.getX() + width, point.getY() + height));
  }
Exemplo n.º 28
0
  /**
   * Tests if a point p is over a selection point.
   *
   * @param p point
   * @return nearest selection point
   */
  public WhiteboardPoint getSelectionPoint(Point2D p) {
    WhiteboardPoint givenPoint = new WhiteboardPoint(p.getX(), p.getY());

    for (int i = 0; i < selectionPoints.size(); i++) {
      WhiteboardPoint point = (WhiteboardPoint) selectionPoints.get(i);

      if (point.distance(givenPoint) < 18) return point;
    }

    return null;
  }
Exemplo n.º 29
0
  public ArrayList getILSDMEModels() {
    ArrayList arrayList = new ArrayList();
    for (int i = runwayAL.size() - 1; i >= 0; i--) {
      RunwayModel runwayModel = (RunwayModel) runwayAL.get(i);
      for (int j = runwayModel.getILSAL().size() - 1; j >= 0; j--)
        if (((ILSModel) runwayModel.getILSAL().get(j)).getDMEModel() != null)
          arrayList.add(((ILSModel) runwayModel.getILSAL().get(j)).getDMEModel());
    }

    return arrayList;
  }
Exemplo n.º 30
0
  private void graphGrid(ArrayList<ArrayList<Position>> grid) throws InterruptedException {
    System.out.println(
        "Size of file by rows = " + grid.size() + ", columns = " + grid.get(0).size());
    final long current = System.currentTimeMillis();
    // System.out.println("Time for parsing file: " + ((current - startParseTime) / 1000) + " sec");
    // long afterEdge = 0;
    // long timeFindEdge = 0;

    ArrayList<Integer> ranges = findRanges();
    final Cell<Integer> threadsActive = new Cell<Integer>(threads);
    class EdgeThread extends Thread {

      int startRow = 0;
      int endRow = 0;

      public EdgeThread(int startRow, int endRow) {
        this.startRow = startRow;
        this.endRow = endRow;
      }

      public void run() {
        System.out.println("Thread: " + this.getId());
        findEdges(startRow, endRow);
        boolean lastThread;
        synchronized (threadsActive) {
          lastThread = --threadsActive.object == 0;
        }
        if (lastThread) {
          System.out.println("Last Thread: " + this.getId());
          long afterEdge = System.currentTimeMillis();
          long timeFindEdge = (afterEdge - current) / 1000;
          System.out.println("Time for findEdges: " + timeFindEdge + " sec");

          colorSCC();
          long afterColor = System.currentTimeMillis();
          long timeForColor = (afterColor - afterEdge) / 1000;
          System.out.println("Time for coloring and find CC: " + timeForColor + " sec");
          // findConnectedComponents();
          create();
          long timeForCreate = (System.currentTimeMillis() - afterColor) / 1000;
          System.out.println("Time for creating map: " + timeForCreate + " sec");
        }
      }
    }
    for (int i = 0; i < threads; i++) {
      EdgeThread thread = new EdgeThread(ranges.get(2 * i), ranges.get(2 * i + 1));
      thread.start();
    }

    Thread.currentThread().join();
  }