From 5f09026ddda7c7d201df54b031dd42c0f6b16ddb Mon Sep 17 00:00:00 2001 From: Bane Stojkovic Date: Mon, 12 Oct 2026 14:51:45 +0200 Subject: [PATCH] Include 'Potentiometer (Miniature)' and 'Trimmer Potentiometer' in Guitar Wiring Analyzer --- .../org/diylc/netlist/NetlistBuilder.java | 31 ++++++++-- .../diylc-core/src/main/resources/update.xml | 4 ++ .../org/diylc/netlist/NetlistBuilderTest.java | 58 +++++++++++++++++++ .../passive/AbstractPotentiometer.java | 11 ++++ .../passive/MiniaturePotentiometer.java | 7 ++- .../passive/PotentiometerPanel.java | 11 ---- 6 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 diylc/diylc-core/src/test/java/org/diylc/netlist/NetlistBuilderTest.java diff --git a/diylc/diylc-core/src/main/java/org/diylc/netlist/NetlistBuilder.java b/diylc/diylc-core/src/main/java/org/diylc/netlist/NetlistBuilder.java index e040fd82..7622d6c0 100644 --- a/diylc/diylc-core/src/main/java/org/diylc/netlist/NetlistBuilder.java +++ b/diylc/diylc-core/src/main/java/org/diylc/netlist/NetlistBuilder.java @@ -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 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> nodeMapByPoint, Builder 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()) - .add(new ProjectGraphNode(p, node)); + .add(new ProjectGraphNode(node.getPoint2D(), node)); } } diff --git a/diylc/diylc-core/src/main/resources/update.xml b/diylc/diylc-core/src/main/resources/update.xml index a68e0f3d..8c17c388 100644 --- a/diylc/diylc-core/src/main/resources/update.xml +++ b/diylc/diylc-core/src/main/resources/update.xml @@ -601,6 +601,10 @@ IMPROVEMENT 'Cut Line' can be rotated using keyboard shortcuts + + IMPROVEMENT + Include 'Potentiometer (Miniature)' and 'Trimmer Potentiometer' in Guitar Wiring Analyzer + https://github.com/bancika/diy-layout-creator/releases diff --git a/diylc/diylc-core/src/test/java/org/diylc/netlist/NetlistBuilderTest.java b/diylc/diylc-core/src/test/java/org/diylc/netlist/NetlistBuilderTest.java new file mode 100644 index 00000000..b950e227 --- /dev/null +++ b/diylc/diylc-core/src/test/java/org/diylc/netlist/NetlistBuilderTest.java @@ -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 . + +*/ +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> components = Arrays.asList(pin, far); + List nodes = Arrays.asList(new Node(pin, 0), new Node(far, 0)); + List connections = Arrays.asList( + new Connection(new Point2D.Double(520, 620), new Point2D.Double(800, 800), 0)); + return NetlistBuilder.buildNetlist(components, nodes, new ArrayList<>(), connections); + } +} diff --git a/diylc/diylc-library/src/main/java/org/diylc/components/passive/AbstractPotentiometer.java b/diylc/diylc-library/src/main/java/org/diylc/components/passive/AbstractPotentiometer.java index 646e4c57..1ba19854 100644 --- a/diylc/diylc-library/src/main/java/org/diylc/components/passive/AbstractPotentiometer.java +++ b/diylc/diylc-library/src/main/java/org/diylc/components/passive/AbstractPotentiometer.java @@ -99,4 +99,15 @@ public abstract class AbstractPotentiometer extends AbstractLabeledComponent index2) + return getInternalLinkName(index2, index1); + + if (index2 - index1 == 1) + return getControlPointNodeName(index1) + "-" + getControlPointNodeName(index2); + + return null; + } } diff --git a/diylc/diylc-library/src/main/java/org/diylc/components/passive/MiniaturePotentiometer.java b/diylc/diylc-library/src/main/java/org/diylc/components/passive/MiniaturePotentiometer.java index 04de3bfa..2471e926 100644 --- a/diylc/diylc-library/src/main/java/org/diylc/components/passive/MiniaturePotentiometer.java +++ b/diylc/diylc-library/src/main/java/org/diylc/components/passive/MiniaturePotentiometer.java @@ -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"); diff --git a/diylc/diylc-library/src/main/java/org/diylc/components/passive/PotentiometerPanel.java b/diylc/diylc-library/src/main/java/org/diylc/components/passive/PotentiometerPanel.java index 8cdb1850..3580d7e0 100644 --- a/diylc/diylc-library/src/main/java/org/diylc/components/passive/PotentiometerPanel.java +++ b/diylc/diylc-library/src/main/java/org/diylc/components/passive/PotentiometerPanel.java @@ -771,17 +771,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() {