implemented mirroring in the Graphics classes

This commit is contained in:
hneemann 2019-11-06 19:10:27 +01:00
parent 45776736db
commit 834ee12957
3 changed files with 21 additions and 10 deletions

View File

@ -10,6 +10,8 @@ import de.neemann.digital.draw.graphics.text.formatter.GraphicsFormatter;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import static de.neemann.digital.draw.graphics.GraphicSwing.isMirror;
/**
* This class is used to determine the size of shapes or the whole circuit.
* You can draw the items to an instance of this class and then obtain the size
@ -110,8 +112,10 @@ public class GraphicMinMax extends Graphic {
p = p.sub(width.mul(orientation.getX()).div(2));
}
if (orientation.getY() != 0) {
p = p.sub(height.mul(orientation.getY()).div(2));
int oy = orientation.getY();
if (isMirror(p1, p2, p3)) oy = 2 - oy;
if (oy != 0) {
p = p.sub(height.mul(oy).div(2));
} else
p = p.sub(height.div(4));

View File

@ -13,6 +13,8 @@ import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashSet;
import static de.neemann.digital.draw.graphics.GraphicSwing.isMirror;
/**
* Used to create a SVG representation of the circuit.
*/
@ -204,7 +206,9 @@ public class GraphicSVG extends Graphic {
}
VectorFloat p = new VectorFloat(p1);
switch (orientation.getY()) {
int oy = orientation.getY();
if (isMirror(p1, p2, p3)) oy = 2 - oy;
switch (oy) {
case 1:
p = p.add(new VectorFloat(0, style.getFontSize() / 2f - style.getFontSize() / 8f));
break;

View File

@ -113,11 +113,6 @@ public class GraphicSwing extends Graphic {
rotateText = true;
}
VectorInterface d0 = p2.sub(p1).toFloat().getOrthogonal();
VectorInterface d1 = p3.sub(p1);
boolean mirror = d1.getX() * d0.getX() + d1.getY() * d0.getY() < 0;
if (mirror) text += "|";
GraphicsFormatter.Fragment fragment = GraphicsFormatter.createFragment(gr, text);
AffineTransform old = null;
@ -135,9 +130,11 @@ public class GraphicSwing extends Graphic {
}
int yoff = 0;
if (orientation.getY() != 0) {
int oy = orientation.getY();
if (isMirror(p1, p2, p3)) oy = 2 - oy;
if (oy != 0) {
int height = fragment.getHeight();
yoff += height * orientation.getY() / 3;
yoff += height * oy / 3;
}
fragment.draw(gr, p1.getX() + xoff, p1.getY() + yoff);
@ -147,6 +144,12 @@ public class GraphicSwing extends Graphic {
}
}
static boolean isMirror(VectorInterface p1, VectorInterface p2, VectorInterface p3) {
VectorInterface d0 = p2.sub(p1).toFloat().getOrthogonal();
VectorInterface d1 = p3.sub(p1);
return d1.getX() * d0.getX() + d1.getY() * d0.getY() < 0;
}
@Override
public boolean isFlagSet(Flag flag) {
if (flag == Flag.tiny)