From f1a066f4c112b3783d5a52a6a91badd8e956a312 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sun, 28 Jun 2009 21:02:09 +0200 Subject: [PATCH] [CpmlArc] Added cpml_arc_length() Implemented the arc length computation. The algorithm is quite trivial: the length is directly proportional to the angle delta of the arc and the proportion is applied to the whole circumference: length = delta / 2PI * circumference = delta * radius --- cpml/cpml-arc.c | 23 +++++++++++++++++++++++ cpml/cpml-arc.h | 1 + 2 files changed, 24 insertions(+) diff --git a/cpml/cpml-arc.c b/cpml/cpml-arc.c index 51e241d6..743ed924 100644 --- a/cpml/cpml-arc.c +++ b/cpml/cpml-arc.c @@ -162,6 +162,29 @@ cpml_arc_info(const CpmlPrimitive *arc, CpmlPair *center, } /** + * cpml_arc_length: + * @arc: the #CpmlPrimitive arc data + * + * Given the @arc primitive, returns its length. + * + * Return value: the requested length or 0 on errors + **/ +double +cpml_arc_length(const CpmlPrimitive *arc) +{ + double r, start, end, delta; + + if (!cpml_arc_info(arc, NULL, &r, &start, &end) || start == end) + return 0.; + + delta = end - start; + if (delta < 0) + delta += M_PI*2; + + return r*delta; +} + +/** * cpml_arc_pair_at: * @arc: the #CpmlPrimitive arc data * @pair: the destination #CpmlPair diff --git a/cpml/cpml-arc.h b/cpml/cpml-arc.h index 02348dd1..80ea7f58 100644 --- a/cpml/cpml-arc.h +++ b/cpml/cpml-arc.h @@ -40,6 +40,7 @@ cairo_bool_t double *r, double *start, double *end); +double cpml_arc_length (const CpmlPrimitive *arc); void cpml_arc_pair_at (const CpmlPrimitive *arc, CpmlPair *pair, double pos); -- 2.11.4.GIT