From 1ef120ff4fff10141b8b7f0e6e4cdfad0e6c2a58 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Wed, 7 Oct 2020 15:15:16 +0200 Subject: [PATCH] geometry: SHAPE::Format() now outputs C-like code for easy test cases... --- libs/kimath/CMakeLists.txt | 2 + libs/kimath/include/geometry/shape_rect.h | 2 + libs/kimath/include/geometry/shape_segment.h | 12 +---- libs/kimath/src/geometry/shape_compound.cpp | 11 ++++- libs/kimath/src/geometry/shape_line_chain.cpp | 19 ++++++-- libs/kimath/src/geometry/shape_segment.cpp | 46 +++++++++++++++++++ 6 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 libs/kimath/src/geometry/shape_segment.cpp diff --git a/libs/kimath/CMakeLists.txt b/libs/kimath/CMakeLists.txt index b6631b63a7..832bfa888b 100644 --- a/libs/kimath/CMakeLists.txt +++ b/libs/kimath/CMakeLists.txt @@ -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 ) diff --git a/libs/kimath/include/geometry/shape_rect.h b/libs/kimath/include/geometry/shape_rect.h index dc968f9e3e..33367faa3a 100644 --- a/libs/kimath/include/geometry/shape_rect.h +++ b/libs/kimath/include/geometry/shape_rect.h @@ -185,6 +185,8 @@ public: return rv; } + virtual const std::string Format( ) const override; + private: ///> Top-left corner VECTOR2I m_p0; diff --git a/libs/kimath/include/geometry/shape_segment.h b/libs/kimath/include/geometry/shape_segment.h index afd12d6504..d221cf3cd2 100644 --- a/libs/kimath/include/geometry/shape_segment.h +++ b/libs/kimath/include/geometry/shape_segment.h @@ -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; diff --git a/libs/kimath/src/geometry/shape_compound.cpp b/libs/kimath/src/geometry/shape_compound.cpp index 57a626c1ad..a3f128aeae 100644 --- a/libs/kimath/src/geometry/shape_compound.cpp +++ b/libs/kimath/src/geometry/shape_compound.cpp @@ -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; +} diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index bbed7858c4..5916c525e2 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -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();*/ } diff --git a/libs/kimath/src/geometry/shape_segment.cpp b/libs/kimath/src/geometry/shape_segment.cpp new file mode 100644 index 0000000000..4c4d093b3e --- /dev/null +++ b/libs/kimath/src/geometry/shape_segment.cpp @@ -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 + * + * 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 + +#include + +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(); +}