/* -------------------------------------------------------------*/ 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 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; }
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; }
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(); }
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 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) }
/* -------------------------------------------------------------*/ 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; } } }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // 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); } } }
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)); } }
/** 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 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; }
public Figure basicRemoveChild(int index) { Figure figure = children.get(index); children.remove(index); quadTree.remove(figure); figure.removeFigureListener(figureHandler); needsSorting = true; return figure; }
public void updateFile() { // writes highscore, coins and updates eveything else try { outFile = new PrintWriter(new BufferedWriter(new FileWriter("stats.txt"))); outFile.println("" + (money + coins)); outFile.println("" + powerUps.size()); for (int i = 0; i < powerUps.size(); i++) { outFile.println("" + powerUps.get(i)); // writes the highscore in the file } outFile.println("" + chars.size()); for (int i = 0; i < chars.size(); i++) { outFile.println("" + chars.get(i)); } if (Integer.parseInt(stats.get(stats.size() - 3)) < score) { outFile.println(score); } else { outFile.println(stats.get(stats.size() - 3)); } if (Integer.parseInt(stats.get(stats.size() - 2)) < score) { outFile.println(height); } else { outFile.println(stats.get(stats.size() - 2)); } outFile.println(Integer.parseInt(stats.get(stats.size() - 1)) + height); outFile.close(); } catch (IOException ex) { System.out.println("yooo stop noobing out"); } }
public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == evt.VK_RIGHT) { charcounter++; if (charcounter >= charnames.size()) { charcounter = 0; } showing = readGlyph((String) charnames.get(charcounter)); } else if (evt.getKeyCode() == evt.VK_LEFT) { charcounter--; if (charcounter < 0) { charcounter = charnames.size() - 1; } showing = readGlyph((String) charnames.get(charcounter)); } else { char c = evt.getKeyChar(); // System.out.println("Got char: "+name); showing = readGlyph(FontSupport.stdNames[FontSupport.standardEncoding[(int) c & 0xff]]); } repaint(); }
/** * 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; }
public void mergeApronEdgeLights( ApronEdgeLightModel model1, ApronEdgeLightModel model2, VertexModel vertexModel1, VertexModel vertexModel2) { boolean insert = model1.getVertexAL().get(0) == vertexModel1; ArrayList arrayList = model2.getVertexAL(); if (vertexModel2 == arrayList.get(0)) { for (int i = 1; i < arrayList.size(); i++) if (insert) model1.insertVertexModel((VertexModel) ((VertexModel) arrayList.get(i)).clone(), 0); else model1.addVertexModel((VertexModel) ((VertexModel) arrayList.get(i)).clone()); } else { for (int i = arrayList.size() - 2; i >= 0; i--) if (insert) model1.insertVertexModel((VertexModel) ((VertexModel) arrayList.get(i)).clone(), 0); else model1.addVertexModel((VertexModel) ((VertexModel) arrayList.get(i)).clone()); } removeApronEdgeLightModel(model2); }
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; }
private static <a> ArrayList<ArrayList<a>> transpose(ArrayList<ArrayList<a>> matrix) { ArrayList<ArrayList<a>> grid2 = new ArrayList<ArrayList<a>>(); if (matrix.isEmpty()) return grid2; for (int i = 0; i < matrix.get(0).size(); i++) { grid2.add(new ArrayList<a>(matrix.size())); } System.out.println(grid2); for (int i = 0; i < matrix.size(); i++) { ArrayList<a> row = matrix.get(i); for (int j = 0; j < row.size(); j++) { grid2.get(j).add(row.get(j)); // .set(i, row.get(j)); } } return grid2; }
public void draw(Graphics2D g) { g.setColor(fillColor); g.fill(gp); g.setColor(Color.black); g.draw(gp); for (int i = 0; i < points.size(); i++) { GlyphPoint p = points.get(i); g.setColor(Color.red); g.draw(p.gp); g.setColor(Color.blue); g.setFont(gfont); g.drawString(String.valueOf(i), p.x + 3, p.y + 3); } g.setColor(Color.black); // System.out.println("Advance: "+advance); g.draw(advp); if (name != null) { g.setFont(gfont); g.drawString(name, 0, -40); } }
public void drawPowerUpEffect(Graphics g) { if (player1.getPower().equals("Magnet")) { Image magpic = magnetList.get((int) count % 6); g.drawImage( magpic, player1.getX() - ((magpic.getWidth(null) - player1.getWidth()) / 2), player1.getY() - ((magpic.getHeight(null) - player1.getHeight()) / 2), magpic.getWidth(null), magpic.getHeight(null), this); count += 0.1; } else if (player1.getPower().equals("Ball")) { g.drawImage( ballPower, player1.getX() - ballPower.getWidth(null) / 2 + 17, player1.getY() + player1.getHeight() - 20, ballPower.getWidth(null), ballPower.getHeight(null), this); } else if (player1.getPower().equals("Sheild")) { g.drawImage( sheildPower, player1.getX() - ((sheildPower.getWidth(null) - player1.getWidth()) / 2), player1.getY() - ((sheildPower.getHeight(null) - player1.getHeight()) / 2), sheildPower.getWidth(null), sheildPower.getHeight(null), this); } else if (player1.getPower().equals("Umbrella")) { g.drawImage( umbrellaPower, player1.getX() - (umbrellaPower.getWidth(null) / 2) + 20, player1.getY() - umbrellaPower.getHeight(null) + 40, umbrellaPower.getWidth(null), umbrellaPower.getHeight(null), this); } else if (player1.getPower().equals("")) { } }
public static boolean polygonsIntersect(Polygon poly1, Polygon poly2) { // if any vertices from one polygon are inside the other polygon for (Mat vertex : poly1.vertices) { if (pointInPolygon(poly2, vertex)) { return true; } } for (Mat vertex : poly2.vertices) { if (pointInPolygon(poly1, vertex)) { return true; } } // if any edges hit eachother ArrayList<Mat> poly1EdgesA = poly1.vertices; ArrayList<Mat> poly1EdgesB = new ArrayList<Mat>(poly1EdgesA); poly1EdgesB.add(poly1EdgesB.get(0)); poly1EdgesB.remove(0); ArrayList<Mat> poly2EdgesA = poly2.vertices; ArrayList<Mat> poly2EdgesB = new ArrayList<Mat>(poly2EdgesA); poly2EdgesB.add(poly2EdgesB.get(0)); poly2EdgesB.remove(0); for (int e1 = 0; e1 < poly1EdgesA.size(); e1++) { for (int e2 = 0; e2 < poly2EdgesA.size(); e2++) { if (lineSegIntersect( poly1EdgesA.get(e1), poly1EdgesB.get(e1), poly2EdgesA.get(e2), poly2EdgesB.get(e2))) { return true; } } } // No? ok, cool. return false; }
/* * Take a collection of vertices and edges between them, * and return the minimum area polygon containing all of them. * * ArrayList<Mat> vertices = the list of vertices * * ArrayList<TreeSet<Integer>> edgesTo = To find the edges connecting to a point indexed i in vertices, * look in edgesTo.get(i). There you will find a list of indicies * into vertices, which are the endpoints of the edges. This data * structure is slow to write, but fast to read. */ public static Polygon perimeter(ArrayList<Mat> vertices, ArrayList<TreeSet<Integer>> edgesTo) { // Find a point guaranteed to be on the perimeter of the polygon, so we can start tracing it // out double dist; double maxDist = -1; int farPoint = -1; for (int i = 0; i < vertices.size(); i++) { dist = Math.pow( Math.pow(vertices.get(i).data[0][0], 2) + Math.pow(vertices.get(i).data[1][0], 2), 0.5); if (dist > maxDist) { maxDist = dist; farPoint = i; } } // Trace out the perimeter of the polygon int vertexStart = farPoint; int vertex = vertexStart; int prevVertex = -1; double prevAngle = Math.atan2(vertices.get(vertex).data[0][0], vertices.get(vertex).data[1][0]); double edgeAngle; double angleDiff; double minAngleDiff; int nextVertex = -1; double nextAngle = -1; Mat e0, e1; ArrayList<Mat> perimeter = new ArrayList<Mat>(); while (vertex != vertexStart || prevVertex == -1) { minAngleDiff = 3 * Math.PI; System.err.println("v:" + vertex); e0 = vertices.get(vertex); // System.err.println(edgesTo.get(vertex)); // Mat.print(System.err, e0); perimeter.add(e0); if (perimeter.size() > 100) { // F**K! try { throw new Exception(); } catch (Exception e) { e.printStackTrace(); System.err.println("hey there"); System.exit(1); } } for (int edgeVertex : edgesTo.get(vertex)) { e1 = vertices.get(edgeVertex); edgeAngle = Math.atan2(e1.data[0][0] - e0.data[0][0], e1.data[1][0] - e0.data[1][0]); angleDiff = edgeAngle - prevAngle; if (angleDiff < 0) { angleDiff += 2 * Math.PI; } if (angleDiff > 2 * Math.PI) { angleDiff -= 2 * Math.PI; } if (angleDiff < minAngleDiff && edgeVertex != prevVertex) { minAngleDiff = angleDiff; nextVertex = edgeVertex; nextAngle = edgeAngle; } } System.err.println("PERIMETER ITERATION:"); System.err.println("vertexStart = " + vertexStart); System.err.println("prevVertex = " + prevVertex); System.err.println("vertex = " + vertex); System.err.println("nextVertex = " + nextVertex); System.err.println(""); if (nextAngle > 0) { prevAngle = nextAngle - Math.PI; } else { prevAngle = nextAngle + Math.PI; } prevVertex = vertex; vertex = nextVertex; } return new Polygon(perimeter); }
// take the union of two polygons, assuming no enclosed empty spaces, and that the result will // be contiguous. public static Polygon combine(Polygon poly1, Polygon poly2) { ArrayList<Mat> vertices = new ArrayList<Mat>(); ArrayList<TreeSet<Integer>> edgesTo = new ArrayList<TreeSet<Integer>>(); int sizePoly1 = poly1.vertices.size(); int sizePoly2 = poly2.vertices.size(); int size = sizePoly1 + sizePoly2; boolean done; Publisher<GUISegmentMsg> segmentPub = node.newPublisher("/gui/Segment", "lab5_msgs/GUISegmentMsg"); Publisher<GUIEraseMsg> erasePub = node.newPublisher("/gui/Erase", "lab5_msgs/GUIEraseMsg"); // erasePub.publish(new GUIEraseMsg()); GUISegmentMsg segmentPlot = new GUISegmentMsg(); ColorMsg segmentPlotColor = new ColorMsg(); // add all the vertices in both polygons vertices.addAll(poly1.vertices); vertices.addAll(poly2.vertices); for (int i = 0; i < size; i++) { edgesTo.add(new TreeSet<Integer>()); } // add all the edges in both polygons for (int i = 0; i < sizePoly1; i++) { edgesTo.get(i).add(new Integer((i + 1) % sizePoly1)); edgesTo.get((i + 1) % sizePoly1).add(new Integer(i)); } for (int i = 0; i < sizePoly2; i++) { edgesTo.get(i + sizePoly1).add(new Integer(((i + 1) % sizePoly2) + sizePoly1)); edgesTo.get(((i + 1) % sizePoly2) + sizePoly1).add(new Integer(i + sizePoly1)); } System.err.println(vertices); System.err.println(edgesTo); segmentPlotColor.r = 255; segmentPlotColor.g = 0; segmentPlotColor.b = 0; segmentPlot.color = segmentPlotColor; for (int e0 = 0; e0 < size; e0++) { for (int e1 : edgesTo.get(e0)) { double[] xyStart = Mat.decodePoint(vertices.get(e0)); double[] xyEnd = Mat.decodePoint(vertices.get(e1)); segmentPlot.startX = xyStart[0]; segmentPlot.startY = xyStart[1]; segmentPlot.endX = xyEnd[0]; segmentPlot.endY = xyEnd[1]; segmentPub.publish(segmentPlot); } } // find and merge colocated points done = false; while (!done) { done = true; checkFMCP: { for (int p0 = 0; p0 < size; p0++) { for (int p1 = 0; p1 < size; p1++) { if (p0 != p1) { if (ptsEqual(vertices.get(p0), vertices.get(p1))) { // System.err.println("found two colocated: " + p0 + " " + p1); // System.err.println(edgesTo); edgesTo.get(p0).addAll(edgesTo.get(p1)); edgesTo.get(p0).remove(p0); vertices.remove(p1); edgesTo.remove(p1); size--; for (int e0 = 0; e0 < size; e0++) { if (edgesTo.get(e0).contains(new Integer(p1))) { edgesTo.get(e0).remove(new Integer(p1)); edgesTo.get(e0).add(new Integer(p0)); } // System.err.println("e0: " + e0); // System.err.println(edgesTo.get(e0)); TreeSet<Integer> head = new TreeSet(edgesTo.get(e0).headSet(new Integer(p1))); // System.err.println(head); for (Integer e1 : edgesTo.get(e0).tailSet(new Integer(p1))) { head.add(e1 - 1); } head.remove(e0); // System.err.println(head); edgesTo.set(e0, head); // System.err.println(edgesTo.get(e0)); } done = false; // System.err.println(edgesTo); break checkFMCP; } } } } } } System.err.println("merged points"); System.err.println(edgesTo); /*segmentPlotColor.r = 0; segmentPlotColor.g = 0; segmentPlotColor.b = 255; segmentPlot.color = segmentPlotColor; for (int e0 = 0; e0 < size; e0++){ for (int e1 : edgesTo.get(e0)) { double[] xyStart = Mat.decodePoint(vertices.get(e0)); double[] xyEnd = Mat.decodePoint(vertices.get(e1)); segmentPlot.startX = xyStart[0]; segmentPlot.startY = xyStart[1]; segmentPlot.endX = xyEnd[0]; segmentPlot.endY = xyEnd[1]; segmentPub.publish(segmentPlot); } }*/ // find and split edges bisected by points done = false; while (!done) { done = true; checkFSEBP: { for (int e0 = 0; e0 < size; e0++) { for (int e1 : edgesTo.get(e0)) { for (int p = 0; p < size; p++) { if (e0 != p && e1 != p) { if (ptSegIntersect(vertices.get(e0), vertices.get(e1), vertices.get(p))) { edgesTo.get(p).add(new Integer(e0)); edgesTo.get(p).add(new Integer(e1)); edgesTo.get(e0).remove(new Integer(e1)); edgesTo.get(e0).add(new Integer(p)); edgesTo.get(e1).remove(new Integer(e0)); edgesTo.get(e1).add(new Integer(p)); done = false; break checkFSEBP; } } } } } } } System.err.println("split edges on points"); System.err.println(edgesTo); System.err.println("GOT HERE!"); int iters = 0; done = false; while (!done) { // find and split intersecting edges System.err.println("size: " + size); done = true; checkFSIE: { for (int e00 = 0; e00 < size; e00++) { for (int e10 = 0; e10 < size; e10++) { if (e00 != e10) { for (int e01 : new TreeSet<Integer>(edgesTo.get(e00))) { if (e01 != e10 && e01 != e00) { for (int e11 : new TreeSet<Integer>(edgesTo.get(e10))) { if (e11 != e00 && e11 != e01 && e11 != e10) { if (lineSegIntersect( vertices.get(e00), vertices.get(e01), vertices.get(e10), vertices.get(e11))) { // System.err.println("intersectors for iter " + iters); // System.err.println(e00); // System.err.println(edgesTo.get(e00)); // Mat.print(System.err, vertices.get(e00)); // System.err.println(e01); // System.err.println(edgesTo.get(e01)); // Mat.print(System.err, vertices.get(e01)); // System.err.println(e10); // System.err.println(edgesTo.get(e10)); // Mat.print(System.err, vertices.get(e10)); // System.err.println(e11); // System.err.println(edgesTo.get(e11)); // Mat.print(System.err, vertices.get(e11)); if (iters > 10000) { // F**K! try { throw new Exception(); } catch (Exception e) { e.printStackTrace(); System.err.println("hey there"); System.exit(1); } } iters++; Mat newVertex = lineSegIntersection( vertices.get(e00), vertices.get(e01), vertices.get(e10), vertices.get(e11)); if (ptsEqual(newVertex, vertices.get(e00))) { edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(e00)); edgesTo.get(e00).add(new Integer(e10)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(e00)); edgesTo.get(e00).add(new Integer(e11)); } else if (ptsEqual(newVertex, vertices.get(e01))) { edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(e01)); edgesTo.get(e01).add(new Integer(e10)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(e01)); edgesTo.get(e01).add(new Integer(e11)); } else if (ptsEqual(newVertex, vertices.get(e10))) { edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(e10)); edgesTo.get(e10).add(new Integer(e00)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(e10)); edgesTo.get(e10).add(new Integer(e01)); } else if (ptsEqual(newVertex, vertices.get(e11))) { edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(e11)); edgesTo.get(e11).add(new Integer(e00)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(e11)); edgesTo.get(e11).add(new Integer(e01)); } else { vertices.add(newVertex); edgesTo.add(new TreeSet<Integer>()); edgesTo.get(size).add(new Integer(e00)); edgesTo.get(size).add(new Integer(e01)); edgesTo.get(size).add(new Integer(e10)); edgesTo.get(size).add(new Integer(e11)); edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(size)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(size)); edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(size)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(size)); size++; } done = false; break checkFSIE; } } } } } } } } } System.err.println("split edges on edges"); System.err.println(edgesTo); } System.err.println("GOT HERE TOO!"); System.err.println("begin vertices"); for (Mat vertex : vertices) { Mat.print(System.err, vertex); } System.err.println("end vertices"); System.err.println(edgesTo); return perimeter(vertices, edgesTo); }
private void InitUpload() throws ServletException, IOException { String sConfig = myUtil.ReadFile(myUtil.getConfigFileRealPath(m_request.getServletPath())); ArrayList aStyle = myUtil.getConfigArray("Style", sConfig); String sAllowExt, sUploadDir, sBaseUrl, sContentPath; String sCurrDir, sDir; int nAllowBrowse; String sPathShareImage, sPathShareFlash, sPathShareMedia, sPathShareOther; // param String sType = myUtil.dealNull(m_request.getParameter("type")).toUpperCase(); String sStyleName = myUtil.dealNull(m_request.getParameter("style")); String sCusDir = myUtil.dealNull(m_request.getParameter("cusdir")); String sAction = myUtil.dealNull(m_request.getParameter("action")).toUpperCase(); String s_SKey = myUtil.dealNull(m_request.getParameter("skey")); // InitUpload String[] aStyleConfig = new String[1]; boolean bValidStyle = false; for (int i = 0; i < aStyle.size(); i++) { aStyleConfig = myUtil.split(aStyle.get(i).toString(), "|||"); if (sStyleName.toLowerCase().equals(aStyleConfig[0].toLowerCase())) { bValidStyle = true; break; } } if (!bValidStyle) { out.print(getOutScript("alert('Invalid Style!')")); out.close(); return; } if (!aStyleConfig[61].equals("1")) { sCusDir = ""; } String ss_FileSize = "", ss_FileBrowse = "", ss_SpaceSize = "", ss_SpacePath = "", ss_PathMode = "", ss_PathUpload = "", ss_PathCusDir = "", ss_PathCode = "", ss_PathView = ""; if ((aStyleConfig[61].equals("2")) && (!s_SKey.equals(""))) { ss_FileSize = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileSize")); ss_FileBrowse = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileBrowse")); ss_SpaceSize = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpaceSize")); ss_SpacePath = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpacePath")); ss_PathMode = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathMode")); ss_PathUpload = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathUpload")); ss_PathCusDir = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCusDir")); ss_PathCode = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCode")); ss_PathView = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathView")); if (myUtil.IsInt(ss_FileSize)) { aStyleConfig[11] = ss_FileSize; aStyleConfig[12] = ss_FileSize; aStyleConfig[13] = ss_FileSize; aStyleConfig[14] = ss_FileSize; aStyleConfig[15] = ss_FileSize; aStyleConfig[45] = ss_FileSize; } else { ss_FileSize = ""; } if (ss_FileBrowse.equals("0") || ss_FileBrowse.equals("1")) { aStyleConfig[43] = ss_FileBrowse; } else { ss_FileBrowse = ""; } if (myUtil.IsInt(ss_SpaceSize)) { aStyleConfig[78] = ss_SpaceSize; } else { ss_SpaceSize = ""; } if (!ss_PathMode.equals("")) { aStyleConfig[19] = ss_PathMode; } if (!ss_PathUpload.equals("")) { aStyleConfig[3] = ss_PathUpload; } if (!ss_PathCode.equals("")) { aStyleConfig[23] = ss_PathCode; } if (!ss_PathView.equals("")) { aStyleConfig[22] = ss_PathView; } sCusDir = ss_PathCusDir; } sBaseUrl = aStyleConfig[19]; nAllowBrowse = Integer.valueOf(aStyleConfig[43]).intValue(); if (nAllowBrowse != 1) { out.print(getOutScript("alert('Do not allow browse!')")); out.close(); return; } if (!sCusDir.equals("")) { sCusDir = myUtil.replace(sCusDir, "\\", "/"); if ((sCusDir.startsWith("/")) || (sCusDir.startsWith(".")) || (sCusDir.endsWith(".")) || (sCusDir.indexOf("./") >= 0) || (sCusDir.indexOf("/.") >= 0) || (sCusDir.indexOf("//") >= 0) || (sCusDir.indexOf("..") >= 0)) { sCusDir = ""; } else { if (!sCusDir.endsWith("/")) { sCusDir = sCusDir + "/"; } } } sUploadDir = aStyleConfig[3]; if (!sBaseUrl.equals("3")) { sUploadDir = myUtil.getRealPathFromRelative(m_request.getServletPath(), sUploadDir); } sUploadDir = GetSlashPath(sUploadDir); sUploadDir = sUploadDir + myUtil.replace(myUtil.replace(sCusDir, "/", sFileSeparator), "\\", sFileSeparator); if (sType.equals("FILE")) { sAllowExt = aStyleConfig[6]; } else if (sType.equals("MEDIA")) { sAllowExt = aStyleConfig[9]; } else if (sType.equals("FLASH")) { sAllowExt = aStyleConfig[7]; } else { sAllowExt = aStyleConfig[8]; } sPathShareImage = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/image/")); sPathShareFlash = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/flash/")); sPathShareMedia = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/media/")); sPathShareOther = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/other/")); String s_Out = ""; if (sAction.equals("FILE")) { String s_ReturnFlag = myUtil.dealNull(m_request.getParameter("returnflag")); String s_FolderType = myUtil.dealNull(m_request.getParameter("foldertype")); String s_Dir = myUtil.dealNull(m_request.getParameter("dir")); s_Dir = java.net.URLDecoder.decode(s_Dir, "UTF-" + "8"); String s_CurrDir = ""; if (s_FolderType.equals("upload")) { s_CurrDir = sUploadDir; } else if (s_FolderType.equals("shareimage")) { sAllowExt = ""; s_CurrDir = sPathShareImage; } else if (s_FolderType.equals("shareflash")) { sAllowExt = ""; s_CurrDir = sPathShareFlash; } else if (s_FolderType.equals("sharemedia")) { sAllowExt = ""; s_CurrDir = sPathShareMedia; } else { s_FolderType = "shareother"; sAllowExt = ""; s_CurrDir = sPathShareOther; } s_Dir = myUtil.replace(s_Dir, "\\", "/"); if ((s_Dir.startsWith("/")) || (s_Dir.startsWith(".")) || (s_Dir.endsWith(".")) || (s_Dir.indexOf("./") >= 0) || (s_Dir.indexOf("/.") >= 0) || (s_Dir.indexOf("//") >= 0) || (s_Dir.indexOf("..") >= 0)) { s_Dir = ""; } String s_Dir2 = myUtil.replace(s_Dir, "/", sFileSeparator); s_Dir2 = myUtil.replace(s_Dir2, "\\", sFileSeparator); if (!s_Dir.equals("")) { if (CheckValidDir(s_CurrDir + s_Dir2)) { s_CurrDir += s_Dir2; } else { s_Dir = ""; } } if (CheckValidDir(s_CurrDir)) { File file = new File(s_CurrDir); File[] filelist = file.listFiles(); if (filelist != null && filelist.length > 0) { int n = -1; for (int i = 0; i < filelist.length; i++) { if (filelist[i].isFile()) { String s_FileName = filelist[i].getName(); String s_FileExt = s_FileName.substring(s_FileName.lastIndexOf(".") + 1); s_FileExt = s_FileExt.toLowerCase(); if (CheckValidExt(sAllowExt, s_FileExt)) { n++; s_Out = s_Out + "arr[" + String.valueOf(n) + "]=new Array(\"" + s_FileName + "\", \"" + String.valueOf(convertFileSize(filelist[i].length())) + "\",\"" + formatDate(new Date(filelist[i].lastModified())) + "\");\n"; } } } } } s_Out = "var arr = new Array();\n" + s_Out + "parent.setFileList('" + s_ReturnFlag + "', '" + s_FolderType + "', '" + s_Dir + "', arr);"; out.print(getOutScript(s_Out)); } else { s_Out = "var arrUpload = new Array();\n"; s_Out += "var arrShareImage = new Array();\n"; s_Out += "var arrShareFlash = new Array();\n"; s_Out += "var arrShareMedia = new Array();\n"; s_Out += "var arrShareOther = new Array();\n"; s_Out += GetFolderTree(sUploadDir, "Upload", 1, 0).get(0).toString(); sAllowExt = ""; if (sType.equals("FILE")) { s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareOther, "ShareOther", 1, 0).get(0).toString(); } else if (sType.equals("MEDIA")) { s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString(); } else if (sType.equals("FLASH")) { s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString(); } else { s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString(); } s_Out += "parent.setFolderList(arrUpload, arrShareImage, arrShareFlash, arrShareMedia, arrShareOther);"; out.print(getOutScript(s_Out)); } }
public void renderNotes(GLAutoDrawable gLDrawable, double dt) { // RENDER NOTES//////////////////////// /* OLD CODE TO CHECK/UPDATE TIME long songTime = song.getTime(); long milliTime = System.currentTimeMillis(); if(firstTime) { time = songTime; firstTime = false; } else { if(songTime == oldSongTime) { updateTime += milliTime-oldTime; System.out.println("update time: "+updateTime); } else { if (songTime == oldSongTime + updateTime) System.out.println("WINWINWINWIWNWINWIWNWIN"); else System.out.println("Difference: "+(songTime-oldSongTime - updateTime)); updateTime = 0; System.out.println("New Time: "+time); } time = songTime + updateTime; }//end else oldSongTime = songTime; oldTime = milliTime;*/ time = song.getTime(); for (int i = lowestNoteToProcess; i < lines.size(); i++) { Line line = lines.get(i); if (line.getTime() - noteErrorDuration > time) break; if (line.getState() == 0) // not pressed { if (time > line.getTime() + noteErrorDuration) // missed line { // System.out.println("missed line"); line.setState(3); score -= 1; lowestNoteToProcess++; } } // code below takes care of this } // end for // find closest line in bounds to be pressed // if a line exists // see if correct key combo was pressed // do the thing // else // play a bad line sound // if it doesnt exist // play a bad line sound Line closest = null; long closestDistance = 1000000; for (int i = lowestNoteToProcess; i < lines.size(); i++) { Line n = lines.get(i); if (n.getTime() - noteErrorDuration > time) break; if (n.getState() == 1) // user is holding down this line, so it is the only one that can be processed { closest = n; break; } if (Math.abs(time - n.getTime()) <= closestDistance && time >= n.getTime() - noteErrorDuration && time <= n.getTime() + noteErrorDuration) { closest = n; closestDistance = (long) Math.abs(time - n.getTime()); } } if (closest != null) { if (closest.getState() == 0) // not pressed { boolean seq = true; for (int x = 0; x < 5; x++) if (key[x] != closest.getNotes()[x]) { seq = false; break; } if (seq) { // System.out.println("pressed button"); closest.setState(2); // pressed button lowestNoteToProcess++; } score += 1; } else { // play bad line sound } } /*else if(closest.getState() == 1) { //holding and strummed, cant do that closest.getState() = 2; System.out.println("you interrupted the holding"); lowestNoteToProcess++; //play bad line sound }*/ // } else // (if closest == null) { // play bad line sound } // Part 2 for (int i = lowestNoteToRender; i < lines.size(); i++) { Line line = lines.get(i); float posz = (line.getTime() + -targetPos / length * fretDuration - time) / fretDuration * length; // head if (posz > length) break; // not rendered yet float posz2 = (line.getTime() + -targetPos / length * fretDuration - time) / fretDuration * length; // tail if (posz2 <= 1) // will never be rendered again { lowestNoteToRender++; continue; } if (posz <= length) for (int x = 0; x < 5; x++) { if (!line.getNotes()[x]) continue; if (line.getState() == 2) continue; // pressed if (line.getState() == 3) // missed noteToDraw = new Note(127f, 127f, 127f); else noteToDraw = new Note(colors[x][0], colors[x][1], colors[x][2]); if (x < 4) noteToDraw.draw(gLDrawable, -3 + (1.5f * x), -4, -posz); else noteToDraw.drawBar(gLDrawable, -posz, false); } } // }//end if songIsPlaying }