mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-12 14:26:09 -04:00
minor refactoring
This commit is contained in:
parent
3eb14ef41f
commit
cb0ef9a86b
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user