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.

105 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. Flattens a Path object into a series of straight-line sections.
  18. Use one of these to iterate through a Path object, and it will convert
  19. all the curves into line sections so it's easy to render or perform
  20. geometric operations on.
  21. @see Path
  22. @tags{Graphics}
  23. */
  24. class JUCE_API PathFlatteningIterator final
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a PathFlatteningIterator.
  29. After creation, use the next() method to initialise the fields in the
  30. object with the first line's position.
  31. @param path the path to iterate along
  32. @param transform a transform to apply to each point in the path being iterated
  33. @param tolerance the amount by which the curves are allowed to deviate from the lines
  34. into which they are being broken down - a higher tolerance contains
  35. less lines, so can be generated faster, but will be less smooth.
  36. */
  37. PathFlatteningIterator (const Path& path,
  38. const AffineTransform& transform = AffineTransform(),
  39. float tolerance = Path::defaultToleranceForMeasurement);
  40. /** Destructor. */
  41. ~PathFlatteningIterator();
  42. //==============================================================================
  43. /** Fetches the next line segment from the path.
  44. This will update the member variables x1, y1, x2, y2, subPathIndex and closesSubPath
  45. so that they describe the new line segment.
  46. @returns false when there are no more lines to fetch.
  47. */
  48. bool next();
  49. float x1; /**< The x position of the start of the current line segment. */
  50. float y1; /**< The y position of the start of the current line segment. */
  51. float x2; /**< The x position of the end of the current line segment. */
  52. float y2; /**< The y position of the end of the current line segment. */
  53. /** Indicates whether the current line segment is closing a sub-path.
  54. If the current line is the one that connects the end of a sub-path
  55. back to the start again, this will be true.
  56. */
  57. bool closesSubPath;
  58. /** The index of the current line within the current sub-path.
  59. E.g. you can use this to see whether the line is the first one in the
  60. subpath by seeing if it's 0.
  61. */
  62. int subPathIndex;
  63. /** Returns true if the current segment is the last in the current sub-path. */
  64. bool isLastInSubpath() const noexcept;
  65. private:
  66. //==============================================================================
  67. const Path& path;
  68. const AffineTransform transform;
  69. const float* source;
  70. const float toleranceSquared;
  71. float subPathCloseX = 0, subPathCloseY = 0;
  72. const bool isIdentityTransform;
  73. HeapBlock<float> stackBase { 32 };
  74. float* stackPos;
  75. size_t stackSize = 32;
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PathFlatteningIterator)
  77. };
  78. } // namespace juce