diff OrthancStone/Sources/Toolbox/UnionOfRectangles.cpp @ 1876:b1f510e601d2

more unit tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 21:26:47 +0100
parents b896f20d24ca
children c9ccd13c6a3c
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/UnionOfRectangles.cpp	Tue Jan 11 19:59:40 2022 +0100
+++ b/OrthancStone/Sources/Toolbox/UnionOfRectangles.cpp	Tue Jan 11 21:26:47 2022 +0100
@@ -84,7 +84,7 @@
   class UnionOfRectangles::Factory : public SegmentTree::IPayloadFactory
   {
   public:
-    virtual Orthanc::IDynamicObject* Create()
+    virtual Orthanc::IDynamicObject* Create() ORTHANC_OVERRIDE
     {
       return new Payload;
     }
@@ -103,7 +103,7 @@
     }
   
     virtual void Visit(const SegmentTree& node,
-                       bool fullyInside)
+                       bool fullyInside) ORTHANC_OVERRIDE
     {
       Payload& payload = node.GetTypedPayload<Payload>();
 
@@ -384,6 +384,8 @@
   void UnionOfRectangles::Apply(std::list< std::vector<ScenePoint2D> >& contours,
                                 const std::list<Extent2D>& rectangles)
   {
+    contours.clear();
+
     /**
      * STEP 1
      **/
@@ -392,10 +394,14 @@
 
     assert(horizontalProjection.GetProjectedRectanglesCount() == verticalProjection.GetProjectedRectanglesCount());
 
-    
     /**
      * STEP 2
      **/
+    if (verticalProjection.GetEndpointsCount() == 0)
+    {
+      return;
+    }
+    
     Factory factory;
     SegmentTree tree(0, verticalProjection.GetEndpointsCount() - 1, factory);
 
@@ -528,8 +534,6 @@
     std::list<Internals::OrientedIntegerLine2D::Chain> chains;
     Internals::OrientedIntegerLine2D::ExtractChains(chains, allEdges);
 
-    contours.clear();
-
     for (std::list<Internals::OrientedIntegerLine2D::Chain>::const_iterator
            it = chains.begin(); it != chains.end(); ++it)
     {