From d89f8407e0212105363a33fabc14125d21583ff0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 21 Jun 2020 15:58:44 +0100 Subject: [PATCH] Const fixes. --- libs/kimath/include/geometry/shape_poly_set.h | 8 ++++---- libs/kimath/include/geometry/shape_simple.h | 7 +++++++ libs/kimath/src/geometry/shape_poly_set.cpp | 16 ++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index bce4ac27ad..1e282cc8a5 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -1176,7 +1176,7 @@ class SHAPE_POLY_SET : public SHAPE * @return int - The minimum distance between aPoint and all the segments of the aIndex-th * polygon. If the point is contained in the polygon, the distance is zero. */ - SEG::ecoord SquaredDistanceToPolygon( VECTOR2I aPoint, int aIndex ); + SEG::ecoord SquaredDistanceToPolygon( VECTOR2I aPoint, int aIndex ) const; /** * Function DistanceToPolygon @@ -1190,7 +1190,7 @@ class SHAPE_POLY_SET : public SHAPE * aIndex-th polygon. If the point is contained in the polygon, the * distance is zero. */ - SEG::ecoord SquaredDistanceToPolygon( const SEG& aSegment, int aIndex ); + SEG::ecoord SquaredDistanceToPolygon( const SEG& aSegment, int aIndex ) const; /** * Function SquaredDistance @@ -1200,7 +1200,7 @@ class SHAPE_POLY_SET : public SHAPE * @return The minimum distance squared between aPoint and all the polygons in the set. * If the point is contained in any of the polygons, the distance is zero. */ - SEG::ecoord SquaredDistance( VECTOR2I aPoint ); + SEG::ecoord SquaredDistance( VECTOR2I aPoint ) const; /** * Function SquaredDistance @@ -1211,7 +1211,7 @@ class SHAPE_POLY_SET : public SHAPE * @return The minimum distance squared between aSegment and all the polygons in the set. * If the point is contained in the polygon, the distance is zero. */ - SEG::ecoord SquaredDistance( const SEG& aSegment ); + SEG::ecoord SquaredDistance( const SEG& aSegment ) const; /** * Function IsVertexInHole. diff --git a/libs/kimath/include/geometry/shape_simple.h b/libs/kimath/include/geometry/shape_simple.h index a9a9027cf2..2b8d6dcf24 100644 --- a/libs/kimath/include/geometry/shape_simple.h +++ b/libs/kimath/include/geometry/shape_simple.h @@ -52,6 +52,13 @@ public: m_points.SetClosed( true ); } + SHAPE_SIMPLE( const SHAPE_LINE_CHAIN& aPoly ) : + SHAPE( SH_SIMPLE ), + m_points( aPoly ) + { + m_points.SetClosed( true ); + } + SHAPE_SIMPLE( const SHAPE_SIMPLE& aOther ) : SHAPE( SH_SIMPLE ), m_points( aOther.m_points ) {} diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 21f9d19df5..1e59064ca9 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -1584,7 +1584,7 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::FilletPolygon( unsigned int aRadius, int } -SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( VECTOR2I aPoint, int aPolygonIndex ) +SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( VECTOR2I aPoint, int aPolygonIndex ) const { // We calculate the min dist between the segment and each outline segment. However, if the // segment to test is inside the outline, and does not cross any edge, it can be seen outside @@ -1593,7 +1593,7 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( VECTOR2I aPoint, int aPoly if( containsSingle( aPoint, aPolygonIndex, 1 ) ) return 0; - SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex ); + CONST_SEGMENT_ITERATOR iterator = CIterateSegmentsWithHoles( aPolygonIndex ); SEG polygonEdge = *iterator; SEG::ecoord minDistance = polygonEdge.SquaredDistance( aPoint ); @@ -1612,7 +1612,7 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( VECTOR2I aPoint, int aPoly } -SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( const SEG& aSegment, int aPolygonIndex ) +SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( const SEG& aSegment, int aPolygonIndex ) const { // We calculate the min dist between the segment and each outline segment. However, if the // segment to test is inside the outline, and does not cross any edge, it can be seen outside @@ -1621,9 +1621,9 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( const SEG& aSegment, int a if( containsSingle( aSegment.A, aPolygonIndex, 1 ) ) return 0; - SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex ); - SEG polygonEdge = *iterator; - SEG::ecoord minDistance = polygonEdge.SquaredDistance( aSegment ); + CONST_SEGMENT_ITERATOR iterator = CIterateSegmentsWithHoles( aPolygonIndex ); + SEG polygonEdge = *iterator; + SEG::ecoord minDistance = polygonEdge.SquaredDistance( aSegment ); for( iterator++; iterator && minDistance > 0; iterator++ ) { @@ -1640,7 +1640,7 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistanceToPolygon( const SEG& aSegment, int a } -SEG::ecoord SHAPE_POLY_SET::SquaredDistance( VECTOR2I aPoint ) +SEG::ecoord SHAPE_POLY_SET::SquaredDistance( VECTOR2I aPoint ) const { SEG::ecoord currentDistance; SEG::ecoord minDistance = SquaredDistanceToPolygon( aPoint, 0 ); @@ -1658,7 +1658,7 @@ SEG::ecoord SHAPE_POLY_SET::SquaredDistance( VECTOR2I aPoint ) } -SEG::ecoord SHAPE_POLY_SET::SquaredDistance( const SEG& aSegment ) +SEG::ecoord SHAPE_POLY_SET::SquaredDistance( const SEG& aSegment ) const { SEG::ecoord currentDistance; SEG::ecoord minDistance = SquaredDistanceToPolygon( aSegment, 0 );