001/*
002 * Copyright 2006 - 2013
003 *     Stefan Balev     <stefan.balev@graphstream-project.org>
004 *     Julien Baudry    <julien.baudry@graphstream-project.org>
005 *     Antoine Dutot    <antoine.dutot@graphstream-project.org>
006 *     Yoann Pigné      <yoann.pigne@graphstream-project.org>
007 *     Guilhelm Savin   <guilhelm.savin@graphstream-project.org>
008 * 
009 * This file is part of GraphStream <http://graphstream-project.org>.
010 * 
011 * GraphStream is a library whose purpose is to handle static or dynamic
012 * graph, create them from scratch, file or any source and display them.
013 * 
014 * This program is free software distributed under the terms of two licenses, the
015 * CeCILL-C license that fits European law, and the GNU Lesser General Public
016 * License. You can  use, modify and/ or redistribute the software under the terms
017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
019 * the Free Software Foundation, either version 3 of the License, or (at your
020 * option) any later version.
021 * 
022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
024 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
025 * 
026 * You should have received a copy of the GNU Lesser General Public License
027 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
028 * 
029 * The fact that you are presently reading this means that you have had
030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
031 */
032package org.graphstream.ui.layout.springbox;
033
034import org.graphstream.ui.geom.Vector3;
035
036/**
037 * Edge representation.
038 * 
039 * <p>
040 * This is mainly used to store data about an edge, all the computation is done
041 * in the node particle.
042 * </p>
043 */
044public class EdgeSpring {
045        /**
046         * The edge identifier.
047         */
048        public String id;
049
050        /**
051         * Source node.
052         */
053        public NodeParticle node0;
054
055        /**
056         * Target node.
057         */
058        public NodeParticle node1;
059
060        /**
061         * Edge weight.
062         */
063        public double weight = 1f;
064
065        /**
066         * The attraction force on this edge.
067         */
068        public Vector3 spring = new Vector3();
069
070        /**
071         * Make this edge ignored by the layout algorithm ?.
072         */
073        public boolean ignored = false;
074
075        /**
076         * The edge attraction energy.
077         */
078        public double attE;
079
080        /**
081         * New edge between two given nodes.
082         * 
083         * @param id
084         *            The edge identifier.
085         * @param n0
086         *            The first node.
087         * @param n1
088         *            The second node.
089         */
090        public EdgeSpring(String id, NodeParticle n0, NodeParticle n1) {
091                this.id = id;
092                this.node0 = n0;
093                this.node1 = n1;
094        }
095
096        /**
097         * Considering the two nodes of the edge, return the one that was not given
098         * as argument.
099         * 
100         * @param node
101         *            One of the nodes of the edge.
102         * @return The other node.
103         */
104        public NodeParticle getOpposite(NodeParticle node) {
105                return node0 == node ? node1 : node0;
106        }
107}