Audio plugin host https://kx.studio/carla
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.

juce_PathIterator.h 4.2KB

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