Revise edge & vector compare function for clarity
This commit is contained in:
parent
70f0a3c056
commit
2fef05c718
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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.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;
|
||||
}
|
||||
}
|
||||
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.endAngle, e2.endAngle)) {
|
||||
if (e1.endAngle < e2.startAngle) {
|
||||
result = true;
|
||||
}
|
||||
} else if (e1.idx < e2.idx) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
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);
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user