From a730da5299cccb8606c5078eceed7f6f648a72bd Mon Sep 17 00:00:00 2001 From: "rick@ghostpunch.com" Date: Wed, 9 Aug 2017 04:23:39 -0400 Subject: [PATCH] Account for PloyLine stroke width when calculating the dimensions of the PolyLilne's bounding box. --- libraries/entities/src/PolyLineEntityItem.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 61d5dd22ee..90e0a18a3f 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -182,15 +182,27 @@ void PolyLineEntityItem::calculateScaleAndRegistrationPoint() { EntityItem::setRegistrationPoint(glm::vec3(0.0f, 0.0f, 0.0f)); return; } + + // Find the max width of the strokes so we can account for that in the size of the bounding box + float maxWidth = 0.0f; + for (int i = 0; i < _strokeWidths.size(); ++i) { + if (_strokeWidths.at(i) > maxWidth) { + maxWidth = _strokeWidths.at(i); + qCDebug(entities) << "TTTTT " << maxWidth; + } + } glm::vec3 result; - result.x = fabsf(high.x) + fabsf(low.x); - result.y = fabsf(high.y) + fabsf(low.y); - result.z = fabsf(high.z) + fabsf(low.z); + float halfLineWidth = (maxWidth > 0.0f) ? maxWidth * 0.5f : 0.0f; + result.x = fabsf(high.x) + fabsf(low.x) + halfLineWidth; + result.y = fabsf(high.y) + fabsf(low.y) + halfLineWidth; + result.z = fabsf(high.z) + fabsf(low.z) + halfLineWidth; SpatiallyNestable::setScale(result); + // Center the poly line in the bounding box glm::vec3 point = _points.at(0); glm::vec3 startPointInScaleSpace = point - low; + startPointInScaleSpace += glm::vec3(halfLineWidth * 0.5f); glm::vec3 newRegistrationPoint = startPointInScaleSpace / result; EntityItem::setRegistrationPoint(newRegistrationPoint); } else {