/** * 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); }
/** * @param i * @return {@code (x*i,y*i)}. */ public Coord scale(final int i) { return Coord.get(x * i, y * i); }
/** * Separately divides the x and y positions of this Coord by operand, producing a different Coord as their * "quotient." If operand is 0, this will throw an exception, as dividing by 0 is expected to do. * @param operand a value to divide each of x and y by * @return a Coord (usually cached and not a new instance) with {@code x = this.x / operand; y = this.y / operand} */ public Coord divide(final int operand) { return get(x / operand, y / operand); }
/** * Separately divides the x and y positions of this Coord by operand, flooring to a lower int for each of x and * y and producing a different Coord as their "quotient." If operand is 0.0, expect strange results (infinity and * NaN are both possibilities). * @param operand a value to divide each of x and y by * @return a Coord (usually cached and not a new instance) with {@code x = this.x / operand; y = this.y / * operand}, with both x and y rounded accordingly */ public Coord divide(final double operand) { return get((int)(x / operand), (int)(y / operand)); }
/** * @param d * A non-{@code null} direction. * @return The coordinate obtained by applying {@code d} on {@code this}. */ public Coord translate(final Direction d) { return Coord.get(x + d.deltaX, y + d.deltaY); }
/** * Separately multiplies the x and y positions of other from this Coord, producing a different Coord as their * "product." * @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 multiply(final Coord other) { return get(x * other.x, y * other.y); } /**
/** * Separately multiplies the x and y positions of this Coord by operand, producing a different Coord as their * "product." * @param operand a value to multiply each of x and y by * @return a Coord (usually cached and not a new instance) with {@code x = this.x * operand; y = this.y * operand} */ public Coord multiply(final int operand) { return get(x * operand, y * operand); }
/** * Separately divides the x and y positions of this Coord by other, producing a different Coord as their * "quotient." If other has 0 for x or y, this will throw an exception, as dividing by 0 is expected to do. * @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 divide(final Coord other) { return get(x / other.x, y / other.y); } /**
public SpatialTriple() { position = Coord.get(0,0); id = null; element = null; } public SpatialTriple(Coord position, I id, E element) {
protected OrderedSet<Coord> removeAdjacent(OrderedSet<Coord> coll, Coord pt) { for(Coord temp : new Coord[]{Coord.get(pt.x + 1, pt.y), Coord.get(pt.x - 1, pt.y), Coord.get(pt.x, pt.y + 1), Coord.get(pt.x, pt.y - 1)}) { if(coll.contains(temp) && !(temp.x == pt.x && temp.y == pt.y)) coll.remove(temp); } return coll; } protected OrderedSet<Coord> removeAdjacent(OrderedSet<Coord> coll, Coord pt1, Coord pt2)
/** * Separately multiplies the x and y positions of this Coord by operand, rounding to the nearest int for each of x * and y and producing a different Coord as their "product." * @param operand a value to multiply each of x and y by * @return a Coord (usually cached and not a new instance) with {@code x = this.x * operand; y = this.y * * operand}, with both x and y rounded accordingly */ public Coord multiply(final double operand) { return get((int)Math.round(x * operand), (int)Math.round(y * operand)); }
public Coord interpolate(Coord end, float amountTraveled) { return Coord.get(x + Math.round((end.x - x) * amountTraveled), y + Math.round((end.y - y) * amountTraveled)); } }
/** * Separately divides the x and y positions of this Coord by operand, rounding to the nearest int for each of x and * y and producing a different Coord as their "quotient." If operand is 0.0, expect strange results (infinity and * NaN are both possibilities). * @param operand a value to divide each of x and y by * @return a Coord (usually cached and not a new instance) with {@code x = this.x / operand; y = this.y / * operand}, with both x and y rounded accordingly */ public Coord divideRounding(final double operand) { return get((int)Math.round(x / operand), (int)Math.round(y / operand)); }
/** * Adds a Radiance as a light source at the given position. Overwrites any existing Radiance at the same position. * @param x the x-position to add the Radiance at * @param y the y-position to add the Radiance at * @param light a Radiance object that can have a changing radius, color, and various other effects on lighting * @return this for chaining */ public LightingHandler addLight(int x, int y, Radiance light) { return addLight(Coord.get(x, y), light); } /**
protected void setFresh(final Coord pt, double counter) { if(!initialized) return; gradientMap[pt.x][pt.y] = counter; fresh.put(Coord.get(pt.x, pt.y), counter); }
/** * Removes a Radiance as a light source from the given position, if any is present. * @param x the x-position to remove the Radiance from * @param y the y-position to remove the Radiance from * @return this for chaining */ public LightingHandler removeLight(int x, int y) { return removeLight(Coord.get(x, y)); } /**
private void putCircle(int radius, float multiplier) { putModule(CoordPacker.circle(Coord.get(Math.round(radius * multiplier + 1), Math.round(radius * multiplier + 1)), Math.round(radius * multiplier), Math.round((radius + 1) * 2 * multiplier + 1), Math.round((radius + 1) * 2 * multiplier + 1))); }
protected void setFresh(int idx, int x, int y) { if(!initialized) return; fresh.get(idx).add(Coord.get(x, y)); anyFreshMap.insert(x, y); }
@Override public OrderedMap<Coord, Double> findArea() { OrderedMap<Coord, Double> ret = new OrderedMap<>(1); ret.put(Coord.get(center.x, center.y), 1.0); return ret; }