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.

112 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Flattens a Path object into a series of straight-line sections.
  23. Use one of these to iterate through a Path object, and it will convert
  24. all the curves into line sections so it's easy to render or perform
  25. geometric operations on.
  26. @see Path
  27. @tags{Graphics}
  28. */
  29. class JUCE_API PathFlatteningIterator final
  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. const float* source;
  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 stackSize = 32;
  81. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PathFlatteningIterator)
  82. };
  83. } // namespace juce