/** Generates array of XContour from local contours and modules. Used for TTF building. */ private XContour[] toContours() { XContour[] retval; ArrayList<XContour> list = new ArrayList<>(); XContour[] contours = m_glyph.getBody().getContour(); for (int i = 0; i < contours.length; i++) { EContour contour = (EContour) contours[i]; list.add(contour.toQuadratic()); } // for i XModule[] modules = m_glyph.getBody().getModule(); for (int i = 0; i < modules.length; i++) { EModuleInvoke module = (EModuleInvoke) modules[i]; // push and pop happens inside toContour list.add(module.toContour(new AffineTransform())); } // for i if (list.size() == 0) return null; retval = new XContour[list.size()]; for (int i = 0; i < list.size(); i++) { retval[i] = list.get(i); } // for i return retval; }
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>(); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // 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); } }
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>(); }
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)); }
/** * 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; }
// 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; }
/** * 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)); }
private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) { String s_List = ""; ArrayList aSubFolders = new ArrayList(); File file = new File(s_Dir); File[] filelist = file.listFiles(); if (filelist != null && filelist.length > 0) { for (int i = 0; i < filelist.length; i++) { if (filelist[i].isDirectory()) { aSubFolders.add(filelist[i].getName()); } } int n_Count = aSubFolders.size(); String s_LastFlag = ""; String s_Folder = ""; for (int i = 1; i <= n_Count; i++) { if (i < n_Count) { s_LastFlag = "0"; } else { s_LastFlag = "1"; } s_Folder = aSubFolders.get(i - 1).toString(); s_List = s_List + "arr" + s_Flag + "[" + String.valueOf(n_TreeIndex) + "]=new Array(\"" + s_Folder + "\"," + String.valueOf(n_Indent) + ", " + s_LastFlag + ");\n"; n_TreeIndex = n_TreeIndex + 1; ArrayList a_Temp = GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex); s_List = s_List + a_Temp.get(0).toString(); n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue(); } } ArrayList a_Return = new ArrayList(); a_Return.add(s_List); a_Return.add(String.valueOf(n_TreeIndex)); return a_Return; }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // 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); } } }
private ArrayList<Integer> findRanges() { int rowsPerRange = (int) Math.ceil((grid.size()) / (double) threads); ArrayList<Integer> ranges = new ArrayList<Integer>(); int startRow = 0, endRow = rowsPerRange; for (int i = 0; i < threads; i++) { ranges.add(startRow); ranges.add(endRow); startRow = endRow; ; endRow += rowsPerRange; } ranges.set(ranges.size() - 1, Math.min(grid.size(), ranges.get(ranges.size() - 1))); System.out.println(ranges); return ranges; }
// 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); }
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) }
public ArrayList<Polygon> getCSObstacles() { ArrayList<Polygon> csObstacles = new ArrayList<Polygon>(); for (Polygon obstacle : obstacles) { csObstacles.add(Polygon.minkowskiSumSimple(obstacle, reflectedRobot)); } return csObstacles; }
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);*/ }
public void manageStuff() { // organizes the the stuff in the stats list to useable stuff int c = 0; money = Integer.parseInt(stats.get(c)); c++; for (int i = 0; i < Integer.parseInt(stats.get(1)); i++) { powerUps.add(stats.get(i + 2)); c++; } c++; // System.out.println(Integer.parseInt(stats.get(1))+1); // System.out.println(c); for (int i = c + 1; i < c + Integer.parseInt(stats.get(c)) + 1; i++) { chars.add(stats.get(i)); } }
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)); }
public void sendToBack(Figure figure) { if (children.remove(figure)) { children.add(0, figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
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; }
public void bringToFront(Figure figure) { if (children.remove(figure)) { children.add(figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
public TTGlyph toSimpleGlyph() { // convert the file into array of contours XContour[] contours = toContours(); if ((contours == null) && (!isRequiredGlyph())) { return null; } // if TTGlyph retval = new TTGlyph(); retval.setSimple(true); retval.setAdvanceWidth(getAdvanceWidth()); if (contours == null) { return retval; } // if ArrayList<EContourPoint> points = new ArrayList<>(); for (int i = 0; i < contours.length; i++) { XContour contour = contours[i]; XContourPoint[] contourPoints = contour.getContourPoint(); for (int j = 0; j < contourPoints.length; j++) { points.add((EContourPoint) contourPoints[j]); } // for j retval.addEndPoint(points.size() - 1); } // for i for (EContourPoint point : points) { loadContourPoint(retval, point); } // for point boolean hasGridfit = false; // I need int i here. for (int i = 0; i < points.size(); i++) { EContourPoint point = points.get(i); if (!point.isRounded()) { continue; } // if hasGridfit = true; loadGridfit(retval, point, i); } // for i if (hasGridfit) { retval.addInstruction(TTGlyph.IUP1); retval.addInstruction(TTGlyph.IUP0); } // if // I need int i here. for (int i = 0; i < points.size(); i++) { EContourPoint point = points.get(i); if (point.getHint().length == 0) { continue; } // if loadHint(retval, point, i); } // for i return retval; }
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; }
// assumes that there will be no enclosed empty spaces in the result, and that the result will // be contiguous, and that everything is convex public static Polygon minkowskiSumSimple(Polygon poly1, Polygon poly2) { ArrayList<Mat> verts = new ArrayList<Mat>(); for (Mat v1 : poly1.vertices) { for (Mat v2 : poly2.vertices) { verts.add(Mat.add(v1, v2)); } } ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>(); for (Mat v : verts) { points.add(new Point2D.Double(v.data[0][0], v.data[1][0])); } PolygonObstacle po = GeomUtils.convexHull(points); verts = new ArrayList<Mat>(); for (Point2D.Double vert : po.getVertices()) { verts.add(Mat.encodePoint(vert.x, vert.y)); } return new Polygon(verts); }
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; }
/** 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; }
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; }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // 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>(); }
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; }
public void checkSpikeCollision() { // checks the spike collision for (Spikes s : spikeList) { if (s.getOnScreen()) { // if the spike is on the screen if (s.checkCollision(s.getImage(), player1)) { // if the user collides with the spike if (player1.getInvi() == false) { // if player is not invisiblity player1.setSpikeVelo(); // set the spike velocity loseCoins(); player1.setDown(true); } spRemove.add(s); } } else { spRemove.add(s); // remove the spike } } for (Spikes s : spRemove) { spikeList.remove(s); } spRemove = new ArrayList<Spikes>(); }
public void addTaxiwayPathDisplayModel( TaxiwayPathDisplayModel taxiwayPathDisplayModel, boolean parking) { if (!taxiwayPathDisplayModel.isDisplayed()) return; Integer start = new Integer(taxiwayPathDisplayModel.getStart()); Integer end = new Integer(taxiwayPathDisplayModel.getEnd()); if (!parking) if (taxiwayPathDisplayHM.containsKey(end)) { ((ArrayList) taxiwayPathDisplayHM.get(end)).add(taxiwayPathDisplayModel); } else { ArrayList arrayList = new ArrayList(); arrayList.add(taxiwayPathDisplayModel); taxiwayPathDisplayHM.put(end, arrayList); } if (taxiwayPathDisplayHM.containsKey(start)) { ((ArrayList) taxiwayPathDisplayHM.get(start)).add(taxiwayPathDisplayModel); } else { ArrayList arrayList = new ArrayList(); arrayList.add(taxiwayPathDisplayModel); taxiwayPathDisplayHM.put(start, arrayList); } taxiwayPathDisplayAL.add(taxiwayPathDisplayModel); }