22 * Java transcription of Springy v2.8.0
33 *
44 * Copyright (c) 2010-2018 Dennis Hotson
5- * Copyright (c) 2021 RTE (https://www.rte-france.com)
5+ * Copyright (c) 2021-2025 RTE (https://www.rte-france.com)
66 *
77 * Permission is hereby granted, free of charge, to any person
88 * obtaining a copy of this software and associated documentation
@@ -62,16 +62,13 @@ public class ForceLayout<V, E> {
6262 private static final double DEFAULT_REPULSION = 800.0 ;
6363 private static final double DEFAULT_FRICTION = 500 ;
6464 private static final double DEFAULT_MAX_SPEED = 100 ;
65- /** Spring repulsion is disabled by default */
66- private static final double DEFAULT_SPRING_REPULSION_FACTOR = 0.0 ;
6765
6866 private int maxSteps ;
6967 private double minEnergyThreshold ;
7068 private double deltaTime ;
7169 private double repulsion ;
7270 private double friction ;
7371 private double maxSpeed ;
74- private double springRepulsionFactor ;
7572 /** Initial location for some nodes */
7673 private Map <V , Point > initialPoints = Collections .emptyMap ();
7774 /** The location of these nodes should not be modified by the layout */
@@ -95,7 +92,6 @@ public ForceLayout(Graph<V, E> graph) {
9592 this .repulsion = DEFAULT_REPULSION ;
9693 this .friction = DEFAULT_FRICTION ;
9794 this .maxSpeed = DEFAULT_MAX_SPEED ;
98- this .springRepulsionFactor = DEFAULT_SPRING_REPULSION_FACTOR ;
9995 this .graph = Objects .requireNonNull (graph );
10096 }
10197
@@ -139,11 +135,6 @@ public ForceLayout<V, E> setMaxSpeed(double maxSpeed) {
139135 return this ;
140136 }
141137
142- public ForceLayout <V , E > setSpringRepulsionFactor (double springRepulsionFactor ) {
143- this .springRepulsionFactor = springRepulsionFactor ;
144- return this ;
145- }
146-
147138 public ForceLayout <V , E > setInitialPoints (Map <V , Point > initialPoints ) {
148139 this .initialPoints = Objects .requireNonNull (initialPoints );
149140 return this ;
@@ -210,9 +201,6 @@ public void execute() {
210201 int i ;
211202 for (i = 0 ; i < maxSteps ; i ++) {
212203 applyCoulombsLawToPoints ();
213- if (springRepulsionFactor != 0.0 ) {
214- applyCoulombsLawToSprings ();
215- }
216204 applyHookesLaw ();
217205 if (attractToCenterForce ) {
218206 attractToCenter ();
@@ -255,45 +243,6 @@ private void applyCoulombsLawToPoints() {
255243 }
256244 }
257245
258- private void applyCoulombsLawToSprings () {
259- for (Point point : points .values ()) {
260- Vector p = point .getPosition ();
261- for (Spring spring : springs ) {
262- Point n1 = spring .getNode1 ();
263- Point n2 = spring .getNode2 ();
264- if (!n1 .equals (point ) && !n2 .equals (point )) {
265- Vector q1 = spring .getNode1 ().getPosition ();
266- Vector q2 = spring .getNode2 ().getPosition ();
267- Vector newCenter = q1 .add (q2 .subtract (q1 ).multiply (0.5 ));
268- Vector force = coulombsForce (p , newCenter , repulsion * springRepulsionFactor );
269- point .applyForce (force );
270- n1 .applyForce (force .multiply (-0.5 ));
271- n2 .applyForce (force .multiply (-0.5 ));
272- }
273- }
274- }
275- for (Spring spring : springs ) {
276- Point n1 = spring .getNode1 ();
277- Point n2 = spring .getNode2 ();
278- Vector p1 = spring .getNode1 ().getPosition ();
279- Vector p2 = spring .getNode2 ().getPosition ();
280- Vector newCenter = p1 .add (p2 .subtract (p1 ).multiply (0.5 ));
281- for (Spring otherSpring : springs ) {
282- if (!spring .equals (otherSpring )) {
283- // Compute the repulsion force between centers of the springs
284- Vector op1 = otherSpring .getNode1 ().getPosition ();
285- Vector op2 = otherSpring .getNode2 ().getPosition ();
286- Vector otherCenter = op1 .add (op2 .subtract (op1 ).multiply (0.5 ));
287- Vector force = coulombsForce (newCenter , otherCenter , repulsion * springRepulsionFactor );
288-
289- // And apply it to both points of the spring
290- n1 .applyForce (force );
291- n2 .applyForce (force );
292- }
293- }
294- }
295- }
296-
297246 private void applyHookesLaw () {
298247 for (Spring spring : springs ) {
299248 Point point1 = spring .getNode1 ();
0 commit comments