The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

117 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_PATHITERATOR_JUCEHEADER__
  19. #define __JUCE_PATHITERATOR_JUCEHEADER__
  20. #include "juce_Path.h"
  21. //==============================================================================
  22. /**
  23. Flattens a Path object into a series of straight-line sections.
  24. Use one of these to iterate through a Path object, and it will convert
  25. all the curves into line sections so it's easy to render or perform
  26. geometric operations on.
  27. @see Path
  28. */
  29. class JUCE_API PathFlatteningIterator
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a PathFlatteningIterator.
  34. After creation, use the next() method to initialise the fields in the
  35. object with the first line's position.
  36. @param path the path to iterate along
  37. @param transform a transform to apply to each point in the path being iterated
  38. @param tolerance the amount by which the curves are allowed to deviate from the lines
  39. into which they are being broken down - a higher tolerance contains
  40. less lines, so can be generated faster, but will be less smooth.
  41. */
  42. PathFlatteningIterator (const Path& path,
  43. const AffineTransform& transform = AffineTransform::identity,
  44. float tolerance = defaultTolerance);
  45. /** Destructor. */
  46. ~PathFlatteningIterator();
  47. //==============================================================================
  48. /** Fetches the next line segment from the path.
  49. This will update the member variables x1, y1, x2, y2, subPathIndex and closesSubPath
  50. so that they describe the new line segment.
  51. @returns false when there are no more lines to fetch.
  52. */
  53. bool next();
  54. float x1; /**< The x position of the start of the current line segment. */
  55. float y1; /**< The y position of the start of the current line segment. */
  56. float x2; /**< The x position of the end of the current line segment. */
  57. float y2; /**< The y position of the end of the current line segment. */
  58. /** Indicates whether the current line segment is closing a sub-path.
  59. If the current line is the one that connects the end of a sub-path
  60. back to the start again, this will be true.
  61. */
  62. bool closesSubPath;
  63. /** The index of the current line within the current sub-path.
  64. E.g. you can use this to see whether the line is the first one in the
  65. subpath by seeing if it's 0.
  66. */
  67. int subPathIndex;
  68. /** Returns true if the current segment is the last in the current sub-path. */
  69. bool isLastInSubpath() const noexcept;
  70. /** This is the default value that should be used for the tolerance value (see the constructor parameters). */
  71. static const float defaultTolerance;
  72. private:
  73. //==============================================================================
  74. const Path& path;
  75. const AffineTransform transform;
  76. float* points;
  77. const float toleranceSquared;
  78. float subPathCloseX, subPathCloseY;
  79. const bool isIdentityTransform;
  80. HeapBlock <float> stackBase;
  81. float* stackPos;
  82. size_t index, stackSize;
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PathFlatteningIterator);
  84. };
  85. #endif // __JUCE_PATHITERATOR_JUCEHEADER__