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

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
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -29,16 +29,15 @@ using boost::optional;

bool SHAPE_LINE_CHAIN::Collide( const VECTOR2I& aP, int aClearance ) const
{
    assert( false );

    return false;
	// fixme: ugly!
    SEG s(aP, aP);
    return this->Collide(s, aClearance);
}


bool SHAPE_LINE_CHAIN::Collide( const BOX2I& aBox, int aClearance ) const
{
    assert( false );

    return false;
}

+28 −8
Original line number Diff line number Diff line
@@ -215,14 +215,34 @@ public:
     */
    bool Collinear( const SEG& aSeg ) const
    {
        ecoord qa1 = A.y - B.y;
        ecoord qb1 = B.x - A.x;
        ecoord qc1 = -qa1 * A.x - qb1 * A.y;
        ecoord qa2 = aSeg.A.y - aSeg.B.y;
        ecoord qb2 = aSeg.B.x - aSeg.A.x;
        ecoord qc2 = -qa2 * aSeg.A.x - qb2 * aSeg.A.y;

        return ( qa1 == qa2 ) && ( qb1 == qb2 ) && ( qc1 == qc2 );
        ecoord qa = A.y - B.y;
        ecoord qb = B.x - A.x;
        ecoord qc = -qa * A.x - qb * A.y;

        ecoord d1 = std::abs( aSeg.A.x * qa + aSeg.A.y * qb + qc );
        ecoord d2 = std::abs( aSeg.B.x * qa + aSeg.B.y * qb + qc );

        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;
    }

    /**
+9 −2
Original line number Diff line number Diff line
@@ -40,7 +40,10 @@ enum SHAPE_TYPE
    SH_RECT = 0,        ///> axis-aligned rectangle
    SH_SEGMENT,         ///> line segment
    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:
        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
    SHAPE_TYPE m_type;
};
+9 −0
Original line number Diff line number Diff line
@@ -86,6 +86,15 @@ public:
        return m_center;
    }

    void Move ( const VECTOR2I& aVector )
    {
        m_center += aVector;
    }

    bool IsSolid() const
    {
        return true;
    }
private:
    int m_radius;
    VECTOR2I m_center;
+21 −0
Original line number Diff line number Diff line
@@ -103,6 +103,17 @@ public:
        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( SH_LINE_CHAIN ),
        m_closed( false )
@@ -553,6 +564,16 @@ public:

    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:
    /// array of vertices
    std::vector<VECTOR2I> m_points;
Loading