Skip to content

Commit

Permalink
changed EPS so more common cases work, problems occur with more detai…
Browse files Browse the repository at this point in the history
…led models (maybe EPS should be settable?, maybe retessellation before makeManifold call will help?)
  • Loading branch information
jallwine committed Dec 7, 2017
1 parent e9018bc commit d854d84
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
42 changes: 22 additions & 20 deletions src/csgjs/CSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,28 @@ namespace csgjs {
++edgeDataItr;
}

//std::cout << "here" << std::endl;
//std::set<VertexKeyDist>::iterator testItr = vertices.begin();
//while(testItr != vertices.end()) {
// std::cout << testItr->key.hash << " " << testItr->key.v << " " << testItr->dist << std::endl;
// ++testItr;
//}

//std::cout << "starting vertices " << std::endl;
//std::unordered_map<VertexKey, std::vector<PolygonEdgeData*> >::iterator startItr = startVertex2PolygonEdgeData.begin();
//while(startItr != startVertex2PolygonEdgeData.end()) {
// std::cout << startItr->first.hash << " " << startItr->first.v << " starts " << startItr->second.size() << " edges" << std::endl;
// ++startItr;
//}

//std::cout << "ending vertices " << std::endl;
//std::unordered_map<VertexKey, std::vector<PolygonEdgeData*> >::iterator endItr = endVertex2PolygonEdgeData.begin();
//while(endItr != endVertex2PolygonEdgeData.end()) {
// std::cout << endItr->first.hash << " " << endItr->first.v << " ends " << endItr->second.size() << " edges" << std::endl;
// ++endItr;
//}
#ifdef CSGJS_DEBUG
std::cout << "all vertices" << std::endl;
std::set<VertexKeyDist>::iterator testItr = vertices.begin();
while(testItr != vertices.end()) {
std::cout << testItr->key.hash << " " << testItr->key.v << " " << testItr->dist << std::endl;
++testItr;
}

std::cout << "starting vertices " << std::endl;
std::unordered_map<VertexKey, std::vector<PolygonEdgeData*> >::iterator startItr = startVertex2PolygonEdgeData.begin();
while(startItr != startVertex2PolygonEdgeData.end()) {
std::cout << startItr->first.hash << " " << startItr->first.v << " starts " << startItr->second.size() << " edges" << std::endl;
++startItr;
}

std::cout << "ending vertices " << std::endl;
std::unordered_map<VertexKey, std::vector<PolygonEdgeData*> >::iterator endItr = endVertex2PolygonEdgeData.begin();
while(endItr != endVertex2PolygonEdgeData.end()) {
std::cout << endItr->first.hash << " " << endItr->first.v << " ends " << endItr->second.size() << " edges" << std::endl;
++endItr;
}
#endif

// keep track of vertices to add to each polygon, after we're done we'll iterate over this to actually insert them
std::unordered_map<Polygon*, std::vector<std::pair<Vector3,Vector3> > > verticesToInsert;
Expand Down
2 changes: 1 addition & 1 deletion src/csgjs/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
typedef double csgjs_real;

//#define CSGJS_DEBUG
const csgjs_real EPS = .00000001;
const csgjs_real EPS = .00001;
const csgjs_real NEG_EPS = -EPS;
const csgjs_real EPS_SQUARED = EPS*EPS;

Expand Down
50 changes: 27 additions & 23 deletions src/csgjs/math/HashKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ namespace csgjs {
}
}

long int x = (int)(std::round(line.direction.x/(EPS)));
long int y = (int)(std::round(line.direction.y/(EPS)));
long int z = (int)(std::round(line.direction.z/(EPS)));

long int x2 = (int)(std::round(line.point.x/(EPS)));
long int y2 = (int)(std::round(line.point.y/(EPS)));
long int z2 = (int)(std::round(line.point.z/(EPS)));

hash = (((std::hash<long int>()(x) ^ (std::hash<long int>()(y) << 1)) >> 1) ^ (std::hash<long int>()(z) << 1)) ^
(((std::hash<long int>()(x2) ^ (std::hash<long int>()(y2) << 1)) >> 1) ^ (std::hash<long int>()(z2) << 1));

long int x = (long int)(std::round(line.direction.x/(10*EPS)));
long int y = (long int)(std::round(line.direction.y/(10*EPS)));
long int z = (long int)(std::round(line.direction.z/(10*EPS)));

long int x2 = (long int)(std::round(line.point.x/(10*EPS)));
long int y2 = (long int)(std::round(line.point.y/(10*EPS)));
long int z2 = (long int)(std::round(line.point.z/(10*EPS)));

// hash = (((std::hash<long int>()(x) ^ (std::hash<long int>()(y) << 1)) >> 1) ^ (std::hash<long int>()(z) << 1)) ^
// (((std::hash<long int>()(x2) ^ (std::hash<long int>()(y2) << 1)) >> 1) ^ (std::hash<long int>()(z2) << 1));
hash = (std::hash<long int>()(x) ^ std::hash<long int>()(y) ^ std::hash<long int>()(z)) ^
(std::hash<long int>()(x2) ^ std::hash<long int>()(y2) ^ std::hash<long int>()(z2));
}

bool LineKey::operator==(const LineKey &l) const {
Expand All @@ -56,16 +57,18 @@ namespace csgjs {
first = a;
second = b;

long int x = (int)(std::round(first.x/(EPS)));
long int y = (int)(std::round(first.y/(EPS)));
long int z = (int)(std::round(first.z/(EPS)));
long int x = (long int)(std::round(first.x/(10*EPS)));
long int y = (long int)(std::round(first.y/(10*EPS)));
long int z = (long int)(std::round(first.z/(10*EPS)));

long int x2 = (int)(std::round(second.x/(EPS)));
long int y2 = (int)(std::round(second.y/(EPS)));
long int z2 = (int)(std::round(second.z/(EPS)));
long int x2 = (long int)(std::round(second.x/(10*EPS)));
long int y2 = (long int)(std::round(second.y/(10*EPS)));
long int z2 = (long int)(std::round(second.z/(10*EPS)));

hash = (((std::hash<long int>()(x) ^ (std::hash<long int>()(y) << 1)) >> 1) ^ (std::hash<long int>()(z) << 1)) ^
(((std::hash<long int>()(x2) ^ (std::hash<long int>()(y2) << 1)) >> 1) ^ (std::hash<long int>()(z2) << 1));
// hash = (((std::hash<long int>()(x) ^ (std::hash<long int>()(y) << 1)) >> 1) ^ (std::hash<long int>()(z) << 1)) ^
// (((std::hash<long int>()(x2) ^ (std::hash<long int>()(y2) << 1)) >> 1) ^ (std::hash<long int>()(z2) << 1));
hash = (std::hash<long int>()(x) ^ std::hash<long int>()(y) ^ std::hash<long int>()(z)) ^
(std::hash<long int>()(x2) ^ std::hash<long int>()(y2) ^ std::hash<long int>()(z2));
}

EdgeKey EdgeKey::reversed() const {
Expand All @@ -77,11 +80,12 @@ namespace csgjs {
}

VertexKey::VertexKey(const Vector3 &a) : v(a) {
long int x = (int)(std::round(v.x/(EPS)));
long int y = (int)(std::round(v.y/(EPS)));
long int z = (int)(std::round(v.z/(EPS)));
long int x = (long int)(std::round(v.x/(10*EPS)));
long int y = (long int)(std::round(v.y/(10*EPS)));
long int z = (long int)(std::round(v.z/(10*EPS)));

hash = (((std::hash<long int>()(x) ^ (std::hash<long int>()(y) << 1)) >> 1) ^ (std::hash<long int>()(z) << 1));
// hash = (((std::hash<long int>()(x) ^ (std::hash<long int>()(y) << 1)) >> 1) ^ (std::hash<long int>()(z) << 1));
hash = (std::hash<long int>()(x) ^ std::hash<long int>()(y) ^ std::hash<long int>()(z));
}

bool VertexKey::operator==(const VertexKey &a) const {
Expand Down

0 comments on commit d854d84

Please sign in to comment.