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.

152 lines
6.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
  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 CONVERT_BASIC_SHAPES_TO_POLYGON_H
  25. #define CONVERT_BASIC_SHAPES_TO_POLYGON_H
  26. /**
  27. * @file convert_basic_shapes_to_polygon.h
  28. */
  29. #include <vector>
  30. #include <fctsys.h>
  31. #include <trigo.h>
  32. #include <macros.h>
  33. #include <geometry/shape_poly_set.h>
  34. /**
  35. * Function TransformCircleToPolygon
  36. * convert a circle to a polygon, using multiple straight lines
  37. * @param aCornerBuffer = a buffer to store the polygon
  38. * @param aCenter = the center of the circle
  39. * @param aRadius = the radius of the circle
  40. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  41. * Note: the polygon is inside the circle, so if you want to have the polygon
  42. * outside the circle, you should give aRadius calculated with a correction factor
  43. */
  44. void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  45. wxPoint aCenter, int aRadius,
  46. int aCircleToSegmentsCount );
  47. /**
  48. * convert a oblong shape to a polygon, using multiple segments
  49. * It is similar to TransformRoundedEndsSegmentToPolygon, but the polygon
  50. * is outside the actual oblong shape (a segment with rounded ends)
  51. * It is suitable to create oblong clearance areas.
  52. * because multiple segments create a smaller area than the circle, the
  53. * radius of the circle to approximate must be bigger ( radius*aCorrectionFactor)
  54. * to create segments outside the circle.
  55. * @param aCornerBuffer = a buffer to store the polygon
  56. * @param aStart = the first point of the segment
  57. * @param aEnd = the second point of the segment
  58. * @param aWidth = the width of the segment
  59. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  60. * @param aCorrectionFactor = the coefficient to have segments outside the circle
  61. * if aCorrectionFactor = 1.0, the shape will be the same as
  62. * TransformRoundedEndsSegmentToPolygon
  63. */
  64. void TransformOvalClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  65. wxPoint aStart, wxPoint aEnd, int aWidth,
  66. int aCircleToSegmentsCount, double aCorrectionFactor );
  67. /**
  68. * Helper function GetRoundRectCornerCenters
  69. * Has meaning only for rounded rect
  70. * Returns the centers of the rounded corners.
  71. * @param aCenters is the buffer to store the 4 coordinates.
  72. * @param aRadius = the radius of the of the rounded corners.
  73. * @param aPosition = position of the round rect
  74. * @param aSize = size of the of the round rect.
  75. * @param aRotation = rotation of the of the round rect
  76. */
  77. void GetRoundRectCornerCenters( wxPoint aCenters[4], int aRadius,
  78. const wxPoint& aPosition, const wxSize& aSize, double aRotation );
  79. /**
  80. * Function TransformRoundRectToPolygon
  81. * convert a rectangle with rounded corners to a polygon
  82. * Convert arcs to multiple straight lines
  83. * @param aCornerBuffer = a buffer to store the polygon
  84. * @param aPosition = the coordinate of the center of the rectangle
  85. * @param aSize = the size of the rectangle
  86. * @param aCornerRadius = radius of rounded corners
  87. * @param aRotation = rotation in 0.1 degrees of the rectangle
  88. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  89. */
  90. void TransformRoundRectToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  91. const wxPoint& aPosition, const wxSize& aSize,
  92. double aRotation, int aCornerRadius,
  93. int aCircleToSegmentsCount );
  94. /**
  95. * Function TransformRoundedEndsSegmentToPolygon
  96. * convert a segment with rounded ends to a polygon
  97. * Convert arcs to multiple straight lines
  98. * @param aCornerBuffer = a buffer to store the polygon
  99. * @param aStart = the segment start point coordinate
  100. * @param aEnd = the segment end point coordinate
  101. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  102. * @param aWidth = the segment width
  103. * Note: the polygon is inside the arc ends, so if you want to have the polygon
  104. * outside the circle, you should give aStart and aEnd calculated with a correction factor
  105. */
  106. void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  107. wxPoint aStart, wxPoint aEnd,
  108. int aCircleToSegmentsCount,
  109. int aWidth );
  110. /**
  111. * Function TransformArcToPolygon
  112. * Creates a polygon from an Arc
  113. * Convert arcs to multiple straight segments
  114. * @param aCornerBuffer = a buffer to store the polygon
  115. * @param aCentre = centre of the arc or circle
  116. * @param aStart = start point of the arc, or a point on the circle
  117. * @param aArcAngle = arc angle in 0.1 degrees. For a circle, aArcAngle = 3600
  118. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  119. * @param aWidth = width (thickness) of the line
  120. */
  121. void TransformArcToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  122. wxPoint aCentre, wxPoint aStart, double aArcAngle,
  123. int aCircleToSegmentsCount, int aWidth );
  124. /**
  125. * Function TransformRingToPolygon
  126. * Creates a polygon from a ring
  127. * Convert arcs to multiple straight segments
  128. * @param aCornerBuffer = a buffer to store the polygon
  129. * @param aCentre = centre of the arc or circle
  130. * @param aRadius = radius of the circle
  131. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  132. * @param aWidth = width (thickness) of the ring
  133. */
  134. void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  135. wxPoint aCentre, int aRadius,
  136. int aCircleToSegmentsCount, int aWidth );
  137. #endif // CONVERT_BASIC_SHAPES_TO_POLYGON_H