Sfoglia il codice sorgente

LibGfx: Add Path::cubic_bezier_curve_to()

This is pretty unsophisticated as it will simply add a fixed number of
of line segments approximating the curve. Still better than nothing.
Andreas Kling 3 anni fa
parent
commit
09d13e437b
2 ha cambiato i file con 13 aggiunte e 0 eliminazioni
  1. 11 0
      Userland/Libraries/LibGfx/Path.cpp
  2. 2 0
      Userland/Libraries/LibGfx/Path.h

+ 11 - 0
Userland/Libraries/LibGfx/Path.cpp

@@ -311,4 +311,15 @@ void Path::segmentize_path()
     m_bounding_box = Gfx::FloatRect { min_x, min_y, max_x - min_x, max_y - min_y };
     m_bounding_box = Gfx::FloatRect { min_x, min_y, max_x - min_x, max_y - min_y };
 }
 }
 
 
+void Path::cubic_bezier_curve_to(FloatPoint const& c1, FloatPoint const& c2, FloatPoint const& p2)
+{
+    // FIXME: I'm sure there's a faster and more elegant way to do this.
+    // FIXME: We should divide it into enough segments to stay within some tolerance.
+    auto p1 = segments().last().point();
+    for (float t = 0; t <= 1.0f; t += 0.02f) {
+        auto p = cubic_interpolate(p1, p2, c1, c2, t);
+        line_to(p);
+    }
+}
+
 }
 }

+ 2 - 0
Userland/Libraries/LibGfx/Path.h

@@ -134,6 +134,8 @@ public:
         invalidate_split_lines();
         invalidate_split_lines();
     }
     }
 
 
+    void cubic_bezier_curve_to(FloatPoint const& c1, FloatPoint const& c2, FloatPoint const& p2);
+
     void elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, double x_axis_rotation, bool large_arc, bool sweep);
     void elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, double x_axis_rotation, bool large_arc, bool sweep);
     void arc_to(const FloatPoint& point, float radius, bool large_arc, bool sweep)
     void arc_to(const FloatPoint& point, float radius, bool large_arc, bool sweep)
     {
     {