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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  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(),
  44. float tolerance = Path::defaultToleranceForMeasurement);
  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. private:
  71. //==============================================================================
  72. const Path& path;
  73. const AffineTransform transform;
  74. float* points;
  75. const float toleranceSquared;
  76. float subPathCloseX = 0, subPathCloseY = 0;
  77. const bool isIdentityTransform;
  78. HeapBlock<float> stackBase { 32 };
  79. float* stackPos;
  80. size_t index = 0, stackSize = 32;
  81. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PathFlatteningIterator)
  82. };
  83. } // namespace juce