Browse Source

optimize further_point_from_line

scanner 7 years ago
parent
commit
88adc0ba22
2 changed files with 6 additions and 5 deletions
  1. 1 0
      CMakeLists.txt
  2. 5 5
      geometry.cpp

+ 1 - 0
CMakeLists.txt

@@ -7,6 +7,7 @@ endif(NOT CMAKE_BUILD_TYPE)
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Werror -pedantic")
+set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -pedantic -pg")
 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -D_DEBUG")
 
 

+ 5 - 5
geometry.cpp

@@ -9,6 +9,9 @@ using namespace cv;
 
 #include "geometry.h"
 
+#define likely(x) __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
+
 double dist(Point a, Point b)
 {
 		return sqrt((double)pow(a.x-b.x,2)+pow(a.y-b.y,2));
@@ -115,16 +118,13 @@ cv::Point
 further_point_from_line(cv::Vec<double,3> line, std::vector<Point> points)
 {
     //distance = abs(a*p.x+b*p.y+c) / sqrt(a^2+b^2)
-    double denom = sqrt(line(0)*line(0)+line(1)*line(1));
     Point further = points[0];
     double maxdist = -1;
-    std::cout << "--- further" << std::endl;
     for(Point p: points)
     {
         double numerator = abs(line(0)*p.x + line(1)*p.y + line(2));
-        double distance = numerator/denom;
-        if(distance > maxdist) {
-            maxdist = distance;
+        if(numerator > maxdist) {
+            maxdist = numerator;
             further = p;
         }
     }