DiscreteCircle.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // DiscreteCircle.h ///////////////////////////////////////////////////////////////////////////////
  24. // John K McDonald, Jr.
  25. // September 2002
  26. // DO NOT DISTRIBUTE
  27. #pragma once
  28. #ifndef __DISCRETECIRCLE_H__
  29. #define __DISCRETECIRCLE_H__
  30. //-------------------------------------------------------------------------------------------------
  31. /**
  32. One horizontal line of the circle we are going to generate, the points drawn should be from
  33. (xStart, yPos)-(xEnd, yPos), inclusive.
  34. */
  35. struct HorzLine
  36. {
  37. Int yPos;
  38. Int xStart;
  39. Int xEnd;
  40. };
  41. // Vector and Iterators for the HorzLine struct.
  42. typedef std::vector<HorzLine> VecHorzLine;
  43. typedef VecHorzLine::iterator VecHorzLineIt;
  44. //-------------------------------------------------------------------------------------------------
  45. // Useful if you'd like to not have to deal with the logic of drawing the circle.
  46. typedef void (*ScanlineDrawFunc)(Int xStart, Int xEnd, Int yPos, void *otherParms);
  47. /**
  48. DiscreteCircle generates a circle centered at xCenter, yCenter, including radius. It generates
  49. horizontal segments for the top half of the circle only, so they need to be duplicated for the
  50. bottom half.
  51. */
  52. class DiscreteCircle
  53. {
  54. VecHorzLine m_edges; // Should be HorzLines
  55. Int m_yPos; // Used to know when to draw the bottom scanline
  56. Int m_yPosDoubled; // Used to draw the bottom half of the circle.
  57. public:
  58. DiscreteCircle(Int xCenter, Int yCenter, Int radius);
  59. __inline const VecHorzLine &getEdges(void) const { return m_edges; }
  60. __inline Int getEdgeCount(void) const { return m_edges.size(); }
  61. void drawCircle(ScanlineDrawFunc functionToDrawWith, void *parmToPass);
  62. protected:
  63. void generateEdgePairs(Int xCenter, Int yCenter, Int radius);
  64. void removeDuplicates();
  65. };
  66. #endif /* __DISCRETECIRCLE_H__ */