forked from pcb2gcode/pcb2gcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Perform path finding on all milling
This required major performance improvements in path-finding.
- Loading branch information
Showing
105 changed files
with
48,797 additions
and
51,295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef DISJOINT_SET_HPP | ||
#define DISJOINT_SET_HPP | ||
|
||
#include <unordered_map> | ||
|
||
template <typename node_t> | ||
class DisjointSet { | ||
public: | ||
const node_t& find(const node_t& node) { | ||
const node_t *current = &node; | ||
if (parent.find(*current) == parent.cend()) { | ||
// New node | ||
parent[node] = node; | ||
rank[node] = 0; | ||
return node; | ||
} | ||
while (parent.at(*current) != *current) { | ||
const auto& p = parent[*current]; | ||
const auto& pp = parent[p]; | ||
parent[*current] = pp; | ||
current = &p; | ||
} | ||
return *current; | ||
} | ||
|
||
void join(const node_t& x, const node_t& y) { | ||
const auto& root_x = find(x); | ||
const auto& root_y = find(y); | ||
if (root_x == root_y) { | ||
return; | ||
} | ||
join_unjoined(root_x, root_y); | ||
} | ||
|
||
private: | ||
// It's expected that x and y both have themselves as parents. | ||
void join_unjoined(const node_t& x, const node_t& y) { | ||
if (rank[x] < rank[y]) { | ||
join_unjoined(y, x); | ||
return; | ||
} | ||
parent[y] = x; | ||
if (rank[x] == rank[y]) { | ||
rank[x]++; | ||
} | ||
} | ||
|
||
// Stores the parent for each node. If the parent isn't in the map | ||
// then the node is its own parent. | ||
std::unordered_map<node_t, node_t> parent; | ||
// Stores the rank of each node, which is an upper bound on the | ||
// height of the subtree below the node. Nodes that aren't in the | ||
// nap are assumed to have a rank of 0. | ||
std::unordered_map<node_t, size_t> rank; | ||
}; | ||
|
||
#endif // DISJOINT_SET_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#define BOOST_TEST_MODULE disjoint set tests | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "disjoint_set.hpp" | ||
|
||
BOOST_AUTO_TEST_SUITE(disjoint_set_tests) | ||
|
||
BOOST_AUTO_TEST_CASE(simple) { | ||
DisjointSet<int> d; | ||
BOOST_CHECK(d.find(2) != d.find(3)); | ||
d.join(3,2); | ||
BOOST_CHECK(d.find(2) == d.find(3)); | ||
BOOST_CHECK(d.find(9) != d.find(3)); | ||
d.join(4,5); | ||
BOOST_CHECK(d.find(4) == d.find(5)); | ||
BOOST_CHECK(d.find(4) != d.find(3)); | ||
BOOST_CHECK(d.find(2) == d.find(3)); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(simple2) { | ||
DisjointSet<int> d; | ||
BOOST_CHECK(d.find(3) != d.find(4)); | ||
d.join(3,4); | ||
BOOST_CHECK(d.find(3) == d.find(4)); | ||
BOOST_CHECK(d.find(1) != d.find(3)); | ||
d.join(1,3); | ||
BOOST_CHECK(d.find(1) == d.find(3)); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.