Sketcher: Fix dimension extension overshoot length

This commit is contained in:
Kacper Donat
2025-08-13 00:59:47 +02:00
committed by Benjamin Nauck
parent 4195f7fee2
commit 5fabb1372d
2 changed files with 14 additions and 15 deletions

View File

@@ -286,7 +286,7 @@ private:
}
// use the shared geometry calculation for consistency
SoDatumLabel::DistanceGeometry geom = label->calculateDistanceGeometry(points, scale, srch);
SoDatumLabel::DistanceGeometry geom = label->calculateDistanceGeometry(points);
std::vector<SbVec3f> corners;
float margin = imgHeight / 4.0F;
@@ -682,9 +682,8 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe
void SoDatumLabel::generateDistancePrimitives(SoAction * action, const SbVec3f& p1, const SbVec3f& p2)
{
SbVec3f points[2] = {p1, p2};
float scale = 1.0f;
int srch = 1;
DistanceGeometry geom = calculateDistanceGeometry(points, scale, srch);
DistanceGeometry geom = calculateDistanceGeometry(points);
// generate selectable primitive for txt label
SbVec3f img1 = SbVec3f(-this->imgWidth / 2, -this->imgHeight / 2, 0.F);
@@ -1147,7 +1146,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
if (this->datumtype.getValue() == DISTANCE ||
this->datumtype.getValue() == DISTANCEX ||
this->datumtype.getValue() == DISTANCEY ) {
drawDistance(points, scale, srch, angle, textOffset);
drawDistance(points, angle, textOffset);
}
else if (this->datumtype.getValue() == RADIUS || this->datumtype.getValue() == DIAMETER) {
drawRadiusOrDiameter(points, angle, textOffset);
@@ -1199,9 +1198,9 @@ void SoDatumLabel::getDimension(float scale, int& srcw, int& srch)
this->imgWidth = aspectRatio * (float) this->imgHeight;
}
void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, float& angle, SbVec3f& textOffset)
void SoDatumLabel::drawDistance(const SbVec3f* points, float& angle, SbVec3f& textOffset)
{
SoDatumLabel::DistanceGeometry geom = this->calculateDistanceGeometry(points, scale, srch);
SoDatumLabel::DistanceGeometry geom = this->calculateDistanceGeometry(points);
angle = geom.angle;
textOffset = geom.textOffset;
@@ -1493,7 +1492,7 @@ void SoDatumLabel::setPoints(SbVec3f p1, SbVec3f p2)
}
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-pro-bounds-pointer-arithmetic)
SoDatumLabel::DistanceGeometry SoDatumLabel::calculateDistanceGeometry(const SbVec3f* points, float scale, int srch) const
SoDatumLabel::DistanceGeometry SoDatumLabel::calculateDistanceGeometry(const SbVec3f* points) const
{
using std::numbers::pi;
@@ -1525,9 +1524,6 @@ SoDatumLabel::DistanceGeometry SoDatumLabel::calculateDistanceGeometry(const SbV
geom.midpos = (p1_ + geom.p2) / 2;
float offset1 = ((length + normproj12 < 0) ? -1.F : 1.F) * srch;
float offset2 = ((length < 0) ? -1 : 1) * srch;
// Get magnitude of angle between horizontal
geom.angle = atan2f(geom.dir[1], geom.dir[0]);
if (geom.angle > pi/2 + pi/12) {
@@ -1540,8 +1536,11 @@ SoDatumLabel::DistanceGeometry SoDatumLabel::calculateDistanceGeometry(const SbV
geom.margin = this->imgHeight / 3.0F;
geom.perp1 = p1_ + geom.normal * (length + offset1 * scale);
geom.perp2 = geom.p2 + geom.normal * (length + offset2 * scale);
float offset1 = ((length + normproj12 < 0) ? -1.F : 1.F) * geom.margin;
float offset2 = ((length < 0) ? -1 : 1) * geom.margin;
geom.perp1 = p1_ + geom.normal * (length + offset1);
geom.perp2 = geom.p2 + geom.normal * (length + offset2);
// Calculate the coordinates for the parallel datum lines
geom.par1 = p1_ + geom.normal * length;

View File

@@ -188,7 +188,7 @@ private:
SbVec3f getLabelTextCenterArcLength(const SbVec3f&, const SbVec3f&, const SbVec3f&) const;
bool hasDatumText() const;
void getDimension(float scale, int& srcw, int& srch);
DistanceGeometry calculateDistanceGeometry(const SbVec3f* points, float scale, int srch) const;
DistanceGeometry calculateDistanceGeometry(const SbVec3f* points) const;
DiameterGeometry calculateDiameterGeometry(const SbVec3f* points) const;
AngleGeometry calculateAngleGeometry(const SbVec3f* points) const;
SymmetricGeometry calculateSymmetricGeometry(const SbVec3f* points) const;
@@ -196,7 +196,7 @@ private:
void generateLineSelectionPrimitive(SoAction* action, const SbVec3f& start, const SbVec3f& end, float width);
void generateArcSelectionPrimitive(SoAction* action, const SbVec3f& center, float radius, float startAngle, float endAngle, float width);
void generateArrowSelectionPrimitive(SoAction* action, const SbVec3f& base, const SbVec3f& dir, float width, float length);
void drawDistance(const SbVec3f* points, float scale, int srch, float& angle, SbVec3f& textOffset);
void drawDistance(const SbVec3f* points, float& angle, SbVec3f& textOffset);
void drawDistance(const SbVec3f* points);
void drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbVec3f& textOffset);
void drawAngle(const SbVec3f* points, float& angle, SbVec3f& textOffset);