libs/kimath: implement indexable subshape support for SHAPE_COMPOUND and SHAPE_POLY_SET
This commit is contained in:
parent
a01e4f19b4
commit
482767a850
|
@ -26,6 +26,7 @@
|
||||||
#define __SHAPE_H
|
#define __SHAPE_H
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
#include <geometry/seg.h>
|
#include <geometry/seg.h>
|
||||||
#include <math/vector2d.h>
|
#include <math/vector2d.h>
|
||||||
#include <math/box2.h>
|
#include <math/box2.h>
|
||||||
|
@ -70,6 +71,7 @@ static inline wxString SHAPE_TYPE_asString( SHAPE_TYPE a )
|
||||||
return wxEmptyString; // Just to quiet GCC.
|
return wxEmptyString; // Just to quiet GCC.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SHAPE;
|
||||||
|
|
||||||
class SHAPE_BASE
|
class SHAPE_BASE
|
||||||
{
|
{
|
||||||
|
@ -103,9 +105,9 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t GetIndexableSubshapeCount() { return 0; }
|
virtual size_t GetIndexableSubshapeCount() const { return 0; }
|
||||||
|
|
||||||
virtual void GetIndexableSubshape( SHAPE_BASE& aSubshape ) const {};
|
virtual void GetIndexableSubshapes( std::vector<SHAPE*>& aSubshapes ) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///> type of our shape
|
///> type of our shape
|
||||||
|
|
|
@ -96,6 +96,21 @@ class SHAPE_COMPOUND : public SHAPE
|
||||||
return m_shapes.size() != 1 ? nullptr : m_shapes[0];
|
return m_shapes.size() != 1 ? nullptr : m_shapes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool HasIndexableSubshapes() const override
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual size_t GetIndexableSubshapeCount() const override
|
||||||
|
{
|
||||||
|
return m_shapes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void GetIndexableSubshapes( std::vector<SHAPE*>& aSubshapes ) override
|
||||||
|
{
|
||||||
|
aSubshapes = m_shapes;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
BOX2I m_cachedBBox;
|
BOX2I m_cachedBBox;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <deque> // for deque
|
#include <deque> // for deque
|
||||||
|
#include <vector> // for vector
|
||||||
#include <iosfwd> // for string, stringstream
|
#include <iosfwd> // for string, stringstream
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set> // for set
|
#include <set> // for set
|
||||||
|
@ -165,6 +166,11 @@ class SHAPE_POLY_SET : public SHAPE
|
||||||
return m_triangles.size();
|
return m_triangles.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::deque<TRI>& Triangles()
|
||||||
|
{
|
||||||
|
return m_triangles;
|
||||||
|
}
|
||||||
|
|
||||||
size_t GetVertexCount() const
|
size_t GetVertexCount() const
|
||||||
{
|
{
|
||||||
return m_vertices.size();
|
return m_vertices.size();
|
||||||
|
@ -1370,6 +1376,12 @@ class SHAPE_POLY_SET : public SHAPE
|
||||||
|
|
||||||
MD5_HASH GetHash() const;
|
MD5_HASH GetHash() const;
|
||||||
|
|
||||||
|
virtual bool HasIndexableSubshapes() const override;
|
||||||
|
|
||||||
|
virtual size_t GetIndexableSubshapeCount() const override;
|
||||||
|
|
||||||
|
virtual void GetIndexableSubshapes( std::vector<SHAPE*>& aSubshapes ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
MD5_HASH checksum() const;
|
MD5_HASH checksum() const;
|
||||||
|
|
|
@ -2090,3 +2090,31 @@ bool SHAPE_POLY_SET::hasTouchingHoles( const POLYGON& aPoly ) const
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHAPE_POLY_SET::HasIndexableSubshapes() const
|
||||||
|
{
|
||||||
|
return IsTriangulationUpToDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SHAPE_POLY_SET::GetIndexableSubshapeCount() const
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
for( auto& t : m_triangulatedPolys )
|
||||||
|
n += t->GetTriangleCount();
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHAPE_POLY_SET:: GetIndexableSubshapes( std::vector<SHAPE*>& aSubshapes )
|
||||||
|
{
|
||||||
|
aSubshapes.reserve( GetIndexableSubshapeCount() );
|
||||||
|
|
||||||
|
for( auto& tpoly : m_triangulatedPolys )
|
||||||
|
{
|
||||||
|
for ( auto& tri : tpoly->Triangles() )
|
||||||
|
{
|
||||||
|
SHAPE *s = static_cast<SHAPE*> ( &tri );
|
||||||
|
aSubshapes.push_back( &tri );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue