0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / OpenGl / OpenGl_BVHClipPrimitiveSet.cxx
index 5ed3007..a21840f 100644 (file)
@@ -16,6 +16,7 @@
 #include <OpenGl_BVHClipPrimitiveSet.hxx>
 
 #include <BVH_BinnedBuilder.hxx>
+#include <Graphic3d_GraphicDriver.hxx>
 
 // =======================================================================
 // 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_ArrayOfIndexedMapOfStructure& theStructs)
-{
-  myStructs.Clear();
-
-  for (Standard_Integer aPriorityIdx = 0, aNbPriorities = theStructs.Length(); aPriorityIdx < aNbPriorities; ++aPriorityIdx)
-  {
-    for (OpenGl_IndexedMapOfStructure::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;
 }
 
 // =======================================================================