X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FOpenGl%2FOpenGl_BVHClipPrimitiveSet.cxx;h=a21840f98f86a37609e46f73532d2aab60cc9705;hp=e105ab3733a4667061d70edcde37987c23896d38;hb=41e08b4df852620444707084f3bf33fce92bcf25;hpb=385c43e7ea176f3e42e186147b293d523dea1baf diff --git a/src/OpenGl/OpenGl_BVHClipPrimitiveSet.cxx b/src/OpenGl/OpenGl_BVHClipPrimitiveSet.cxx index e105ab3733..a21840f98f 100644 --- a/src/OpenGl/OpenGl_BVHClipPrimitiveSet.cxx +++ b/src/OpenGl/OpenGl_BVHClipPrimitiveSet.cxx @@ -16,6 +16,7 @@ #include #include +#include // ======================================================================= // function : OpenGl_BVHClipPrimitiveSet @@ -53,8 +54,17 @@ Standard_ShortReal OpenGl_BVHClipPrimitiveSet::Center (const Standard_Integer th { Graphic3d_BndBox4f aBndBox = myStructs.FindKey (theIdx + 1)->BoundingBox(); - return (aBndBox.CornerMin()[theAxis] + - aBndBox.CornerMax()[theAxis]) * 0.5f; + // to prevent float overflow + const Standard_Real aMin = Standard_Real (aBndBox.CornerMin()[theAxis]); + const Standard_Real aMax = Standard_Real (aBndBox.CornerMax()[theAxis]); + const Standard_Real aCenter = (aMin + aMax) * 0.5; + + if (aCenter <= Standard_Real (-ShortRealLast())) + return -ShortRealLast(); + if (aCenter >= Standard_Real (ShortRealLast())) + return ShortRealLast(); + + return Standard_ShortReal (aCenter); } // ======================================================================= @@ -67,49 +77,29 @@ void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1, myStructs.Swap (theIdx1 + 1, theIdx2 + 1); } -// ======================================================================= -// function : Assign -// purpose : -// ======================================================================= -void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfStructure& theStructs) -{ - myStructs.Clear(); - - for (Standard_Integer aPriorityIdx = 0, aNbPriorities = theStructs.Length(); aPriorityIdx < aNbPriorities; ++aPriorityIdx) - { - for (OpenGl_SequenceOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next()) - { - const OpenGl_Structure* aStruct = aStructIter.Value(); - - if (!aStruct->IsAlwaysRendered()) - { - myStructs.Add (aStruct); - } - } - } - - MarkDirty(); -} - // ======================================================================= // function : Add // purpose : // ======================================================================= -void OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct) +Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct) { const Standard_Integer aSize = myStructs.Size(); if (myStructs.Add (theStruct) > aSize) // new structure? { MarkDirty(); + + return Standard_True; } + + return Standard_False; } // ======================================================================= // function : Remove // purpose : // ======================================================================= -void OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct) +Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct) { const Standard_Integer anIndex = myStructs.FindIndex (theStruct); @@ -118,7 +108,11 @@ void OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct) myStructs.Swap (Size(), anIndex); myStructs.RemoveLast(); MarkDirty(); + + return Standard_True; } + + return Standard_False; } // =======================================================================