/** @param override true if should kill even if invulerable, false if not */ public void kill(boolean override) { if (!override) { if (star || invulerable || piped) return; } deathPos.setLocation(pos); if (deathPos.y < 0) { deathPos.y = 0; } if (metal) { metal = false; startInvulnerable(); invulerableTime = 3000 / 15; Point2D.Double v = new Point2D.Double(Math.random() * 8 - 4, Math.random() * 4 + 7); TMetalCap cap = new TMetalCap(); cap.setPos(pos.x, pos.y); cap.kill(v); this.addSpawn(cap); return; } cape = false; dead = true; numBullets = 0; falling = false; acc = new Point2D.Double(); vel = new Point2D.Double(); deadTime = 25; }
public double getDistance(Vector<VivaeObject> objects) { GeneralPath thisPath = new GeneralPath(this.getTransformedShape()); PathIntersection pi = new PathIntersection(); Point2D.Double[] points; double dist = ray_length; double nd; for (VivaeObject vivaeObject : objects) { if (vivaeObject != this.owner) { GeneralPath gp = new GeneralPath(vivaeObject.getTransformedShape()); points = pi.getIntersections(thisPath, gp); for (Point2D.Double point : points) { nd = pi.euclideanDistance(point.getX(), point.getY(), owner.getX(), owner.getY()); if (nd < dist) { dist = nd; } // System.out.println(dist); } } } opacity = Math.max((float) (1d - (dist / ray_length)), opacity); opacityOfRay = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity); return 1d - (dist / ray_length); }
/** Transform a bounding box. This is only a rough estimate. */ public Rectangle2D transform(Rectangle2D r) { Point2D.Double in = new Point2D.Double(); Point2D.Double out = new Point2D.Double(); Rectangle2D bounds = null; if (isRectilinear()) { for (int ix = 0; ix < 2; ix++) { double x = r.getX() + r.getWidth() * ix; for (int iy = 0; iy < 2; iy++) { double y = r.getY() + r.getHeight() * iy; in.x = x; in.y = y; transform(in, out); if (ix == 0 && iy == 0) bounds = new Rectangle2D.Double(out.x, out.y, 0, 0); else bounds.add(out.x, out.y); } } } else { for (int ix = 0; ix < 7; ix++) { double x = r.getX() + r.getWidth() * ix / 6; for (int iy = 0; iy < 7; iy++) { double y = r.getY() + r.getHeight() * iy / 6; in.x = x; in.y = y; transform(in, out); if (ix == 0 && iy == 0) bounds = new Rectangle2D.Double(out.x, out.y, 0, 0); else bounds.add(out.x, out.y); } } } return bounds; }
/** Project a lat/long point, producing a result in metres */ public Point2D.Double transformRadians(Point2D.Double src, Point2D.Double dst) { double x = src.x; if (projectionLongitude != 0) x = MapMath.normalizeLongitude(x - projectionLongitude); project(x, src.y, dst); dst.x = totalScale * dst.x + totalFalseEasting; dst.y = totalScale * dst.y + totalFalseNorthing; return dst; }
public static Point2D.Double pointBetween(Point2D.Double p, Point2D.Double p2, double pos) { Point2D.Double n = new Point2D.Double( p.getX() * (1 - pos) + p2.getX() * (pos), p.getY() * (1 - pos) + p2.getY() * (pos)); return n; }
/** Inverse-project a point (in metres), producing a lat/long result in radians */ public Point2D.Double inverseTransformRadians(Point2D.Double src, Point2D.Double dst) { double x = (src.x - totalFalseEasting) / totalScale; double y = (src.y - totalFalseNorthing) / totalScale; projectInverse(x, y, dst); if (dst.x < -Math.PI) dst.x = -Math.PI; else if (dst.x > Math.PI) dst.x = Math.PI; if (projectionLongitude != 0) dst.x = MapMath.normalizeLongitude(dst.x + projectionLongitude); return dst; }
public boolean isInside(Point2D.Double point) { double x = point.getX(); double y = point.getY(); if ((x < center.getX() + radius && x > center.getX() - radius) && (y < center.getY() + radius && y > center.getY() - radius)) { return true; } return false; }
public Point2D.Double project(double lplam, double lpphi, Point2D.Double out) { double t = lpphi * lpphi; out.y = lpphi * (1. + t * C12); out.x = lplam * (1. - Cp * t); t = lplam * lplam; out.x *= (0.87 - Cl * t * t); return out; }
/** * The mouse location changed during a drag, while this MapTool was the active tool. * * @param point The location of the mouse in world coordinates. * @param evt The original event. */ @Override public void updateDrag(Point2D.Double point, MouseEvent evt) { // just in case we didn't get a mousePressed event if (dragStartPos == null) { dragStartPos = (Point2D.Double) point.clone(); } else { double dx = dragStartPos.getX() - point.getX(); double dy = dragStartPos.getY() - point.getY(); mapComponent.offsetVisibleArea(dx, dy); } }
/** Inverse-project a number of points (in metres), producing a lat/long result in radians */ public void inverseTransformRadians( double[] srcPoints, int srcOffset, double[] dstPoints, int dstOffset, int numPoints) { Point2D.Double in = new Point2D.Double(); Point2D.Double out = new Point2D.Double(); for (int i = 0; i < numPoints; i++) { in.x = srcPoints[srcOffset++]; in.y = srcPoints[srcOffset++]; inverseTransformRadians(in, out); dstPoints[dstOffset++] = out.x; dstPoints[dstOffset++] = out.y; } }
public static int closest(Point2D.Double[] BTS, Point2D.Double p) { double[] dist = new double[BTS.length]; int min = 0; for (int i = 0; i < BTS.length; i++) { dist[i] = distanceSq(BTS[i].getX(), BTS[i].getY(), p.getX(), p.getY()); if (dist[i] < dist[min]) min = i; } // System.out.println(dist[min] + " " + min); return min; }
/** * The mouse location changed during a drag, while this MapTool was the active one. * * @param point The location of the mouse in world coordinates. * @param evt The original event. */ public void updateDrag(Point2D.Double point, MouseEvent evt) { // just in case we didn't get a mousePressed-Event if (dragStartPos == null) { dragStartPos = (Point2D.Double) point.clone(); setMeasureCursor(); return; } // if this is the first time mouseDragged is called, capture the screen. if (dragCurrentPos == null) captureBackground(); dragCurrentPos = (Point2D.Double) point.clone(); mapComponent.repaint(); reportDistance(false); }
public void setFontSize(float size) { // FONT_SIZE.basicSet(this, new Double(size)); Point2D.Double p = new Point2D.Double(0, size); AffineTransform tx = TRANSFORM.get(this); if (tx != null) { try { tx.inverseTransform(p, p); Point2D.Double p0 = new Point2D.Double(0, 0); tx.inverseTransform(p0, p0); p.y -= p0.y; } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); } } FONT_SIZE.set(this, Math.abs(p.y)); }
public void vec2FieldMagnitude(Field field, AffineTransform ftoi) { AffineTransform itof = null; try { itof = ftoi.createInverse(); } catch (NoninvertibleTransformException niv) { TDebug.println(0, "NoninvertibleTransformException: " + niv); } Vector3d v = new Vector3d(); Point2D.Double p = new Point2D.Double(); for (int j = 0, k = 0; j < height; ++j) for (int i = 0; i < width; ++i, ++k) { p.x = i; p.y = j; itof.transform(p, p); v = field.get(p.x, p.y, 0.0); f[k] = (float) Math.sqrt(v.x * v.x + v.y * v.y); } }
public float getFontSize() { // return FONT_SIZE.get(this).floatValue(); Point2D.Double p = new Point2D.Double(0, FONT_SIZE.get(this)); AffineTransform tx = TRANSFORM.get(this); if (tx != null) { tx.transform(p, p); Point2D.Double p0 = new Point2D.Double(0, 0); tx.transform(p0, p0); p.y -= p0.y; /* try { tx.inverseTransform(p, p); } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); }*/ } return (float) Math.abs(p.y); }
public Point2D.Double project(double lplam, double lpphi, Point2D.Double out) { double rho; switch (type) { case MURD2: rho = rho_c + Math.tan(sig - lpphi); break; case PCONIC: rho = c2 * (c1 - Math.tan(lpphi)); break; default: rho = rho_c - lpphi; break; } out.x = rho * Math.sin(lplam *= n); out.y = rho_0 - rho * Math.cos(lplam); return out; }
public void onScannedRobot(ScannedRobotEvent e) { robotLocation = new Point2D.Double(getX(), getY()); enemyAbsoluteBearing = getHeadingRadians() + e.getBearingRadians(); enemyDistance = e.getDistance(); enemyLocation = vectorToLocation(enemyAbsoluteBearing, enemyDistance, robotLocation); // Change direction at random if (Math.random() < 0.015) { movementLateralAngle *= -1; } move(); execute(); // radar setTurnRadarRightRadians( Utils.normalRelativeAngle(enemyAbsoluteBearing - getRadarHeadingRadians()) * 2); /* * Circular Gun from wiki */ double absBearing = e.getBearingRadians() + getHeadingRadians(); // Finding the heading and heading change. double enemyHeading = e.getHeadingRadians(); double enemyHeadingChange = enemyHeading - oldEnemyHeading; oldEnemyHeading = enemyHeading; double deltaTime = 0; double predictedX = getX() + e.getDistance() * Math.sin(absBearing); double predictedY = getY() + e.getDistance() * Math.cos(absBearing); while ((++deltaTime) * BULLET_SPEED < Point2D.Double.distance(getX(), getY(), predictedX, predictedY)) { // Add the movement we think our enemy will make to our enemy's current X and Y predictedX += Math.sin(enemyHeading) * (e.getVelocity()); predictedY += Math.cos(enemyHeading) * (e.getVelocity()); // Find our enemy's heading changes. enemyHeading += enemyHeadingChange; // If our predicted coordinates are outside the walls, put them 18 // distance units away from the walls as we know // that that is the closest they can get to the wall (Bots are // non-rotating 36*36 squares). predictedX = Math.max(Math.min(predictedX, getBattleFieldWidth() - 18), 18); predictedY = Math.max(Math.min(predictedY, getBattleFieldHeight() - 18), 18); } // Find the bearing of our predicted coordinates from us. double aim = Utils.normalAbsoluteAngle(Math.atan2(predictedX - getX(), predictedY - getY())); // Aim and fire. setTurnGunRightRadians(Utils.normalRelativeAngle(aim - getGunHeadingRadians())); setFire(BULLET_POWER); setTurnRadarRightRadians(Utils.normalRelativeAngle(absBearing - getRadarHeadingRadians()) * 2); }
public void vec2FieldZero(Field field, AffineTransform ftoi) { AffineTransform itof = null; try { itof = ftoi.createInverse(); } catch (NoninvertibleTransformException niv) { TDebug.println(0, "NoninvertibleTransformException: " + niv); } Vector3d v = new Vector3d(); Point2D.Double p = new Point2D.Double(); for (int j = 0, k = 0; j < height; ++j) for (int i = 0; i < width; ++i, ++k) { p.x = i; p.y = j; itof.transform(p, p); v = field.get(p.x, p.y, 0.0); if ((v.x == 0.0) && (v.y == 0.0)) f[k] = 1.0f; else f[k] = 0.0f; } }
protected void drawCaps(Graphics2D g) { if (getNodeCount() > 1) { if (get(START_DECORATION) != null) { BezierPath cp = getCappedPath(); Point2D.Double p1 = path.get(0, 0); Point2D.Double p2 = cp.get(0, 0); if (p2.equals(p1)) { p2 = path.get(1, 0); } get(START_DECORATION).draw(g, this, p1, p2); } if (get(END_DECORATION) != null) { BezierPath cp = getCappedPath(); Point2D.Double p1 = path.get(path.size() - 1, 0); Point2D.Double p2 = cp.get(path.size() - 1, 0); if (p2.equals(p1)) { p2 = path.get(path.size() - 2, 0); } get(END_DECORATION).draw(g, this, p1, p2); } } }
/** * Method to get the coordinates of the enclosing rectangle after this transformation is applied * to the current picture * * @return the enclosing rectangle */ public Rectangle2D getTransformEnclosingRect(AffineTransform trans) { int width = getWidth(); int height = getHeight(); double maxX = width - 1; double maxY = height - 1; double minX, minY; Point2D.Double p1 = new Point2D.Double(0, 0); Point2D.Double p2 = new Point2D.Double(maxX, 0); Point2D.Double p3 = new Point2D.Double(maxX, maxY); Point2D.Double p4 = new Point2D.Double(0, maxY); Point2D.Double result = new Point2D.Double(0, 0); Rectangle2D.Double rect = null; // get the new points and min x and y and max x and y trans.deltaTransform(p1, result); minX = result.getX(); maxX = result.getX(); minY = result.getY(); maxY = result.getY(); trans.deltaTransform(p2, result); minX = Math.min(minX, result.getX()); maxX = Math.max(maxX, result.getX()); minY = Math.min(minY, result.getY()); maxY = Math.max(maxY, result.getY()); trans.deltaTransform(p3, result); minX = Math.min(minX, result.getX()); maxX = Math.max(maxX, result.getX()); minY = Math.min(minY, result.getY()); maxY = Math.max(maxY, result.getY()); trans.deltaTransform(p4, result); minX = Math.min(minX, result.getX()); maxX = Math.max(maxX, result.getX()); minY = Math.min(minY, result.getY()); maxY = Math.max(maxY, result.getY()); // create the bounding rectangle to return rect = new Rectangle2D.Double(minX, minY, maxX - minX + 1, maxY - minY + 1); return rect; }
public void update() { // update all the virtual bullets double battleFieldX = owner.getBattleFieldWidth(); double battleFieldY = owner.getBattleFieldHeight(); for (int i = 0; i < virtualBullets.size(); i++) { VirtualBullet bullet = virtualBullets.get(i); long dt = lastEnemyScanTime - bullet.lastUpdateTime; if (dt <= 0) continue; bullet.x += bullet.velX * dt; bullet.y += bullet.velY * dt; bullet.lastUpdateTime = lastEnemyScanTime; if (bullet.x > battleFieldX || bullet.y > battleFieldY || bullet.x < 0.0 || bullet.y < 0.0) { // missed virtualBullets.remove(i); i--; } else if (Point2D.Double.distance(bullet.x, bullet.y, enemyX, enemyY) < 30.0) { // log in array successes[bullet.targetter]++; // hit! virtualBullets.remove(i); i--; } } owner.setDebugProperty("VGVBCount", "" + virtualBullets.size()); owner.setDebugProperty( "VGHits", "circ=" + successes[0] + " naive=" + successes[1] + " linear=" + successes[2] + " rc=" + successes[3] + " rN=" + successes[4] + " rW=" + successes[5]); for (int i = 0; i < numVirtualGuns; i++) { targetters[i].update(); } }
public Point2D.Double projectInverse(double xyx, double xyy, Point2D.Double out) { double rho; rho = MapMath.distance(xyx, out.y = rho_0 - xyy); if (n < 0.) { rho = -rho; out.x = -xyx; out.y = -xyy; } out.x = Math.atan2(xyx, xyy) / n; switch (type) { case PCONIC: out.y = Math.atan(c1 - rho / c2) + sig; break; case MURD2: out.y = sig - Math.atan(rho - rho_c); break; default: out.y = rho_c - rho; } return out; }
@Override public Object getTransformRestoreData() { return origin.clone(); }
@Override public void restoreTransformTo(Object geometry) { Point2D.Double p = (Point2D.Double) geometry; origin.x = p.x; origin.y = p.y; }
private void scan(Graphics2D g, InputStream input) throws IOException { Set<String> unknownC = new HashSet<String>(); Pattern tab = Pattern.compile("[\t]"); LineIterator in = new LineIteratorImpl(LineReaderUtil.fromBufferedStream(input)); while (in.hasNext()) { String line = in.next(); String tokens[] = tab.split(line, 5); if (tokens.length < 4) { warning("Ignoring " + line); continue; } SAMSequenceRecord rec = this.context.getDictionary().getSequence(tokens[0]); if (rec == null) { warning("unknown chromosome " + tokens[0]); continue; } String country = tokens[3].toLowerCase().replaceAll("[ ]", ""); Shape shape = this.country2shape.get(country); if (shape == null) { if (!unknownC.contains(country)) { unknownC.add(country); warning("unknown country " + country); } continue; } seen.incr(country); int midpos = (Integer.parseInt(tokens[1]) + Integer.parseInt(tokens[2])) / 2; // country center Point2D.Double pt1 = new Point2D.Double(shape.getBounds2D().getCenterX(), shape.getBounds2D().getCenterY()); // circle point Point2D pt3 = this.context.convertPositionToPoint(tokens[0], midpos, getRadiusInt()); double angle = this.context.convertPositionToRadian(rec, midpos); double angle2 = angle -= Math.PI / 10.0; double distance13 = context .getCenter() .distance( new Point2D.Double( (pt1.getX() + pt3.getX()) / 2.0, (pt1.getY() + pt3.getY()) / 2.0)); // mid point Point2D pt2 = new Point2D.Double( context.getCenterX() + distance13 * Math.cos(angle2), context.getCenterX() + distance13 * Math.sin(angle2)); Composite old = g.getComposite(); Stroke olds = g.getStroke(); g.setStroke(new BasicStroke(0.8f)); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.02f)); g.setColor(Color.DARK_GRAY); GeneralPath p = new GeneralPath(); p.moveTo(pt1.getX(), pt1.getY()); p.quadTo(pt2.getX(), pt2.getY(), pt3.getX(), pt3.getY()); p.closePath(); g.draw(p); g.setComposite(old); g.setStroke(olds); } CloserUtil.close(in); }
/** * Write the given text string in the current font, centered at <location>. * * @param location the Point at the center of the text * @param s the text */ public static void text(Point2D.Double location, String s) { text(location.getX(), location.getY(), s); }
/** * Draw a filled rectangle of given half width and half height, centred at <location> and rotated * by d degrees. * * @param location the Point at the centre of the rectangle * @param halfWidth is half the width of the rectangle * @param halfHeight is half the height of the rectangle * @param degrees is the rotation of the rectangle with 3 o'clock being 0 degrees and 12 o'clock * being 270 degrees * @throws RuntimeException if halfWidth or halfHeight is negative */ public static void filledAngledRectangle( Point2D.Double location, double halfWidth, double halfHeight, double degrees) { filledAngledRectangle(location.getX(), location.getY(), halfWidth, halfHeight, degrees); }
/** * Draw a filled diamond of side length 2r, centred at <location>. * * @param location the Point at the centre of the square * @param r radius is half the length of any side of the diamond * @throws RuntimeException if r is negative */ public static void filledDiamond(Point2D.Double location, double r) { filledDiamond(location.getX(), location.getY(), r); }
/** * Draw a filled square of side length 2r, centred at <location>. * * @param location the Point at the centre of the square * @param r radius is half the length of any side of the square * @throws RuntimeException if r is negative */ public static void filledSquare(Point2D.Double location, double r) { filledSquare(location.getX(), location.getY(), r); }
/** * Draw a circle of radius r, centred at <location>. * * @param location the Point at the centre of the circle * @param r the radius of the circle * @throws RuntimeException if the radius of the circle is negative */ public static void circle(Point2D.Double location, double r) { circle(location.getX(), location.getY(), r); }