/** * Separately subtracts the x and y positions of other from this Coord, producing a different Coord as their * "difference." * @param other another Coord * @return a Coord (usually cached and not a new instance) with {@code x = this.x - other.x; y = this.y - other.y} */ public Coord subtract(final Coord other) { return get(x - other.x, y - other.y); }
int x = ...; //x is some int int y = ...; //y is some int Coord coordOriginal = new Coord(x, y); //coordOriginal points to a new Coord object. Let's call it "A". Coord coordCopy = coordOriginal.copy(); //coordCopy points to to a new Coord object. Let's call it "B". //coordOriginal still points to Coord object "A".
height = land.height; MultiSpill spreader = new MultiSpill(new short[width][height], Spill.Measurement.MANHATTAN, rng); Coord.expandPoolTo(width, height); GreasedRegion map = land.copy(); entries.put(Coord.get(-1, -1), 0.0); for (int i = 0; i < factionCount; i++) { entries.put(map.nth(i), rng.between(0.5, 1.0));
do { myCoord = new Coord(); //********** myCoord.userId = cur.getInt(0); myCoord.timestamp = cur.getLong(1); myCoord.x = cur.getDouble(2); myCoord.y = cur.getDouble(3); myCoord.coordType = cur.getInt(4); myCoord.id = cur.getInt(5); myCoord.coordTypeDesc = cur.getString(6); markerArray.add(myCoord); Log.d("getCoordMarkers()", "X: " + myCoord.x + " Y: " + myCoord.y); myCoord = null; //for the garbage collector ******* } while( cur.moveToNext());
Coord center = minPosition.average(maxPosition); Coord dimensions = maxPosition.subtract(minPosition); float cellSize = Math.max(minimumDistance / rootTwo, 0.25f); int gridWidth = (int)(dimensions.x / cellSize) + 1; continue; added = true; Coord p = Coord.get(Math.min(xr, maxX - 1), Math.min(yr, maxY - 1)); Coord index = p.subtract(minPosition).divide(cellSize); Coord q = point.translateCapped(Math.round(newX), Math.round(newY), maxX, maxY); (rejectionDistance <= 0 || disk.radius(center.x, center.y, q.x, q.y) <= rejectionDistance)) Coord qIndex = q.subtract(minPosition).divide((int)Math.ceil(cellSize)); boolean tooClose = false;
Coord rc2 = Coord.get(width - 1 - rc.x, height - 1 - rc.y); double dist = lc.distance(rc2); if(dist < 0.001) continue; r1 = rc2; else if(dist < lowest2 && !lc.equals(l1) && !rc2.equals(r1)) && !lc.equals(l1) && !rc2.equals(r1) && !lc.equals(l2) && !rc2.equals(r2)) && !lc.equals(l1) && !rc2.equals(r1) && !lc.equals(l2) && !rc2.equals(r2) && !lc.equals(l3) && !rc2.equals(r3))
private Coord nearestPoint(Coord point) { if (distribution.isEmpty()) { Coord center = Coord.get(width / 2, height / 2); distribution.add(center); return center; } Coord nearestPoint = distribution.get(0); double nearestDistance = point.distance(nearestPoint); for (Coord candidatePoint : distribution) { double candidateDistance = point.distance(candidatePoint); if (candidateDistance > 0 && candidateDistance <= maxDistance) { return candidatePoint; } if (candidateDistance < nearestDistance) { nearestPoint = candidatePoint; nearestDistance = candidateDistance; } } return nearestPoint; }
/** * Copies all fields from copying and makes a new DungeonGenerator. * @param copying the DungeonGenerator to copy */ public SectionDungeonGenerator(SectionDungeonGenerator copying) { rng = new StatefulRNG(copying.rng.getState()); utility = new DungeonUtility(rng); rebuildSeed = rng.getState(); height = copying.height; width = copying.width; Coord.expandPoolTo(width, height); roomFX = new EnumMap<>(copying.roomFX); corridorFX = new EnumMap<>(copying.corridorFX); caveFX = new EnumMap<>(copying.caveFX); doorFX = copying.doorFX; lakeFX = copying.lakeFX; deepLakeGlyph = copying.deepLakeGlyph; shallowLakeGlyph = copying.shallowLakeGlyph; dungeon = copying.dungeon; }
Coord prev = centers[0]; for (int i = 0; i < 16; i++) { centers[i] = centers[i].interpolate(end, adjust(percent, i)); if(!prev.equals(centers[0])) if(!centers[i-1].equals(centers[i]))
restricted = true; Coord dimensions = maxPosition.subtract(minPosition); float cellSize = Math.max(minimumDistance / rootTwo, 1f); int gridWidth = (int) (dimensions.x / cellSize) + 1; if (p == null) return points; Coord index = p.subtract(minPosition).divide(cellSize); Coord q = point.translateCapped(Math.round(newX), Math.round(newY), width, height); int frustration = 0; while(restricted && blocked.contains(map[q.x][q.y]) && frustration < 8) newX = radius * NumberTools.sin(angle); newY = radius * NumberTools.cos(angle); q = point.translateCapped(Math.round(newX), Math.round(newY), width, height); frustration++; Coord qIndex = q.subtract(minPosition).divide((int) Math.ceil(cellSize)); boolean tooClose = false;
/** * Enlarges the pool of cached Coords to the given width and height, and doesn't change * a dimension if it would be reduced in size. * Cached Coord values will be reused by Coord.get instead of re-allocated each time. * The default pool allows Coords with x and y each between -3 and 255, inclusive, to * be cached, and is considered to have width and height of 256 to begin with. Giving a * width greater than 256 will allow Coords with x greater than 255 to be cached; * likewise for height. If width or height is smaller than the current cache width or * height, that dimension will not change, but the other still may if it is valid. You * cannot shrink the pool size. * @param width the new width for the pool of cached Coords; will be ignored if smaller than the current width * @param height the new height for the pool of cached Coords; will be ignored if smaller than the current height */ public static void expandPoolTo(final int width, final int height) { expandPool(Math.max(0, width + 3 - POOL.length), Math.max(0, height + 3 - POOL[0].length)); }
height = land.height; MultiSpill spreader = new MultiSpill(new short[width][height], Spill.Measurement.MANHATTAN, rng); Coord.expandPoolTo(width, height); GreasedRegion map = land.copy(); entries.put(Coord.get(-1, -1), 0.0); for (int i = 0; i < factionCount; i++) { entries.put(map.nth(i), rng.between(0.5, 1.0));
public static Coord get(final int x, final int y) { if(x >= -3 && y >= -3 && x < POOL.length - 3 && y < POOL[x + 3].length - 3) return POOL[x + 3][y + 3]; else return new Coord(x, y); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SpatialTriple<?, ?> that = (SpatialTriple<?, ?>) o; if (position != null ? !position.equals(that.position) : that.position != null) return false; if (id != null ? !id.equals(that.id) : that.id != null) return false; return element != null ? element.equals(that.element) : that.element == null; }
public void paint(Graphics g) { int incX = 5; // initial x increment for circle locations int incY = 5; // initial y increment for circle locations Coord temp = new Coord(0,0); Queue<Coord> q = new LinkedList<Coord>(); Circle c = new Circle(g,circleSize,incX,incY,TIME_DELAY); try { for(int i = 1; i <= TOTAL_NUM_CIRCLES; i++) { if(q.size() >= 50) { temp = q.remove(); c.eraseCircle(g,temp.getX(),temp.getY()); } temp = new Coord(getX(),getY()); //q.add(temp); q.add(c.drawCircle(g)); c.hitEdge(); } } catch(InterruptedException e){} }
/** * Creates a pip that falls within the required distance from the current * distribution. Does not add the pip to the distribution. * * @return the created pip */ public Coord createPoint() { Coord randomPoint = randomPoint(); Coord nearestPoint = nearestPoint(randomPoint); double pointDistance = randomPoint.distance(nearestPoint); // Too close, toss while (pointDistance < minDistance) { randomPoint = randomPoint(); nearestPoint = nearestPoint(randomPoint); pointDistance = randomPoint.distance(nearestPoint); } // Adjust if we're too far if (pointDistance > maxDistance) { // Calculate unit vector double unitX = (randomPoint.x - nearestPoint.x) / pointDistance; double unitY = (randomPoint.y - nearestPoint.y) / pointDistance; randomPoint = Coord.get( (int) (rng.between(minDistance, maxDistance + 1) * unitX + nearestPoint.x) , (int) (rng.between(minDistance, maxDistance + 1) * unitY + nearestPoint.y)); } return randomPoint; }