diff options
author | David Robillard <d@drobilla.net> | 2013-12-18 19:38:58 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-12-18 19:38:58 +0000 |
commit | 63c2c34dd2b4ae5be99284b94c0b99d39600bd6f (patch) | |
tree | 364b54ae6981b9cbc539013471ff7a7382577fce /src | |
parent | 5b34aff56759854ee18dbd901264ee445a232703 (diff) | |
download | ganv-63c2c34dd2b4ae5be99284b94c0b99d39600bd6f.tar.gz ganv-63c2c34dd2b4ae5be99284b94c0b99d39600bd6f.tar.bz2 ganv-63c2c34dd2b4ae5be99284b94c0b99d39600bd6f.zip |
FDGL: Add spring between partners so interface modules line up in Patchage.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5181 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/Canvas.cpp | 26 | ||||
-rw-r--r-- | src/fdgl.hpp | 5 |
2 files changed, 23 insertions, 8 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp index cbe8263..a0d956f 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -722,6 +722,13 @@ get_pos_area(const GanvNode* node, Vector* pos, Vector* area) ganv_item_i2w(GANV_ITEM(node), &pos->x, &pos->y); } +inline void +apply_force(GanvNode* a, GanvNode* b, const Vector& f) +{ + a->impl->force = vec_add(a->impl->force, f); + b->impl->force = vec_sub(b->impl->force, f); +} + gboolean GanvCanvasImpl::layout_iteration() { @@ -748,8 +755,18 @@ GanvCanvasImpl::layout_iteration() const Vector f = repel_force(pos, area, pos2, area2); - node->impl->force = vec_add(node->impl->force, f); - node2->impl->force = vec_add(node2->impl->force, vec_mult(f, -1.0)); + apply_force(node, node2, f); + } + + // Add fake long spring to partner to line up as if connected + GanvNode* partner = ganv_node_get_partner(node); + if (partner) { + Vector ppos; + Vector parea; + get_pos_area(partner, &ppos, &parea); + + const Vector f = spring_force(ppos, pos, parea.x); + apply_force(node, partner, f); } } @@ -770,10 +787,9 @@ GanvCanvasImpl::layout_iteration() const Vector tail_pos = { edge->impl->coords.x1, edge->impl->coords.y1 }; const Vector head_pos = { edge->impl->coords.x2, edge->impl->coords.y2 }; - const Vector f = spring_force(head_pos, tail_pos); + const Vector f = spring_force(head_pos, tail_pos, 1.0); - tail->impl->force = vec_add(tail->impl->force, f); - head->impl->force = vec_add(head->impl->force, vec_mult(f, -1.0)); + apply_force(tail, head, f); } // Update positions based on calculated forces diff --git a/src/fdgl.hpp b/src/fdgl.hpp index cabdba8..844912e 100644 --- a/src/fdgl.hpp +++ b/src/fdgl.hpp @@ -17,7 +17,6 @@ #include <math.h> static const double SPRING_K = 12.0; -static const double SPRING_LEN = 0.1; static const double CHARGE_KE = 80000.0; static const double AREA_WEIGHT = 0.4; @@ -57,11 +56,11 @@ vec_rmag(const Vector& vec) /** Hooke's law */ inline Vector -spring_force(const Vector& a, const Vector& b) +spring_force(const Vector& a, const Vector& b, const double length) { const Vector vec = vec_sub(b, a); const double rmag = vec_rmag(vec); - const double displacement = SPRING_LEN - (1.0 / rmag); + const double displacement = length - (1.0 / rmag); return vec_mult(vec, rmag * SPRING_K * displacement * 0.5); } |