Commit 33f3aca6 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Maciej Suminski

geometry: IsSolid() and Move() methods, segment overlap detection, some...

geometry: IsSolid() and Move() methods, segment overlap detection, some improvements in SHAPE_LINE_CHAIN class.
parent 4e280f06
...@@ -29,16 +29,15 @@ using boost::optional; ...@@ -29,16 +29,15 @@ using boost::optional;
bool SHAPE_LINE_CHAIN::Collide( const VECTOR2I& aP, int aClearance ) const bool SHAPE_LINE_CHAIN::Collide( const VECTOR2I& aP, int aClearance ) const
{ {
assert( false ); // fixme: ugly!
SEG s(aP, aP);
return false; return this->Collide(s, aClearance);
} }
bool SHAPE_LINE_CHAIN::Collide( const BOX2I& aBox, int aClearance ) const bool SHAPE_LINE_CHAIN::Collide( const BOX2I& aBox, int aClearance ) const
{ {
assert( false ); assert( false );
return false; return false;
} }
......
...@@ -215,14 +215,34 @@ public: ...@@ -215,14 +215,34 @@ public:
*/ */
bool Collinear( const SEG& aSeg ) const bool Collinear( const SEG& aSeg ) const
{ {
ecoord qa1 = A.y - B.y; ecoord qa = A.y - B.y;
ecoord qb1 = B.x - A.x; ecoord qb = B.x - A.x;
ecoord qc1 = -qa1 * A.x - qb1 * A.y; ecoord qc = -qa * A.x - qb * A.y;
ecoord qa2 = aSeg.A.y - aSeg.B.y;
ecoord qb2 = aSeg.B.x - aSeg.A.x; ecoord d1 = std::abs( aSeg.A.x * qa + aSeg.A.y * qb + qc );
ecoord qc2 = -qa2 * aSeg.A.x - qb2 * aSeg.A.y; ecoord d2 = std::abs( aSeg.B.x * qa + aSeg.B.y * qb + qc );
return ( qa1 == qa2 ) && ( qb1 == qb2 ) && ( qc1 == qc2 ); return ( d1 <= 1 && d2 <= 1 );
}
bool Overlaps ( const SEG& aSeg ) const
{
if( aSeg.A == aSeg.B ) // single point corner case
{
if(A == aSeg.A || B == aSeg.A)
return false;
return Contains(aSeg.A);
}
if( !Collinear (aSeg ))
return false;
if ( Contains (aSeg.A) || Contains(aSeg.B) )
return true;
if ( aSeg.Contains (A) || aSeg.Contains(B) )
return true;
return false;
} }
/** /**
......
...@@ -40,7 +40,10 @@ enum SHAPE_TYPE ...@@ -40,7 +40,10 @@ enum SHAPE_TYPE
SH_RECT = 0, ///> axis-aligned rectangle SH_RECT = 0, ///> axis-aligned rectangle
SH_SEGMENT, ///> line segment SH_SEGMENT, ///> line segment
SH_LINE_CHAIN, ///> line chain (polyline) SH_LINE_CHAIN, ///> line chain (polyline)
SH_CIRCLE ///> circle SH_CIRCLE, ///> circle
SH_CONVEX, ///> convex polygon
SH_POLYGON, ///> any polygon (with holes, etc.)
SH_COMPOUND ///> compound shape, consisting of multiple simple shapes
}; };
/** /**
...@@ -146,7 +149,11 @@ public: ...@@ -146,7 +149,11 @@ public:
return BBox( 0 ).Centre(); // if nothing better is available.... return BBox( 0 ).Centre(); // if nothing better is available....
} }
private: virtual void Move ( const VECTOR2I& aVector ) = 0;
virtual bool IsSolid() const = 0;
protected:
///> type of our shape ///> type of our shape
SHAPE_TYPE m_type; SHAPE_TYPE m_type;
}; };
......
...@@ -86,6 +86,15 @@ public: ...@@ -86,6 +86,15 @@ public:
return m_center; return m_center;
} }
void Move ( const VECTOR2I& aVector )
{
m_center += aVector;
}
bool IsSolid() const
{
return true;
}
private: private:
int m_radius; int m_radius;
VECTOR2I m_center; VECTOR2I m_center;
......
...@@ -103,6 +103,17 @@ public: ...@@ -103,6 +103,17 @@ public:
m_points[2] = aC; m_points[2] = aC;
} }
SHAPE_LINE_CHAIN( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC, const VECTOR2I& aD ) :
SHAPE( SH_LINE_CHAIN ), m_closed( false )
{
m_points.resize( 4 );
m_points[0] = aA;
m_points[1] = aB;
m_points[2] = aC;
m_points[3] = aD;
}
SHAPE_LINE_CHAIN(const VECTOR2I* aV, int aCount ) : SHAPE_LINE_CHAIN(const VECTOR2I* aV, int aCount ) :
SHAPE( SH_LINE_CHAIN ), SHAPE( SH_LINE_CHAIN ),
m_closed( false ) m_closed( false )
...@@ -553,6 +564,16 @@ public: ...@@ -553,6 +564,16 @@ public:
bool CompareGeometry( const SHAPE_LINE_CHAIN & aOther ) const; bool CompareGeometry( const SHAPE_LINE_CHAIN & aOther ) const;
void Move ( const VECTOR2I& aVector )
{
for(std::vector<VECTOR2I>::iterator i = m_points.begin(); i != m_points.end(); ++i)
(*i) += aVector;
}
bool IsSolid() const
{
return false;
}
private: private:
/// array of vertices /// array of vertices
std::vector<VECTOR2I> m_points; std::vector<VECTOR2I> m_points;
......
...@@ -159,6 +159,16 @@ public: ...@@ -159,6 +159,16 @@ public:
return m_h; return m_h;
} }
void Move ( const VECTOR2I& aVector )
{
m_p0 += aVector;
}
bool IsSolid() const
{
return true;
}
private: private:
///> Top-left corner ///> Top-left corner
VECTOR2I m_p0; VECTOR2I m_p0;
......
...@@ -82,6 +82,17 @@ public: ...@@ -82,6 +82,17 @@ public:
return m_width; return m_width;
} }
bool IsSolid() const
{
return true;
}
void Move ( const VECTOR2I& aVector )
{
m_seg.A += aVector;
m_seg.B += aVector;
}
private: private:
SEG m_seg; SEG m_seg;
int m_width; int m_width;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment