From b3bc9a7a3688aeac53d75befae2a6552d8bc5846 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 18 Dec 2013 07:11:11 +0000 Subject: FDGL performance improvements. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5179 a436a847-0d15-0410-975c-d299462d15a1 --- src/Canvas.cpp | 22 +++++++++++++++++++--- src/fdgl.hpp | 10 +++++----- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Canvas.cpp b/src/Canvas.cpp index bcb4dd1..5d4eb55 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -150,7 +150,7 @@ struct GanvCanvasImpl { #ifdef GANV_FDGL g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, - 100, + 40, on_timeout, this, NULL); @@ -785,7 +785,7 @@ GanvCanvasImpl::layout_iteration() GanvNode* const node = GANV_NODE(*i); static const float dur = 0.1; // Time duration - static const float damp = 0.5; // Velocity damping (momentum loss) + static const float damp = 0.7; // Velocity damping (momentum loss) if (node->impl->grabbed) { node->impl->vel.x = 0.0; @@ -797,7 +797,17 @@ GanvCanvasImpl::layout_iteration() // Update position const Vector dpos = vec_mult(node->impl->vel, dur); - ganv_node_move(node, dpos.x, dpos.y); + if (fabs(dpos.x) > 1.0 || fabs(dpos.y) > 1.0) { + GanvItem* item = GANV_ITEM(node); + ganv_item_move(GANV_ITEM(node), dpos.x, dpos.y); + static const float min_coord = 4.0; + if (item->x < min_coord) { + item->x = min_coord; + } + if (item->y < min_coord) { + item->y = min_coord; + } + } } // Reset forces for next time @@ -805,6 +815,12 @@ GanvCanvasImpl::layout_iteration() node->impl->force.y = 0.0; } + // Now update edge positions to reflect new node positions + FOREACH_EDGE(_edges, i) { + GanvEdge* const edge = *i; + ganv_edge_update_location(edge); + } + return TRUE; } diff --git a/src/fdgl.hpp b/src/fdgl.hpp index 6bdb2e7..cabdba8 100644 --- a/src/fdgl.hpp +++ b/src/fdgl.hpp @@ -16,10 +16,10 @@ #include #include -static const double SPRING_K = 50.0; -static const double SPRING_LEN = 1.0; -static const double CHARGE_KE = 50000.0; -static const double AREA_WEIGHT = 0.25; +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; inline Vector vec_add(const Vector& a, const Vector& b) @@ -70,7 +70,7 @@ inline Vector repel_force(const Vector& a, const Vector& a_area, const Vector& b, const Vector& b_area) { - const Vector vec = vec_sub(a, b); + const Vector vec = vec_mult(vec_sub(a, b), 4.0); const double rmag = vec_rmag(vec); const Vector a_weight = vec_mult(a_area, AREA_WEIGHT); const Vector b_weight = vec_mult(b_area, AREA_WEIGHT); -- cgit v1.2.1