summaryrefslogtreecommitdiffstats
path: root/src/fdgl.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-12-19 03:40:21 +0000
committerDavid Robillard <d@drobilla.net>2013-12-19 03:40:21 +0000
commit39df78049d6cbb0b368215d5d37a3fa03042eb45 (patch)
tree17983faa77200cc54a0ee8c749b09ed1048a72ed /src/fdgl.hpp
parent730f7d88ff1c86872cdcf289dd2b72a845fb8449 (diff)
downloadganv-39df78049d6cbb0b368215d5d37a3fa03042eb45.tar.gz
ganv-39df78049d6cbb0b368215d5d37a3fa03042eb45.tar.bz2
ganv-39df78049d6cbb0b368215d5d37a3fa03042eb45.zip
FDGL: Improve flow-directed layout.
Allow apps to specify nodes as sources to improve layout. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5185 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/fdgl.hpp')
-rw-r--r--src/fdgl.hpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/fdgl.hpp b/src/fdgl.hpp
index b28df82..42b3538 100644
--- a/src/fdgl.hpp
+++ b/src/fdgl.hpp
@@ -16,8 +16,8 @@
#include <float.h>
#include <math.h>
-static const double SPRING_K = 14.0;
-static const double CHARGE_KE = 60000.0;
+static const double SPRING_K = 16.0;
+static const double CHARGE_KE = 40000.0;
static const double AREA_WEIGHT = 0.5;
struct Region {
@@ -61,12 +61,23 @@ vec_rmag(const Vector& vec)
/** Hooke's law */
inline Vector
-spring_force(const Vector& a, const Vector& b, const double length)
+spring_force(const Vector& a, const Vector& b, double length, double k)
{
const Vector vec = vec_sub(b, a);
const double rmag = vec_rmag(vec);
const double displacement = length - (1.0 / rmag);
- return vec_mult(vec, rmag * SPRING_K * displacement * 0.5);
+ return vec_mult(vec, rmag * k * displacement * 0.5);
+}
+
+/** Spring force with a directional force to align with flow direction. */
+static const Vector
+edge_force(const Vector& dir,
+ const Vector& hpos,
+ const Vector& tpos,
+ double length,
+ double k)
+{
+ return vec_add(dir, spring_force(hpos, tpos, length, k));
}
/** Modified Coulomb's law */