[TD]fix pathological centerline for points
This commit is contained in:
@@ -159,7 +159,7 @@ CenterLine* CenterLine::CenterLineBuilder(DrawViewPart* partFeat,
|
||||
int mode,
|
||||
bool flip)
|
||||
{
|
||||
// Base::Console().Message("CL::CLBuilder()\n - subNames: %d", subNames.size());
|
||||
// Base::Console().Message("CL::CLBuilder()\n - subNames: %d\n", subNames.size());
|
||||
std::pair<Base::Vector3d, Base::Vector3d> ends;
|
||||
std::vector<std::string> faces;
|
||||
std::vector<std::string> edges;
|
||||
@@ -405,7 +405,6 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints(DrawViewPart
|
||||
|
||||
if (faceBox.IsVoid()) {
|
||||
Base::Console().Error("CL::calcEndPoints - faceBox is void!\n");
|
||||
// return result;
|
||||
throw Base::IndexError("CenterLine wrong number of faces.");
|
||||
}
|
||||
|
||||
@@ -527,7 +526,6 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
|
||||
// if the proposed end points prevent the creation of a vertical or horizontal centerline, we need
|
||||
// to prevent the "orientation" code below from creating identical endpoints. This would create a
|
||||
// zero length edge and cause problems later.
|
||||
// this should probably be prevented in the creation task?
|
||||
bool inhibitVertical = false;
|
||||
bool inhibitHorizontal = false;
|
||||
if (DU::fpCompare(p1.y, p2.y, EWTOLERANCE)) {
|
||||
@@ -586,7 +584,7 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
|
||||
double rotate, bool flip)
|
||||
|
||||
{
|
||||
// Base::Console().Message("CL::calc2Points()\n");
|
||||
// Base::Console().Message("CL::calc2Points() - mode: %d\n", mode);
|
||||
if (vertNames.empty()) {
|
||||
Base::Console().Warning("CL::calcEndPoints2Points - no points!\n");
|
||||
return std::pair<Base::Vector3d, Base::Vector3d>();
|
||||
@@ -606,17 +604,41 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
|
||||
}
|
||||
}
|
||||
if (points.size() != 2) {
|
||||
//this should fail harder. maybe be in a try/catch.
|
||||
// Base::Console().Message("CL::calcEndPoints2Points - wrong number of points!\n");
|
||||
// return result;
|
||||
throw Base::IndexError("CenterLine wrong number of points.");
|
||||
}
|
||||
|
||||
Base::Vector3d v1 = points.front()->point();
|
||||
Base::Vector3d v2 = points.back()->point();
|
||||
|
||||
Base::Vector3d mid = (v1 + v2) / 2.0;
|
||||
Base::Vector3d dir = v2 - v1;
|
||||
|
||||
// if the proposed end points prevent the creation of a vertical or horizontal centerline, we need
|
||||
// to prevent the "orientation" code below from creating identical endpoints. This would create a
|
||||
// zero length edge and cause problems later.
|
||||
|
||||
bool inhibitVertical = false;
|
||||
bool inhibitHorizontal = false;
|
||||
if (DU::fpCompare(v1.y, v2.y, EWTOLERANCE)) {
|
||||
// proposed end points are aligned horizontally, can not draw horizontal CL
|
||||
inhibitHorizontal = true;
|
||||
}
|
||||
if (DU::fpCompare(v1.x, v2.x, EWTOLERANCE)) {
|
||||
// proposed end points are aligned vertically, can not draw vertical CL
|
||||
inhibitVertical = true;
|
||||
}
|
||||
|
||||
if (mode == 0 && !inhibitVertical) {
|
||||
//Vertical
|
||||
v1.x = mid.x;
|
||||
v2.x = mid.x;
|
||||
} else if (mode == 1 && !inhibitHorizontal) {
|
||||
//Horizontal
|
||||
v1.y = mid.y;
|
||||
v2.y = mid.y;
|
||||
} else if (mode == 2) { //Aligned
|
||||
// no op
|
||||
}
|
||||
|
||||
double length = dir.Length();
|
||||
dir.Normalize();
|
||||
Base::Vector3d clDir(dir.y, -dir.x, dir.z);
|
||||
@@ -630,17 +652,6 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
|
||||
p2 = temp;
|
||||
}
|
||||
|
||||
if (mode == 0) { //Vertical
|
||||
p1.x = mid.x;
|
||||
p2.x = mid.x;
|
||||
} else if (mode == 1) { //Horizontal
|
||||
p1.y = mid.y;
|
||||
p2.y = mid.y;
|
||||
} else if (mode == 2) { //Aligned
|
||||
// no op
|
||||
}
|
||||
|
||||
|
||||
//extend
|
||||
p1 = p1 + (clDir * ext);
|
||||
p2 = p2 - (clDir * ext);
|
||||
|
||||
Reference in New Issue
Block a user