Compare commits

..

3 Commits

Author SHA1 Message Date
ab2adf4173 Add simple testing script to main 2020-12-28 13:55:57 +01:00
2105e2619e Change std::max_element to min_element
We were using max_element twice
2020-12-28 13:55:38 +01:00
2ce6b06e54 Fix inserted point not being removed from list 2020-12-28 13:51:14 +01:00
3 changed files with 18 additions and 6 deletions

View File

@ -1,10 +1,10 @@
CXX = g++
CXXFLAGS = -Wall -O3
program: main.o
$(CXX) $(CXXFLAGS) -o program.out main.o
kdtree: main.o
$(CXX) $(CXXFLAGS) -o kdtree.out main.o
main.o: main.cpp
main.o: main.cpp kdtree.h
$(CXX) $(CXXFLAGS) -c main.cpp
clean :

View File

@ -74,7 +74,7 @@ class KDTree {
// Get extent along this axis
auto comparator = get_point_comparator(it_axis);
Point *min = *std::max_element(points.begin(), points.end(), comparator);
Point *min = *std::min_element(points.begin(), points.end(), comparator);
Point *max = *std::max_element(points.begin(), points.end(), comparator);
float extent = max->coordinates[it_axis] - min->coordinates[it_axis];
@ -98,7 +98,7 @@ class KDTree {
// TODO: This copies. Can we split the vector into two without copying?
std::vector<Point *> left_of_median(points.begin(), points.begin() + middle);
std::vector<Point *> right_of_median(points.begin() + middle, points.end());
std::vector<Point *> right_of_median(points.begin() + middle + 1, points.end());
// Create node, recursively call to construct subtree
return new Node(axis, median, build(left_of_median, depth + 1),
@ -112,7 +112,8 @@ class KDTree {
str += std::string(depth, '-') + std::to_string(point->coordinates[0]) + ", " +
std::to_string(point->coordinates[1]) + ", " +
std::to_string(point->coordinates[2]) + "\n";
std::to_string(point->coordinates[2]) + " with axis " + std::to_string(node->axis) +
"\n";
to_string_recurse(str, node->left, depth + 1);
to_string_recurse(str, node->right, depth + 1);

View File

@ -1,7 +1,18 @@
#include "kdtree.h"
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
// Test points
std::vector<Point *> points{new Point(new float[3]{0.0, 0.0, 0.0}, nullptr),
new Point(new float[3]{0.0, 1.0, 0.0}, nullptr),
new Point(new float[3]{0.0, 2.0, 3.0}, nullptr),
new Point(new float[3]{1.0, 0.0, 4.0}, nullptr)};
KDTree tree = KDTree(points);
std::cout << tree.to_string();
return 0;
}