Commit 44c7ce72 authored by Nico Mack's avatar Nico Mack

Added updating methods for body mass and spring length

parent e8397781
......@@ -207,10 +207,8 @@ public abstract class Marker implements Positionable, Clusterable, Cloneable {
* @return
*/
public @Nullable Point getPosition(Integer handleId) {
if (positions.containsKey(handleId)) {
return positions.get(handleId).clone();
}
return null;
Point position = positions.get(handleId);
return (position != null) ? position.clone() : new Point();
}
// ---------------------------------------------------------------------------
......
......@@ -176,7 +176,7 @@ public class Graph {
boolean alreadyKnown = false;
for (Edge edge : this.edges) {
alreadyKnown |= (edgeToAdd.getId() == edge.getId());
alreadyKnown |= (edgeToAdd.getId().equals(edge.getId()));
}
if (!alreadyKnown) {
......@@ -200,7 +200,7 @@ public class Graph {
for (
Edge edge : this.neighbours.get(edgeToAdd.getSource().getId()).get(edgeToAdd.getTarget().getId())) {
alreadyKnown |= (edgeToAdd.getId() == edge.getId());
alreadyKnown |= (edgeToAdd.getId().equals(edge.getId()));
}
if (!alreadyKnown) {
......
......@@ -140,7 +140,7 @@ public class Node implements Comparable<Node> {
if (object instanceof Node) {
Node node = (Node) object;
return id == node.id;
return id.equals(node.id);
}
return false;
}
......
......@@ -312,6 +312,24 @@ public class ForceDirectedGraph implements GraphListener, Runnable {
this.updatePositions(graphBodies, timestep);
}
// ---------------------------------------------------------------------------
private void updateBodyMass() {
for (Node node : this.graph.getNodes()) {
Body body = this.getBody(node);
body.setMass(node.getMass());
}
}
// ---------------------------------------------------------------------------
private void updateSpringLength() {
for (Edge edge : this.graph.getEdges()) {
Spring spring = this.getSpring(edge);
spring.setLength(edge.getLength());
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
......@@ -449,6 +467,10 @@ public class ForceDirectedGraph implements GraphListener, Runnable {
@Override
public void graphChanged() {
this.updateBodyMass();
this.updateSpringLength();
if (!running) {
Thread runner = new Thread(this, "Force Directed Graph"); //$NON-NLS-1$
runner.start();
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.utility.vector;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class Vector {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public abstract int getNumberOfDimensions();
// ---------------------------------------------------------------------------
/**
* @param scale
* @return
*/
// ---------------------------------------------------------------------------
public abstract Vector random(double scale);
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public abstract Vector zero();
// ---------------------------------------------------------------------------
/**
* @param operand
* @return a new Dimension object representing the sum of this dimension and the specified operand.
*/
// ---------------------------------------------------------------------------
public abstract Vector add(Vector operand);
// ---------------------------------------------------------------------------
/**
* @param operand
* @return a new Dimension object representing the operand subtracted from this instance.
*/
// ---------------------------------------------------------------------------
public abstract Vector subtract(Vector operand);
// ---------------------------------------------------------------------------
/**
* @param factor
* specifies the factor to multiply this dimension with.
* @return a new Dimension object representing this instance scaled by the specified factor.
*/
// ---------------------------------------------------------------------------
public abstract Vector multiplyBy(double factor);
// ---------------------------------------------------------------------------
/**
* @param factor
* specifies the factor to multiply this dimension with.
* @return a new Dimension object representing this instance scaled by the specified factor.
*/
// ---------------------------------------------------------------------------
public abstract Vector atAngle(double angle);
// ---------------------------------------------------------------------------
/**
* @param factor
* specifies the factor to multiply this dimension with.
* @return a new Dimension object representing this instance scaled by the specified factor.
*/
// ---------------------------------------------------------------------------
public abstract Vector divideBy(double factor);
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public abstract double magnitude();
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public Vector normalize() {
return this.divideBy(this.magnitude());
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public abstract Vector normal();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class
// ***************************************************************************
// ---------------------------------------------------------------------------
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment