minor refactoring

This commit is contained in:
hneemann 2019-11-09 09:22:35 +01:00
parent 3eb14ef41f
commit cb0ef9a86b
4 changed files with 22 additions and 7 deletions

View File

@ -145,9 +145,9 @@ public class GraphicSwing extends Graphic {
static int getMirrorYOrientation(Orientation orientation, VectorInterface p1, VectorInterface p2, VectorInterface p3) {
int oy = orientation.getY();
VectorInterface d0 = p2.sub(p1).toFloat().getOrthogonal();
VectorInterface d0 = p2.sub(p1).getOrthogonal();
VectorInterface d1 = p3.sub(p1);
if (d1.getX() * d0.getX() + d1.getY() * d0.getY() < 0) oy = 2 - oy;
if (d0.scalar(d1) < 0) oy = 2 - oy;
return oy;
}

View File

@ -256,4 +256,10 @@ public class Vector implements VectorInterface {
public VectorFloat toFloat() {
return new VectorFloat(x, y);
}
@Override
public Vector getOrthogonal() {
return new Vector(y, -x);
}
}

View File

@ -164,11 +164,7 @@ public class VectorFloat implements VectorInterface {
return this;
}
/**
* Creates vector which is orthogonal to this one.
*
* @return the orthogonal vector
*/
@Override
public VectorFloat getOrthogonal() {
return new VectorFloat(y, -x);
}

View File

@ -91,4 +91,17 @@ public interface VectorInterface {
* @return the length of the vector
*/
float len();
/**
* @return a vector which is orthogonal to this one
*/
VectorInterface getOrthogonal();
/**
* @return the scalar product
*/
default float scalar(VectorInterface v) {
return getXFloat() * v.getXFloat() + getYFloat() * v.getYFloat();
}
}