From ebc4defb9c9c39c7ceedd3b099b3686e1498b736 Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Wed, 12 Aug 2020 13:51:09 +0900 Subject: [PATCH] optimization: optimize VBezier::length() - force VLine::length() function to be inline. --- src/vector/vbezier.cpp | 21 +++++++-------------- src/vector/vline.h | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/vector/vbezier.cpp b/src/vector/vbezier.cpp index 08498c3..797d564 100644 --- a/src/vector/vbezier.cpp +++ b/src/vector/vbezier.cpp @@ -43,23 +43,16 @@ VBezier VBezier::fromPoints(const VPointF &p1, const VPointF &p2, float VBezier::length() const { - VBezier left, right; /* bez poly splits */ - float len = 0.0; /* arc length */ - float chord; /* chord length */ - float length; + const auto len = VLine::length(x1, y1, x2, y2) + + VLine::length(x2, y2, x3, y3) + + VLine::length(x3, y3, x4, y4); - len = len + VLine::length(x1, y1, x2, y2); - len = len + VLine::length(x2, y2, x3, y3); - len = len + VLine::length(x3, y3, x4, y4); - - chord = VLine::length(x1, y1, x4, y4); + const auto chord = VLine::length(x1, y1, x4, y4); if ((len - chord) > 0.01) { - split(&left, &right); /* split in two */ - length = left.length() + /* try left side */ - right.length(); /* try right side */ - - return length; + VBezier left, right; + split(&left, &right); + return left.length() + right.length(); } return len; diff --git a/src/vector/vline.h b/src/vector/vline.h index cb8d9bf..ee8b4a5 100644 --- a/src/vector/vline.h +++ b/src/vector/vline.h @@ -66,7 +66,7 @@ inline float VLine::angle() const // approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm. // With alpha = 1, beta = 3/8, giving results with the largest error less // than 7% compared to the exact value. -inline float VLine::length(float x1, float y1, float x2, float y2) +inline V_ALWAYS_INLINE float VLine::length(float x1, float y1, float x2, float y2) { float x = x2 - x1; float y = y2 - y1; -- 2.34.1