[TD]fix #9471 - prevent impossible centerline

This commit is contained in:
wandererfan
2023-05-06 19:50:05 -04:00
committed by WandererFan
parent bd3f71b478
commit 970fd86705
5 changed files with 103 additions and 57 deletions

View File

@@ -43,6 +43,7 @@
#include "CenterLinePy.h"
using namespace TechDraw;
using DU = DrawUtil;
TYPESYSTEM_SOURCE(TechDraw::CenterLine, Base::Persistence)
@@ -108,8 +109,22 @@ CenterLine::CenterLine(Base::Vector3d pt1,
double h,
double v,
double r,
double x) : CenterLine(BaseGeomPtrFromVectors(pt1, pt2), m, h, v, r, x)
double x)
{
m_start = pt1;
m_end = pt2;
m_mode = m;
m_hShift = h;
m_vShift = v;
m_rotate = r;
m_extendBy = x;
m_type = CLTYPE::FACE;
m_flip2Line = false;
m_geometry = BaseGeomPtrFromVectors(pt1, pt2);
initialize();
}
CenterLine::~CenterLine()
@@ -509,13 +524,28 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
Base::Vector3d p2 = (l1p2 + l2p2) / 2.0;
Base::Vector3d mid = (p1 + p2) / 2.0;
// 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)) {
// proposed end points are aligned vertically, so we can't draw a vertical line to connect them
inhibitVertical = true;
}
if (DU::fpCompare(p1.x, p2.x, EWTOLERANCE)) {
// proposed end points are aligned horizontally, so we can't draw a horizontal line to connect them
inhibitHorizontal = true;
}
//orientation
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;
if (mode == 0 && !inhibitVertical) { //Vertical
p1.x = mid.x;
p2.x = mid.x;
} else if (mode == 1 && !inhibitHorizontal) { //Horizontal
p1.y = mid.y;
p2.y = mid.y;
} else if (mode == 2) { //Aligned
// no op
}