X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fcompress%2FXYpoint.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fcompress%2FXYpoint.java;h=b3d93d1e1b2cc3e55028db777ac2a872014e60f8;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/compress/XYpoint.java b/src/tim/prune/function/compress/XYpoint.java new file mode 100644 index 0000000..b3d93d1 --- /dev/null +++ b/src/tim/prune/function/compress/XYpoint.java @@ -0,0 +1,49 @@ +package tim.prune.function.compress; + +/** + * Basic class to hold x and y coordinates + * for a point or a vector + */ +public class XYpoint +{ + // x and y coordinates + public double x = 0.0, y = 0.0; + + /** + * Empty constructor + */ + public XYpoint() { + this(0.0, 0.0); + } + + /** + * Constructor + * @param inX x value + * @param inY y value + */ + public XYpoint(double inX, double inY) { + x = inX; y = inY; + } + + /** + * @param inOther other vector + * @return scalar dot product + */ + public double dot(XYpoint inOther) { + return (x * inOther.x + y * inOther.y); + } + + /** @return length of vector */ + public double len() {return Math.sqrt(len2());} + + /** @return squared length of vector */ + public double len2() {return (x*x + y*y);} + + /** + * @param inOther other point object + * @return vector from this one to the other one + */ + public XYpoint vectorTo(XYpoint inOther) { + return new XYpoint(inOther.x - x, inOther.y - y); + } +}