]> git.sesse.net Git - tcxmerge/blobdiff - opt.cc
Fix a problem with the normals.
[tcxmerge] / opt.cc
diff --git a/opt.cc b/opt.cc
index bd70b4173443c9765d689e534e5fc24d5dd46f6f..87b632e62e7ac5fd042abe9c0ff1ae9988273417 100644 (file)
--- a/opt.cc
+++ b/opt.cc
@@ -93,8 +93,8 @@ BSPTreeNode* make_bsp_tree(const vector<int>& remaining_roads)
                const LineSegment& ls = roads[remaining_roads[i]];
 
                // find the normal
-               double a = -(ls.to.x - ls.from.x);
-               double b =  ls.to.y - ls.from.y;
+               double a =   ls.to.y - ls.from.y;
+               double b = -(ls.to.x - ls.from.x);
                double invlen = 1.0 / hypot(a, b);
                a *= invlen, b *= invlen;
 
@@ -128,6 +128,13 @@ BSPTreeNode* make_bsp_tree(const vector<int>& remaining_roads)
                }
        }
 
+       if (left.empty() || right.empty()) {
+               node->is_leaf = true;
+               node->left = node->right = NULL;
+               node->roads_this_node = remaining_roads;
+               return node;
+       }
+
        if (left.size() == 0) {
                node->left = NULL;
        } else {