|
|
@ -7,13 +7,12 @@ import mightypork.utils.math.Calc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Coordinate class, object with three or two double coordinates.<br> |
|
|
|
* Coordinate in 3D space, or a vector of three {@link Double}s<br> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author MightyPork |
|
|
|
* @author MightyPork |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class Coord { |
|
|
|
public class Coord { |
|
|
|
|
|
|
|
|
|
|
|
/** RNG */ |
|
|
|
|
|
|
|
protected static Random rand = new Random(); |
|
|
|
protected static Random rand = new Random(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -29,33 +28,6 @@ public class Coord { |
|
|
|
return a.distTo(b); |
|
|
|
return a.distTo(b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate random coord (gaussian) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param max max distance from 0 |
|
|
|
|
|
|
|
* @return new coord |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Coord random(double max) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new Coord(Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2), Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2), |
|
|
|
|
|
|
|
Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate random coord (min-max) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param min min offset |
|
|
|
|
|
|
|
* @param max max offset |
|
|
|
|
|
|
|
* @return new coord |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Coord random(double min, double max) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new Coord((rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)), (rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)), |
|
|
|
|
|
|
|
(rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** X coordinate */ |
|
|
|
/** X coordinate */ |
|
|
|
public double x = 0; |
|
|
|
public double x = 0; |
|
|
|
|
|
|
|
|
|
|
@ -78,9 +50,7 @@ public class Coord { |
|
|
|
* @param copied copied coord |
|
|
|
* @param copied copied coord |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord(Coord copied) { |
|
|
|
public Coord(Coord copied) { |
|
|
|
this.x = copied.x; |
|
|
|
setTo(copied); |
|
|
|
this.y = copied.y; |
|
|
|
|
|
|
|
this.z = copied.z; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -108,76 +78,73 @@ public class Coord { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get a copy offset by vector |
|
|
|
* Add a vector, in a copy |
|
|
|
* |
|
|
|
* |
|
|
|
* @param vec offset |
|
|
|
* @param vec offset |
|
|
|
* @return the offset copy |
|
|
|
* @return changed copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord add(Coord vec) |
|
|
|
public Coord add(Coord vec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().add_ip(vec); |
|
|
|
return copy().add_ip(vec); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get a copy offset by 2D coordinate |
|
|
|
* Add a vector, in place |
|
|
|
* |
|
|
|
* |
|
|
|
* @param x x offset |
|
|
|
* @param vec offset |
|
|
|
* @param y y offset |
|
|
|
* @return this |
|
|
|
* @return the offset copy |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord add(Number x, Number y) |
|
|
|
public Coord add_ip(Coord vec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().add_ip(x, y); |
|
|
|
return add_ip(vec.x, vec.y, vec.z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get a copy offset by 3D coordinate |
|
|
|
* Add to each component, in a copy.<br> |
|
|
|
|
|
|
|
* Z is unchanged. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param x x offset |
|
|
|
* @param x x offset |
|
|
|
* @param y y offset |
|
|
|
* @param y y offset |
|
|
|
* @param z z offset |
|
|
|
* @return changed copy |
|
|
|
* @return the offset copy |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord add(Number x, Number y, Number z) |
|
|
|
public Coord add(Number x, Number y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().add_ip(x, y, z); |
|
|
|
return copy().add_ip(x, y); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Offset by vector in place |
|
|
|
* Add to each component, in place.<br> |
|
|
|
|
|
|
|
* Z is unchanged. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param vec offset |
|
|
|
* @param x x offset |
|
|
|
|
|
|
|
* @param y y offset |
|
|
|
* @return this |
|
|
|
* @return this |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord add_ip(Coord vec) |
|
|
|
public Coord add_ip(Number x, Number y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.x += vec.x; |
|
|
|
return add_ip(x, y, 0); |
|
|
|
this.y += vec.y; |
|
|
|
|
|
|
|
this.z += vec.z; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Offset by 2D coordinate in place |
|
|
|
* Add to each component, in a copy. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param x x offset |
|
|
|
* @param x x offset |
|
|
|
* @param y y offset |
|
|
|
* @param y y offset |
|
|
|
* @return this |
|
|
|
* @param z z offset |
|
|
|
|
|
|
|
* @return changed copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord add_ip(Number x, Number y) |
|
|
|
public Coord add(Number x, Number y, Number z) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.x += x.doubleValue(); |
|
|
|
return copy().add_ip(x, y, z); |
|
|
|
this.y += y.doubleValue(); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Offset by 3D coordinate in place |
|
|
|
* Add to each component, in place. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param x x offset |
|
|
|
* @param x x offset |
|
|
|
* @param y y offset |
|
|
|
* @param y y offset |
|
|
@ -194,9 +161,11 @@ public class Coord { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return copy of this vector |
|
|
|
* Make a copy |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return a copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord getCopy() |
|
|
|
public Coord copy() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Coord(x, y, z); |
|
|
|
return new Coord(x, y, z); |
|
|
|
} |
|
|
|
} |
|
|
@ -215,30 +184,14 @@ public class Coord { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get copy divided by number |
|
|
|
* Check if this rectangle in inside a rectangular zone |
|
|
|
* |
|
|
|
|
|
|
|
* @param d number to divide by |
|
|
|
|
|
|
|
* @return divided copy |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Coord div(double d) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return getCopy().div_ip(d); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Divide by number in place |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* @param d number to divide by |
|
|
|
* @param rect checked rect. |
|
|
|
* @return this |
|
|
|
* @return is inside |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord div_ip(double d) |
|
|
|
public boolean isInRect(Rect rect) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (d == 0) return this; |
|
|
|
return isInRect(rect.min, rect.max); |
|
|
|
x /= d; |
|
|
|
|
|
|
|
y /= d; |
|
|
|
|
|
|
|
z /= d; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -256,111 +209,150 @@ public class Coord { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Check if this rectangle in inside a rectangular zone |
|
|
|
* Get middle of line to other point |
|
|
|
* |
|
|
|
* |
|
|
|
* @param rect checked rect. |
|
|
|
* @param other other point |
|
|
|
* @return is inside |
|
|
|
* @return middle |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isInRect(Rect rect) |
|
|
|
public Coord midTo(Coord other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return isInRect(rect.min, rect.max); |
|
|
|
return add(vecTo(other).half_ip()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get middle of line to other point |
|
|
|
* Get copy divided by two |
|
|
|
* |
|
|
|
* |
|
|
|
* @param other other point |
|
|
|
* @return copy halved |
|
|
|
* @return middle |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord midTo(Coord other) |
|
|
|
public Coord half() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return add(vecTo(other).mul_ip(0.5)); |
|
|
|
return copy().half_ip(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Multiply by number |
|
|
|
* Divide in place by two |
|
|
|
* |
|
|
|
* |
|
|
|
* @param d number |
|
|
|
* @return this |
|
|
|
* @return multiplied copy |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord mul(double d) |
|
|
|
public Coord half_ip() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().mul_ip(d); |
|
|
|
mul_ip(0.5); |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Multiply coords by number |
|
|
|
* Multiply each component, in a copy. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param xd x multiplier |
|
|
|
* @param d multiplier |
|
|
|
* @param yd y multiplier |
|
|
|
* @return changed copy |
|
|
|
* @param zd z multiplier |
|
|
|
|
|
|
|
* @return multiplied copy |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord mul(double xd, double yd, double zd) |
|
|
|
public Coord mul(double d) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().mul_ip(xd, yd, zd); |
|
|
|
return copy().mul_ip(d); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Multiply by number in place |
|
|
|
* Multiply each component, in place. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param d multiplier |
|
|
|
* @param d multiplier |
|
|
|
* @return this |
|
|
|
* @return this |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord mul_ip(double d) |
|
|
|
public Coord mul_ip(double d) |
|
|
|
{ |
|
|
|
{ |
|
|
|
x *= d; |
|
|
|
return mul_ip(d, d, d); |
|
|
|
y *= d; |
|
|
|
|
|
|
|
z *= d; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Multiply coords by number in place |
|
|
|
* Multiply each component, in a copy. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param xd x multiplier |
|
|
|
* @param vec vector of multipliers |
|
|
|
* @param yd y multiplier |
|
|
|
* @return changed copy |
|
|
|
* @param zd z multiplier |
|
|
|
*/ |
|
|
|
|
|
|
|
public Coord mul(Coord vec) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return copy().mul_ip(vec); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Multiply each component, in a copy.<br> |
|
|
|
|
|
|
|
* Z is unchanged. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param x x multiplier |
|
|
|
|
|
|
|
* @param y y multiplier |
|
|
|
|
|
|
|
* @return changed copy |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Coord mul(double x, int y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return copy().mul_ip(x, y); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Multiply each component, in place.<br> |
|
|
|
|
|
|
|
* Z is unchanged. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param x x multiplier |
|
|
|
|
|
|
|
* @param y y multiplier |
|
|
|
* @return this |
|
|
|
* @return this |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord mul_ip(double xd, double yd, double zd) |
|
|
|
public Coord mul_ip(double x, double y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
x *= xd; |
|
|
|
return mul_ip(x, y, 1); |
|
|
|
y *= yd; |
|
|
|
|
|
|
|
z *= zd; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* offset randomly |
|
|
|
* Multiply each component, in a copy. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param max max +- offset |
|
|
|
* @param x x multiplier |
|
|
|
* @return offset coord |
|
|
|
* @param y y multiplier |
|
|
|
|
|
|
|
* @param z z multiplier |
|
|
|
|
|
|
|
* @return changed copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord random_offset(double max) |
|
|
|
public Coord mul(double x, double y, double z) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Coord v = random(1).norm_ip(0.00001 + rand.nextDouble() * max); |
|
|
|
return copy().mul_ip(x, y, z); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return getCopy().add_ip(v); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Multiply each component, in place. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param vec vector of multipliers |
|
|
|
|
|
|
|
* @return this |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Coord mul_ip(Coord vec) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return mul_ip(vec.x, vec.y, vec.z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* offset randomly |
|
|
|
* Multiply each component, in place. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param min min offset |
|
|
|
* @param x x multiplier |
|
|
|
* @param max max offset |
|
|
|
* @param y y multiplier |
|
|
|
* @return offset coord |
|
|
|
* @param z z multiplier |
|
|
|
|
|
|
|
* @return this |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord random_offset(double min, double max) |
|
|
|
public Coord mul_ip(double x, double y, double z) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this.x *= x; |
|
|
|
|
|
|
|
this.y *= y; |
|
|
|
|
|
|
|
this.z *= z; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Coord random_offset(double max) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().add_ip(random(min, max)); |
|
|
|
return copy().random_offset_ip(max); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -372,7 +364,20 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord random_offset_ip(double max) |
|
|
|
public Coord random_offset_ip(double max) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return add(random(max)); |
|
|
|
return add(random(1).norm_ip(rand.nextDouble() * max)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* offset randomly |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param min min offset |
|
|
|
|
|
|
|
* @param max max offset |
|
|
|
|
|
|
|
* @return offset coord |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Coord random_offset(double min, double max) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return copy().random_offset_ip(min, max); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -385,7 +390,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord random_offset_ip(double min, double max) |
|
|
|
public Coord random_offset_ip(double min, double max) |
|
|
|
{ |
|
|
|
{ |
|
|
|
add(random(min, max)); |
|
|
|
add_ip(random(min, max)); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -397,7 +402,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord round() |
|
|
|
public Coord round() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().round_ip(); |
|
|
|
return copy().round_ip(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -420,7 +425,7 @@ public class Coord { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param other other coord |
|
|
|
* @param other other coord |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setMax(Coord other) |
|
|
|
public void setToMax(Coord other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
x = Math.max(x, other.x); |
|
|
|
x = Math.max(x, other.x); |
|
|
|
y = Math.max(y, other.y); |
|
|
|
y = Math.max(y, other.y); |
|
|
@ -433,7 +438,7 @@ public class Coord { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param other other coord |
|
|
|
* @param other other coord |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setMin(Coord other) |
|
|
|
public void setToMin(Coord other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
x = Math.min(x, other.x); |
|
|
|
x = Math.min(x, other.x); |
|
|
|
y = Math.min(y, other.y); |
|
|
|
y = Math.min(y, other.y); |
|
|
@ -449,8 +454,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord setTo(Coord copied) |
|
|
|
public Coord setTo(Coord copied) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setTo(copied.x, copied.y, copied.z); |
|
|
|
return setTo(copied.x, copied.y, copied.z); |
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -463,8 +467,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord setTo(Number x, Number y) |
|
|
|
public Coord setTo(Number x, Number y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setTo(x, y, 0); |
|
|
|
return setTo(x, y, 0); |
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -493,7 +496,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord setX(Number x) |
|
|
|
public Coord setX(Number x) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().setX_ip(x); |
|
|
|
return copy().setX_ip(x); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -518,7 +521,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord setY(Number y) |
|
|
|
public Coord setY(Number y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().setY_ip(y); |
|
|
|
return copy().setY_ip(y); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -543,7 +546,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord setZ(Number z) |
|
|
|
public Coord setZ(Number z) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().setZ_ip(z); |
|
|
|
return copy().setZ_ip(z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -568,7 +571,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord sub(Coord vec) |
|
|
|
public Coord sub(Coord vec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().sub_ip(vec); |
|
|
|
return copy().sub_ip(vec); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -581,7 +584,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord sub(Number x, Number y) |
|
|
|
public Coord sub(Number x, Number y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().sub_ip(x, y); |
|
|
|
return copy().sub_ip(x, y); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -595,7 +598,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord sub(Number x, Number y, Number z) |
|
|
|
public Coord sub(Number x, Number y, Number z) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().sub_ip(x, y, z); |
|
|
|
return copy().sub_ip(x, y, z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -607,10 +610,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord sub_ip(Coord vec) |
|
|
|
public Coord sub_ip(Coord vec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.x -= vec.x; |
|
|
|
return sub_ip(vec.x, vec.y, vec.z); |
|
|
|
this.y -= vec.y; |
|
|
|
|
|
|
|
this.z -= vec.z; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -623,9 +623,7 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord sub_ip(Number x, Number y) |
|
|
|
public Coord sub_ip(Number x, Number y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.x -= x.doubleValue(); |
|
|
|
return sub_ip(x, y, 0); |
|
|
|
this.y -= y.doubleValue(); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -667,24 +665,6 @@ public class Coord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return X as double |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public double xd() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return x; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return X as float |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public float xf() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (float) x; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return X as int |
|
|
|
* @return X as int |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -703,24 +683,6 @@ public class Coord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return Y as double |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public double yd() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return Y as float |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public float yf() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (float) y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return Y as int |
|
|
|
* @return Y as int |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -739,24 +701,6 @@ public class Coord { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return Z as double |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public double zd() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return z; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return Z as float |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public float zf() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return (float) z; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return Z as int |
|
|
|
* @return Z as int |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -796,11 +740,11 @@ public class Coord { |
|
|
|
* Multiply by other vector, vector multiplication |
|
|
|
* Multiply by other vector, vector multiplication |
|
|
|
* |
|
|
|
* |
|
|
|
* @param vec other vector |
|
|
|
* @param vec other vector |
|
|
|
* @return copy multiplied |
|
|
|
* @return changed copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord cross(Coord vec) |
|
|
|
public Coord cross(Coord vec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().cross_ip(vec); |
|
|
|
return copy().cross_ip(vec); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -812,7 +756,13 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord cross_ip(Coord vec) |
|
|
|
public Coord cross_ip(Coord vec) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setTo(y * vec.z - z * vec.y, z * vec.x - x * vec.z, x * vec.y - y * vec.x); |
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
setTo( |
|
|
|
|
|
|
|
y * vec.z - z * vec.y, |
|
|
|
|
|
|
|
z * vec.x - x * vec.z, |
|
|
|
|
|
|
|
x * vec.y - y * vec.x |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -832,11 +782,11 @@ public class Coord { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Negate all coordinates (* -1) |
|
|
|
* Negate all coordinates (* -1) |
|
|
|
* |
|
|
|
* |
|
|
|
* @return negated coordinate |
|
|
|
* @return negated copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord neg() |
|
|
|
public Coord neg() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().neg_ip(); |
|
|
|
return copy().neg_ip(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -860,60 +810,45 @@ public class Coord { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord norm(double size) |
|
|
|
public Coord norm(double size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return getCopy().norm_ip(size); |
|
|
|
return copy().norm_ip(size); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Scale vector to given size, in place |
|
|
|
* Scale vector to given size, in place.<br> |
|
|
|
|
|
|
|
* Zero vector remains zero. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param size size we need |
|
|
|
* @param size size we need |
|
|
|
* @return scaled vector |
|
|
|
* @return scaled vector |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord norm_ip(double size) |
|
|
|
public Coord norm_ip(double size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (size() == 0) { |
|
|
|
if (isZero()) return this; |
|
|
|
z = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (size == 0) { |
|
|
|
|
|
|
|
setTo(0, 0, 0); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
double k = size / size(); |
|
|
|
double k = size / size(); |
|
|
|
mul_ip(k); |
|
|
|
return mul_ip(k); |
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get vector size |
|
|
|
* Get vector size |
|
|
|
* |
|
|
|
* |
|
|
|
* @return vector size in units |
|
|
|
* @return size in units |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public double size() |
|
|
|
public double size() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return Math.sqrt(x * x + y * y + z * z); |
|
|
|
if (isZero()) return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Math.sqrt(x * x + y * y + z * z); |
|
|
|
/** |
|
|
|
|
|
|
|
* Get copy divided by two |
|
|
|
|
|
|
|
* @return copy halved |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Coord half() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return getCopy().half_ip(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Divide in place by two |
|
|
|
* @return true if this coord is a zero coord |
|
|
|
* @return this |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Coord half_ip() |
|
|
|
public boolean isZero() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mul_ip(0.5); |
|
|
|
return x == 0 && y == 0 && z == 0; |
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -955,22 +890,60 @@ public class Coord { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return true if this coord is a zero coord |
|
|
|
* Generate a zero coordinate |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return coord of all zeros |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isZero() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return x == 0 && y == 0 && z == 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Coord zero() |
|
|
|
public static Coord zero() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Coord(0, 0, 0); |
|
|
|
return new Coord(0, 0, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate a unit coordinate |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return coord of all ones |
|
|
|
|
|
|
|
*/ |
|
|
|
public static Coord one() |
|
|
|
public static Coord one() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new Coord(1, 1, 1); |
|
|
|
return new Coord(1, 1, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate random coord (gaussian) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param max max distance from 0 |
|
|
|
|
|
|
|
* @return new coord |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Coord random(double max) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
return new Coord( |
|
|
|
|
|
|
|
Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2), |
|
|
|
|
|
|
|
Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2), |
|
|
|
|
|
|
|
Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate random coord (min-max) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param min min offset |
|
|
|
|
|
|
|
* @param max max offset |
|
|
|
|
|
|
|
* @return new coord |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static Coord random(double min, double max) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
return new Coord( |
|
|
|
|
|
|
|
(rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)), |
|
|
|
|
|
|
|
(rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)), |
|
|
|
|
|
|
|
(rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|