mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 14:56:29 -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) {
|
static int getMirrorYOrientation(Orientation orientation, VectorInterface p1, VectorInterface p2, VectorInterface p3) {
|
||||||
int oy = orientation.getY();
|
int oy = orientation.getY();
|
||||||
VectorInterface d0 = p2.sub(p1).toFloat().getOrthogonal();
|
VectorInterface d0 = p2.sub(p1).getOrthogonal();
|
||||||
VectorInterface d1 = p3.sub(p1);
|
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;
|
return oy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,4 +256,10 @@ public class Vector implements VectorInterface {
|
|||||||
public VectorFloat toFloat() {
|
public VectorFloat toFloat() {
|
||||||
return new VectorFloat(x, y);
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Creates vector which is orthogonal to this one.
|
|
||||||
*
|
|
||||||
* @return the orthogonal vector
|
|
||||||
*/
|
|
||||||
public VectorFloat getOrthogonal() {
|
public VectorFloat getOrthogonal() {
|
||||||
return new VectorFloat(y, -x);
|
return new VectorFloat(y, -x);
|
||||||
}
|
}
|
||||||
|
@ -91,4 +91,17 @@ public interface VectorInterface {
|
|||||||
* @return the length of the vector
|
* @return the length of the vector
|
||||||
*/
|
*/
|
||||||
float len();
|
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