You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef __SHAPE_ARC_H
  25. #define __SHAPE_ARC_H
  26. #include <geometry/shape.h>
  27. #include <geometry/seg.h>
  28. class SHAPE_LINE_CHAIN;
  29. class SHAPE_ARC : public SHAPE
  30. {
  31. public:
  32. SHAPE_ARC() :
  33. SHAPE( SH_ARC ), m_width( 0 ) {};
  34. SHAPE_ARC( const VECTOR2I& pa, const VECTOR2I& pb, const VECTOR2I& pCenter, int aWidth = 0 ) :
  35. SHAPE( SH_ARC ), m_p0( pa ), m_p1( pb ), m_pc( pCenter ), m_width( aWidth ) {};
  36. SHAPE_ARC( const SHAPE_ARC& aOther )
  37. : SHAPE( SH_ARC )
  38. {
  39. m_p0 = aOther.m_p0;
  40. m_p1 = aOther.m_p1;
  41. m_pc = aOther.m_pc;
  42. m_width = aOther.m_width;
  43. }
  44. ~SHAPE_ARC() {};
  45. SHAPE* Clone() const override
  46. {
  47. return new SHAPE_ARC( *this );
  48. }
  49. const VECTOR2I& GetP0() const { return m_p0; }
  50. const VECTOR2I& GetP1() const { return m_p1; }
  51. const VECTOR2I& GetCenter() const { return m_pc; }
  52. const BOX2I BBox( int aClearance = 0 ) const override
  53. {
  54. assert( false );
  55. return BOX2I(); // fixme
  56. }
  57. bool Collide( const SEG& aSeg, int aClearance = 0 ) const override;
  58. bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
  59. void SetWidth( int aWidth )
  60. {
  61. m_width = aWidth;
  62. }
  63. int GetWidth() const
  64. {
  65. return m_width;
  66. }
  67. bool IsSolid() const override
  68. {
  69. return true;
  70. }
  71. void Move( const VECTOR2I& aVector ) override
  72. {
  73. m_p0 += aVector;
  74. m_p1 += aVector;
  75. m_pc += aVector;
  76. }
  77. int GetRadius() const
  78. {
  79. return (m_pc - m_p0).EuclideanNorm();
  80. }
  81. SEG GetChord() const
  82. {
  83. return SEG( m_p0, m_p1 );
  84. }
  85. double GetCentralAngle() const;
  86. double GetStartAngle() const;
  87. double GetEndAngle() const;
  88. bool ConstructFromCorners( VECTOR2I aP0, VECTOR2I aP1, double aCenterAngle );
  89. bool ConstructFromCornerAndAngles( VECTOR2I aP0,
  90. double aStartAngle,
  91. double aCenterAngle,
  92. double aRadius );
  93. const SHAPE_LINE_CHAIN ConvertToPolyline( double aAccuracy = 0.02f ) const;
  94. private:
  95. bool ccw( const VECTOR2I& aA, const VECTOR2I& aB, const VECTOR2I& aC ) const
  96. {
  97. return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) >
  98. (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
  99. }
  100. VECTOR2I m_p0, m_p1, m_pc;
  101. int m_width;
  102. };
  103. #endif