[TD]fix 4335 section line pos on rotated base

This commit is contained in:
wandererfan
2020-06-13 14:55:29 -04:00
committed by WandererFan
parent 8a9ea0caeb
commit b7a448dadc
5 changed files with 45 additions and 23 deletions

View File

@@ -296,36 +296,41 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawUtil::boxIntersect2d(Base::Vector3
dir.Normalize();
// y = mx + b
// m = (y1 - y0) / (x1 - x0)
if (DrawUtil::fpCompare(dir.x, 0.0) ) {
if (DrawUtil::fpCompare(dir.x, 0.0) ) { //vertical case
p1 = Base::Vector3d(point.x, - yRange / 2.0, 0.0);
p2 = Base::Vector3d(point.x, yRange / 2.0, 0.0);
} else {
double slope = dir.y / dir.x;
double left = -xRange / 2.0;
double right = xRange / 2.0;
double top = yRange / 2.0;
double bottom = -yRange / 2.0;
double yLeft = point.y - slope * (point.x - left) ;
double yRight = point.y - slope * (point.x - right);
double xTop = point.x - ( (point.y - top) / slope );
double xBottom = point.x - ( (point.y - bottom) / slope );
if (DrawUtil::fpCompare(slope, 0.0)) { //horizontal case
p1 = Base::Vector3d(left, point.y);
p2 = Base::Vector3d(right, point.y);
} else { //normal case
double top = yRange / 2.0;
double bottom = -yRange / 2.0;
double yLeft = point.y - slope * (point.x - left) ;
double yRight = point.y - slope * (point.x - right);
double xTop = point.x - ( (point.y - top) / slope );
double xBottom = point.x - ( (point.y - bottom) / slope );
if ( (bottom < yLeft) &&
(top > yLeft) ) {
p1 = Base::Vector3d(left, yLeft);
} else if (yLeft <= bottom) {
p1 = Base::Vector3d(xBottom, bottom);
} else if (yLeft >= top) {
p1 = Base::Vector3d(xTop, top);
}
if ( (bottom < yLeft) &&
(top > yLeft) ) {
p1 = Base::Vector3d(left, yLeft);
} else if (yLeft <= bottom) {
p1 = Base::Vector3d(xBottom, bottom);
} else if (yLeft >= top) {
p1 = Base::Vector3d(xTop, top);
}
if ( (bottom < yRight) &&
(top > yRight) ) {
p2 = Base::Vector3d(right, yRight);
} else if (yRight <= bottom) {
p2 = Base::Vector3d(xBottom, bottom);
} else if (yRight >= top) {
p2 = Base::Vector3d(xTop, top);
if ( (bottom < yRight) &&
(top > yRight) ) {
p2 = Base::Vector3d(right, yRight);
} else if (yRight <= bottom) {
p2 = Base::Vector3d(xBottom, bottom);
} else if (yRight >= top) {
p2 = Base::Vector3d(xTop, top);
}
}
}
result.first = p1;

View File

@@ -585,6 +585,11 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds(void)
{
std::pair<Base::Vector3d, Base::Vector3d> result;
Base::Vector3d stdZ(0.0, 0.0, 1.0);
double baseRotation = getBaseDVP()->Rotation.getValue(); //Qt degrees
Base::Rotation rotator(stdZ, baseRotation * M_PI / 180.0);
Base::Rotation unrotator(stdZ, - baseRotation * M_PI / 180.0);
auto sNorm = SectionNormal.getValue();
double angle = M_PI / 2.0;
auto axis = getBaseDVP()->Direction.getValue();
@@ -605,7 +610,12 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds(void)
xRange /= getBaseDVP()->getScale();
double yRange = bbx.MaxY - bbx.MinY;
yRange /= getBaseDVP()->getScale();
sOrgOnBase = rotator.multVec(sOrgOnBase);
sLineOnBase = rotator.multVec(sLineOnBase);
result = DrawUtil::boxIntersect2d(sOrgOnBase, sLineOnBase, xRange, yRange); //unscaled
result.first = unrotator.multVec(result.first);
result.second = unrotator.multVec(result.second);
return result;
}