Skip to content

Commit

Permalink
Revise edge & vector compare function for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Jan 14, 2017
1 parent 70f0a3c commit 2fef05c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
31 changes: 15 additions & 16 deletions src/Mod/TechDraw/App/DrawProjectSplit.cpp
Expand Up @@ -421,7 +421,7 @@ std::vector<TopoDS_Edge> DrawProjectSplit::removeDuplicateEdges(std::vector<Topo
item.startAngle = DrawUtil::angleWithX(e,v1);
item.endAngle = DrawUtil::angleWithX(e,v2);
//catch reverse-duplicates
if (DrawUtil::vectorCompare(item.start,item.end) > 0) {
if (DrawUtil::vectorLess(item.end,item.start)) {
Base::Vector3d vTemp = item.start;
item.start = item.end;
item.end = vTemp;
Expand Down Expand Up @@ -453,7 +453,7 @@ std::vector<TopoDS_Edge> DrawProjectSplit::removeDuplicateEdges(std::vector<Topo
std::vector<edgeSortItem> DrawProjectSplit::sortEdges(std::vector<edgeSortItem>& e, bool ascend)
{
std::vector<edgeSortItem> sorted = e;
std::sort(sorted.begin(), sorted.end(), edgeSortItem::edgeCompare);
std::sort(sorted.begin(), sorted.end(), edgeSortItem::edgeLess);
if (ascend) {
std::reverse(sorted.begin(),sorted.end());
}
Expand All @@ -476,24 +476,23 @@ std::string edgeSortItem::dump(void)


//true if "e1 < e2" - for sorting
/*static*/bool edgeSortItem::edgeCompare(const edgeSortItem& e1, const edgeSortItem& e2)
/*static*/bool edgeSortItem::edgeLess(const edgeSortItem& e1, const edgeSortItem& e2)
{
bool result = false;
int vCompare = DrawUtil::vectorCompare(e1.start, e2.start);
if ( vCompare == -1) {
result = true;
} else if (vCompare == 0) {
if (e1.start != e2.start) {
if ( DrawUtil::vectorLess(e1.start, e2.start)) {
result = true;
}
} else if (!DrawUtil::fpCompare(e1.startAngle, e2.startAngle)) {
if (e1.startAngle < e2.startAngle) {
result = true;
} else if (DrawUtil::fpCompare(e1.startAngle, e2.startAngle)) {
if (e1.endAngle < e2.startAngle) {
result = true;
} else if (DrawUtil::fpCompare(e1.endAngle, e2.endAngle)) {
if (e1.idx < e2.idx) {
result = true;
}
}
result = true;
}
} else if (!DrawUtil::fpCompare(e1.endAngle, e2.endAngle)) {
if (e1.endAngle < e2.startAngle) {
result = true;
}
} else if (e1.idx < e2.idx) {
result = true;
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/App/DrawProjectSplit.h
Expand Up @@ -68,7 +68,7 @@ class edgeSortItem
double endAngle;
unsigned int idx;

static bool edgeCompare(const edgeSortItem& e1, const edgeSortItem& e2);
static bool edgeLess(const edgeSortItem& e1, const edgeSortItem& e2);
static bool edgeEqual(const edgeSortItem& e1, const edgeSortItem& e2);
std::string dump(void);
};
Expand Down
33 changes: 11 additions & 22 deletions src/Mod/TechDraw/App/DrawUtil.cpp
Expand Up @@ -277,33 +277,22 @@ std::string DrawUtil::formatVector(const Base::Vector3d& v)
return result;
}

//! compare 2 vectors for sorting purposes ( -1 -> v1<v2, 0 -> v1 == v2, 1 -> v1 > v2)
int DrawUtil::vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2)
//! compare 2 vectors for sorting - true if v1 < v2
bool DrawUtil::vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2)
{
int result = 0;
if (v1 == v2) {
return result;
}

if (v1.x < v2.x) {
result = -1;
} else if (DrawUtil::fpCompare(v1.x, v2.x)) {
if (v1.y < v2.y) {
result = -1;
} else if (DrawUtil::fpCompare(v1.y, v2.y)) {
if (v1.z < v2.z) {
result = -1;
} else {
result = 1;
}
bool result = false;
if (v1 != v2) {
if (!DrawUtil::fpCompare(v1.x,v2.x)) {
result = v1.x < v2.x;
} else if (!DrawUtil::fpCompare(v1.y,v2.y)) {
result = v1.y < v2.y;
} else {
result = 1; //v2y > v1y
result = v1.z < v2.z;
}
} else {
result = 1; //v1x > v2x
}
return result;
}
}


//!convert fromPoint in coordinate system fromSystem to reference coordinate system
Base::Vector3d DrawUtil::toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint)
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/App/DrawUtil.h
Expand Up @@ -59,7 +59,7 @@ class TechDrawExport DrawUtil {
static bool fpCompare(const double& d1, const double& d2);
static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v);
static std::string formatVector(const Base::Vector3d& v);
static int vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2);
static bool vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2);
static Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint);
static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2);
//! rotate vector by angle radians around axis through org
Expand Down

0 comments on commit 2fef05c

Please sign in to comment.