Allow user to specify weight for new connections
This commit is contained in:
@ -45,6 +45,12 @@ Startknoten (grün) auswählen löscht Pfäde.
|
|||||||
- Escape, `Q`:
|
- Escape, `Q`:
|
||||||
Beenden
|
Beenden
|
||||||
|
|
||||||
|
- `U`, `I`:
|
||||||
|
Gewichtung für die nächste Kante verkleinern/vergrößern
|
||||||
|
|
||||||
|
- `O`:
|
||||||
|
Gewichtung für die nächste Kante auf 1 zurücksetzten
|
||||||
|
|
||||||
## Wenn Knoten ausgewählt (rot)
|
## Wenn Knoten ausgewählt (rot)
|
||||||
|
|
||||||
- WASD:
|
- WASD:
|
||||||
|
@ -44,6 +44,7 @@ class GruphiFrame extends JFrame {
|
|||||||
private Map<Node, Path<Node, Double>> paths = null;
|
private Map<Node, Path<Node, Double>> paths = null;
|
||||||
private boolean running = true;
|
private boolean running = true;
|
||||||
private boolean nuggets = false;
|
private boolean nuggets = false;
|
||||||
|
private double weight = 1.0;
|
||||||
|
|
||||||
GruphiFrame(Gruphi gruphi) {
|
GruphiFrame(Gruphi gruphi) {
|
||||||
super("Gruphi - The Graph GUI - By Osh");
|
super("Gruphi - The Graph GUI - By Osh");
|
||||||
@ -141,6 +142,18 @@ class GruphiFrame extends JFrame {
|
|||||||
generatePaths();
|
generatePaths();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case KeyEvent.VK_I: {
|
||||||
|
weight = Math.min(weight*1.01, 10);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case KeyEvent.VK_U: {
|
||||||
|
weight = Math.max(weight/1.01, 0.1);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case KeyEvent.VK_O: {
|
||||||
|
weight = 1.0;
|
||||||
|
} break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +225,7 @@ class GruphiFrame extends JFrame {
|
|||||||
if (graph.getChildrenForNode(selected).contains(n)) {
|
if (graph.getChildrenForNode(selected).contains(n)) {
|
||||||
graph.disconnectNodes(selected, n);
|
graph.disconnectNodes(selected, n);
|
||||||
} else {
|
} else {
|
||||||
graph.connectNodes(selected, 1.0, n);
|
graph.connectNodes(selected, weight, n);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selected.pos = v;
|
selected.pos = v;
|
||||||
@ -288,9 +301,12 @@ class GruphiFrame extends JFrame {
|
|||||||
|
|
||||||
public void draw(Drawable d) {
|
public void draw(Drawable d) {
|
||||||
d.fill(Color.BLACK);
|
d.fill(Color.BLACK);
|
||||||
|
|
||||||
d.rect(0, 0, getWidth(), getHeight());
|
d.rect(0, 0, getWidth(), getHeight());
|
||||||
panningAndZooming.draw(d, () ->
|
panningAndZooming.draw(d, () ->
|
||||||
drawNodes(d));
|
drawNodes(d));
|
||||||
|
|
||||||
|
d.text(10, 10, String.format("Weight: %.2f", weight));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawNodes(Drawable d) {
|
private void drawNodes(Drawable d) {
|
||||||
@ -323,7 +339,6 @@ class GruphiFrame extends JFrame {
|
|||||||
var path = paths.get(selected);
|
var path = paths.get(selected);
|
||||||
|
|
||||||
d.fill(Color.GREEN);
|
d.fill(Color.GREEN);
|
||||||
d.strokeWeight(2);
|
|
||||||
Node prev = null;
|
Node prev = null;
|
||||||
for (var node : path) {
|
for (var node : path) {
|
||||||
if (prev != null) {
|
if (prev != null) {
|
||||||
@ -336,6 +351,7 @@ class GruphiFrame extends JFrame {
|
|||||||
private void drawConnections(Drawable d) {
|
private void drawConnections(Drawable d) {
|
||||||
for (var node : graph.getAllNodes()) {
|
for (var node : graph.getAllNodes()) {
|
||||||
for (var child : graph.getChildrenForNode(node)) {
|
for (var child : graph.getChildrenForNode(node)) {
|
||||||
|
d.strokeWeight(2 * graph.getArcWeightBetween(node, child));
|
||||||
d.line(node.pos.x, node.pos.y, child.pos.x, child.pos.y);
|
d.line(node.pos.x, node.pos.y, child.pos.x, child.pos.y);
|
||||||
drawConnectionArrowHead(d, node, child);
|
drawConnectionArrowHead(d, node, child);
|
||||||
}
|
}
|
||||||
@ -346,7 +362,7 @@ class GruphiFrame extends JFrame {
|
|||||||
var v = child.pos
|
var v = child.pos
|
||||||
.copy()
|
.copy()
|
||||||
.sub(node.pos);
|
.sub(node.pos);
|
||||||
var r = 4;
|
var r = 4 * graph.getArcWeightBetween(node, child);
|
||||||
var p = v.copy()
|
var p = v.copy()
|
||||||
.setMag(v.mag() - child.radius)
|
.setMag(v.mag() - child.radius)
|
||||||
.add(node.pos);
|
.add(node.pos);
|
||||||
|
Reference in New Issue
Block a user