From 39df78049d6cbb0b368215d5d37a3fa03042eb45 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 19 Dec 2013 03:40:21 +0000 Subject: 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 --- src/fdgl.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/fdgl.hpp') 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 #include -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 */ -- cgit v1.2.1