Voltmeter layout WIP

This commit is contained in:
Patrick Haßel 2024-05-23 16:28:40 +02:00
parent 2dc9513476
commit e7e74cba44
5 changed files with 22 additions and 15 deletions

View File

@ -30,6 +30,10 @@ public class CONFIG {
public static final int P75 = (int) round(0.75 * RASTER);
public static final int P70 = (int) round(0.7 * RASTER);
public static final int P80 = (int) round(0.8 * RASTER);
public static final int P90 = (int) round(0.9 * RASTER);
public static final int P95 = (int) round(0.95 * RASTER);

View File

@ -47,18 +47,18 @@ public class Render {
}
}
public void circle(final Position center, final double radius, final Color border, final Stroke stroke, final Color fill) {
public void circle(final Position center, final double radius, final Color border, final Stroke stroke, final Color fill, final double startAngle, final double arcAngle) {
final int _x = (int) round(center.inside.x - radius);
final int _y = (int) round(center.inside.y - radius);
final int diameter = (int) round(radius * 2);
if (fill != null) {
g.setColor(fill);
g.fillArc(_x, _y, diameter, diameter, 0, 360);
g.fillArc(_x, _y, diameter, diameter, (int) round(startAngle), (int) round(arcAngle));
}
if (border != null && stroke != null) {
g.setColor(border);
g.setStroke(stroke);
g.drawArc(_x, _y, diameter, diameter, 0, 360);
g.drawArc(_x, _y, diameter, diameter, (int) round(startAngle), (int) round(arcAngle));
}
}

View File

@ -66,7 +66,7 @@ public class Junction {
}
public void render(final Render render) {
render.circle(position, JUNCTION_RADIUS, Color.BLACK, JUNCTION_STROKE, color);
render.circle(position, JUNCTION_RADIUS, Color.BLACK, JUNCTION_STROKE, color, 0, 360);
}
public void updatePosition() {

View File

@ -87,7 +87,7 @@ public class Light extends Part {
@Override
protected void _render() {
render.line(a, b, Color.BLACK, SYMBOL_STROKE);
render.circle(ABS(P50, P50), BULB_RADIUS, Color.BLACK, SYMBOL_STROKE, color);
render.circle(ABS(P50, P50), BULB_RADIUS, Color.BLACK, SYMBOL_STROKE, color, 0, 360);
final double diag = 0.33 * RASTER;
render.line(ABS(diag, diag), ABS(RASTER - diag, RASTER - diag), Color.BLACK, SYMBOL_STROKE);

View File

@ -20,15 +20,17 @@ import static de.ph87.electro.circuit.part.Position.ABS;
@Getter
public class Voltmeter extends Part {
private static final RealVector ANCHOR = new ArrayRealVector(new double[]{P50, P50});
private static final double FINGER_LENGTH = P70;
private static final RealVector FINGER = new ArrayRealVector(new double[]{P90, P50}).subtract(ANCHOR);
private static final RealVector ANCHOR = new ArrayRealVector(new double[]{P50, P80});
private static final RealVector FINGER = new ArrayRealVector(new double[]{ANCHOR.getEntry(0) + FINGER_LENGTH, P50}).subtract(ANCHOR);
private static final Stroke SCALE_STROKE = new BasicStroke(1);
private static final double DEGREES_TOTAL = 90.0;
private static final double DEGREES_RANGE = 90;
private static final double DEGREES_ROTATE = -135.0;
public static final double DEGREES_OFFSET = (180 - DEGREES_RANGE) / 2;
private final Junction a;
@ -44,15 +46,15 @@ public class Voltmeter extends Part {
public Voltmeter(final Circuit circuit, final Position position) {
super(circuit, "Voltmeter", position);
a = addJunction("A", P10, P50);
b = addJunction("B", P90, P50);
a = addJunction("A", P10, P90);
b = addJunction("B", P90, P90);
postCalculate(); // TODO remove
}
public Voltmeter(final Circuit circuit, final PartDto dto) {
super(circuit, dto);
a = addJunction("A", P10, P50);
b = addJunction("B", P90, P50);
a = addJunction("A", P10, P90);
b = addJunction("B", P90, P90);
postCalculate(); // TODO remove
}
@ -70,7 +72,7 @@ public class Voltmeter extends Part {
public void postCalculate() {
voltage = !Double.isNaN(b.getVoltage()) && !Double.isNaN(a.getVoltage()) ? b.getVoltage() - a.getVoltage() : 0.0;
final double ratio = (voltage - min) / (max - min);
final double degrees = DEGREES_TOTAL * ratio + DEGREES_ROTATE;
final double degrees = DEGREES_RANGE * ratio + DEGREES_OFFSET / 2;
final RealMatrix rotate = RotationMatrix.ofDegrees(degrees);
final RealVector rotatedFinger = rotate.operate(FINGER);
tip = ANCHOR.add(rotatedFinger);
@ -79,12 +81,13 @@ public class Voltmeter extends Part {
@Override
public void _render() {
render.clockwise(getOrientation());
render.circle(ABS(ANCHOR), FINGER_LENGTH, Color.BLACK, SCALE_STROKE, Color.white, DEGREES_OFFSET, DEGREES_RANGE);
render.line(ABS(ANCHOR), ABS(tip), Color.BLACK, SCALE_STROKE);
}
@Override
protected void _labels() {
render.textCenter(LABEL_FONT, "%.2f V".formatted(voltage), P50, P75, Color.BLACK);
render.textCenter(LABEL_FONT, "%.2f V".formatted(voltage), P50, P90, Color.BLACK);
}
@Override