geometry: SHAPE::Format() now outputs C-like code for easy test cases...
This commit is contained in:
parent
7ffef32ea0
commit
1ef120ff4f
|
@ -17,6 +17,8 @@ set( KIMATH_SRCS
|
|||
src/geometry/shape_poly_set.cpp
|
||||
src/geometry/shape_rect.cpp
|
||||
src/geometry/shape_compound.cpp
|
||||
src/geometry/shape_segment.cpp
|
||||
|
||||
|
||||
src/math/util.cpp
|
||||
)
|
||||
|
|
|
@ -185,6 +185,8 @@ public:
|
|||
return rv;
|
||||
}
|
||||
|
||||
virtual const std::string Format( ) const override;
|
||||
|
||||
private:
|
||||
///> Top-left corner
|
||||
VECTOR2I m_p0;
|
||||
|
|
|
@ -150,17 +150,7 @@ public:
|
|||
m_seg.B += aVector;
|
||||
}
|
||||
|
||||
const std::string Format() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "2 0 ";
|
||||
|
||||
ss << m_seg.A.x << " " << m_seg.A.y << " ";
|
||||
ss << m_seg.B.x << " " << m_seg.B.y << " ";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
virtual const std::string Format( ) const override;
|
||||
|
||||
private:
|
||||
SEG m_seg;
|
||||
|
|
|
@ -31,9 +31,10 @@ const std::string SHAPE_COMPOUND::Format() const
|
|||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "compound";
|
||||
ss << "compound( ";
|
||||
|
||||
// fixme: implement
|
||||
for( auto shape : m_shapes )
|
||||
ss << shape->Format() << " ";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
@ -152,3 +153,9 @@ bool SHAPE_COMPOUND::Collide( const SEG& aSeg, int aClearance, int* aActual,
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SHAPE_COMPOUND::ConvertToSimplePolygon( SHAPE_SIMPLE* aOut ) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -959,17 +959,30 @@ const std::string SHAPE_LINE_CHAIN::Format() const
|
|||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << m_points.size() << " " << ( m_closed ? 1 : 0 ) << " " << m_arcs.size() << " ";
|
||||
|
||||
ss << "SHAPE_LINE_CHAIN( { ";
|
||||
for( int i = 0; i < PointCount(); i++ )
|
||||
ss << m_points[i].x << " " << m_points[i].y << " " << m_shapes[i];
|
||||
{
|
||||
ss << "VECTOR2I( " << m_points[i].x << ", " << m_points[i].y << ")";
|
||||
if( i != PointCount() -1 )
|
||||
ss << ", ";
|
||||
}
|
||||
|
||||
ss << "}, " << m_closed ? "true" : "false";
|
||||
ss << " );";
|
||||
|
||||
|
||||
|
||||
return ss.str();
|
||||
|
||||
|
||||
/* fixme: arcs
|
||||
for( size_t i = 0; i < m_arcs.size(); i++ )
|
||||
ss << m_arcs[i].GetCenter().x << " " << m_arcs[i].GetCenter().y << " "
|
||||
<< m_arcs[i].GetP0().x << " " << m_arcs[i].GetP0().y << " "
|
||||
<< m_arcs[i].GetCentralAngle();
|
||||
|
||||
return ss.str();
|
||||
return ss.str();*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2017 CERN
|
||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <geometry/shape_segment.h>
|
||||
|
||||
const std::string SHAPE_SEGMENT::Format() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "SHAPE_SEGMENT( VECTOR2I( ";
|
||||
ss << m_seg.A.x;
|
||||
ss << ", ";
|
||||
ss << m_seg.A.y;
|
||||
ss << "), VECTOR2I( ";
|
||||
ss << m_seg.B.x;
|
||||
ss << ", ";
|
||||
ss << m_seg.B.y;
|
||||
ss << "), ";
|
||||
ss << m_width;
|
||||
ss << "); ";
|
||||
|
||||
return ss.str();
|
||||
}
|
Loading…
Reference in New Issue