From 88a5425f311b35fc3eaad8c5d3810195ec6ac222 Mon Sep 17 00:00:00 2001 From: erg Date: Tue, 24 May 2011 20:17:01 +0000 Subject: [PATCH] Add utility function to return approximate midpoint of an edge --- lib/common/render.h | 1 + lib/common/splines.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/common/render.h b/lib/common/render.h index 1283739c0..bea9f5468 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -134,6 +134,7 @@ extern "C" { extern void place_graph_label(Agraph_t *); extern void place_portlabel(edge_t * e, boolean head_p); extern void makePortLabels(edge_t * e); + extern pointf edgeMidpoint(graph_t* g, edge_t * e); extern void addEdgeLabels(graph_t* g, edge_t * e, pointf rp, pointf rq); extern void pop_obj_state(GVJ_t *job); extern obj_state_t* push_obj_state(GVJ_t *job); diff --git a/lib/common/splines.c b/lib/common/splines.c index 13d3485fc..ada1efeab 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -1195,6 +1195,28 @@ polylineMidpoint (splines* spl, pointf* pp, pointf* pq) return mf; } +pointf +edgeMidpoint (graph_t* g, edge_t * e) +{ + int et = EDGE_TYPE (g); + pointf d, spf, p, q; + + endPoints(ED_spl(e), &p, &q); + if (APPROXEQPT(p, q, MILLIPOINT)) { /* degenerate spline */ + spf = p; + } + else if (et == ET_SPLINE) { + d.x = (q.x + p.x) / 2.; + d.y = (p.y + q.y) / 2.; + spf = dotneato_closest(ED_spl(e), d); + } + else { /* ET_PLINE, ET_ORTHO or ET_LINE */ + spf = polylineMidpoint (ED_spl(e), &p, &q); + } + + return spf; +} + #define LEFTOF(a,b,c) (((a.y - b.y)*(c.x - b.x) - (c.y - b.y)*(a.x - b.x)) > 0) #define MAXLABELWD (POINTS_PER_INCH/2.0) -- 2.40.0