Include 'Potentiometer (Miniature)' and 'Trimmer Potentiometer' in Guitar Wiring Analyzer

This commit is contained in:
Bane Stojkovic
2026-10-12 14:51:45 +02:00
parent 9e4ce7da81
commit 5f09026ddd
6 changed files with 106 additions and 16 deletions
@@ -354,6 +354,29 @@ public class NetlistBuilder {
builder.putEdge(nodeArr[i], nodeArr[j]);
}
}
// snapping alone splits points that straddle a cell boundary, e.g. 522 and 520 land in
// the cells at 524 and 520, so neighbouring cells are joined by actual distance
Point2D cell = entry.getKey();
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
if (dx == 0 && dy == 0) {
continue;
}
List<ProjectGraphNode> neighbours = nodeMapByPoint
.get(new Point2D.Double(cell.getX() + dx * eps, cell.getY() + dy * eps));
if (neighbours == null) {
continue;
}
for (ProjectGraphNode node : nodeArr) {
for (ProjectGraphNode neighbour : neighbours) {
if (node.getPoint().distance(neighbour.getPoint()) < eps) {
builder.putEdge(node, neighbour);
}
}
}
}
}
}
}
@@ -363,8 +386,8 @@ public class NetlistBuilder {
Point2D p1 = snapToEps(conn.getP1(), eps);
Point2D p2 = snapToEps(conn.getP2(), eps);
ProjectGraphNode graphNode1 = new ProjectGraphNode(p1, conn.getZIndex());
ProjectGraphNode graphNode2 = new ProjectGraphNode(p2, conn.getZIndex());
ProjectGraphNode graphNode1 = new ProjectGraphNode(conn.getP1(), conn.getZIndex());
ProjectGraphNode graphNode2 = new ProjectGraphNode(conn.getP2(), conn.getZIndex());
builder.addNode(graphNode1);
builder.addNode(graphNode2);
@@ -381,10 +404,10 @@ public class NetlistBuilder {
Map<Point2D, List<ProjectGraphNode>> nodeMapByPoint, Builder<ProjectGraphNode> builder) {
for (Node node : nodes) {
Point2D p = snapToEps(node.getPoint2D(), eps);
ProjectGraphNode graphNode = new ProjectGraphNode(p, node);
ProjectGraphNode graphNode = new ProjectGraphNode(node.getPoint2D(), node);
builder.addNode(graphNode);
nodeMapByPoint.computeIfAbsent(p, (point) -> new ArrayList<ProjectGraphNode>())
.add(new ProjectGraphNode(p, node));
.add(new ProjectGraphNode(node.getPoint2D(), node));
}
}
@@ -601,6 +601,10 @@
<changeType>IMPROVEMENT</changeType>
<description>'Cut Line' can be rotated using keyboard shortcuts</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Include 'Potentiometer (Miniature)' and 'Trimmer Potentiometer' in Guitar Wiring Analyzer</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
@@ -0,0 +1,58 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2025 held jointly by the individual authors.
This file is part of DIYLC.
DIYLC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DIYLC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/
package org.diylc.netlist;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.diylc.core.IDIYComponent;
import org.diylc.presenter.Connection;
import org.diylc.testcomponents.OnePointTestComponent;
public class NetlistBuilderTest {
@Test
public void pointsAcrossACellBoundaryAreConnected() {
// 522 snaps to 524 and 520 snaps to 520, yet the two are only 2px apart
Assert.assertEquals(1, buildWire(new Point2D.Double(522, 620)).getGroups().size());
}
@Test
public void pointsFurtherThanEpsAreNotConnected() {
Assert.assertTrue(buildWire(new Point2D.Double(525, 620)).getGroups().isEmpty());
}
private Netlist buildWire(Point2D pinPoint) {
OnePointTestComponent pin = new OnePointTestComponent("Pin", "1", pinPoint);
OnePointTestComponent far = new OnePointTestComponent("Far", "1", new Point2D.Double(800, 800));
List<IDIYComponent<?>> components = Arrays.asList(pin, far);
List<Node> nodes = Arrays.asList(new Node(pin, 0), new Node(far, 0));
List<Connection> connections = Arrays.asList(
new Connection(new Point2D.Double(520, 620), new Point2D.Double(800, 800), 0));
return NetlistBuilder.buildNetlist(components, nodes, new ArrayList<>(), connections);
}
}
@@ -99,4 +99,15 @@ public abstract class AbstractPotentiometer extends AbstractLabeledComponent<Res
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
}
@Override
public String getInternalLinkName(int index1, int index2) {
if (index1 > index2)
return getInternalLinkName(index2, index1);
if (index2 - index1 == 1)
return getControlPointNodeName(index1) + "-" + getControlPointNodeName(index2);
return null;
}
}
@@ -78,7 +78,7 @@ public class MiniaturePotentiometer extends AbstractPotentiometer {
}
protected void updateControlPoints() {
int spacing = getClosestOdd(PIN_SPACING.convertToPixels());
int spacing = (int) PIN_SPACING.convertToPixels();
int dx1 = 0;
int dy1 = 0;
int dx2 = 0;
@@ -530,6 +530,11 @@ public class MiniaturePotentiometer extends AbstractPotentiometer {
return false;
}
@Override
public String getControlPointNodeName(int index) {
return Integer.toString(3 - index);
}
public static enum MiniatureType {
RIGHT_ANGLED("Right-Angled"), VERTICAL("Vertical");
@@ -772,17 +772,6 @@ public class PotentiometerPanel extends AbstractPotentiometer implements ILayere
return Integer.toString(3 - index);
}
@Override
public String getInternalLinkName(int index1, int index2) {
if (index1 > index2)
return getInternalLinkName(index2, index1);
if (index2 - index1 == 1)
return getControlPointNodeName(index1) + "-" + getControlPointNodeName(index2);
return null;
}
@Override
public Rectangle2D getCachingBounds() {
Shape[] body = getBody();