summaryrefslogtreecommitdiff
path: root/Libraries/LibGfx/Path.h
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibGfx/Path.h')
-rw-r--r--Libraries/LibGfx/Path.h49
1 files changed, 39 insertions, 10 deletions
diff --git a/Libraries/LibGfx/Path.h b/Libraries/LibGfx/Path.h
index df4c2d25a4..b8ab5f5cc0 100644
--- a/Libraries/LibGfx/Path.h
+++ b/Libraries/LibGfx/Path.h
@@ -26,6 +26,8 @@
#pragma once
+#include <AK/HashMap.h>
+#include <AK/Optional.h>
#include <AK/Vector.h>
#include <LibGfx/FloatPoint.h>
#include <LibGfx/Forward.h>
@@ -68,7 +70,22 @@ public:
void close();
+ struct LineSegment {
+ Point from, to;
+ float inverse_slope;
+ float x_of_minimum_y;
+ float maximum_y;
+ float minimum_y;
+ float x;
+ };
+
+ enum ShapeKind {
+ Simple,
+ Complex,
+ };
+
const Vector<Segment>& segments() const { return m_segments; }
+ Vector<LineSegment> split_lines(ShapeKind);
const auto& split_lines()
{
if (m_split_lines.has_value())
@@ -80,22 +97,34 @@ public:
String to_string() const;
- struct LineSegment {
- Point from, to;
- float inverse_slope;
- float x_of_minimum_y;
- float maximum_y;
- float minimum_y;
- float x;
- };
-
private:
- void invalidate_split_lines() { m_split_lines.clear(); }
+ void invalidate_split_lines()
+ {
+ m_split_lines.clear();
+ m_graph_node_map.clear();
+ }
void segmentize_path();
+ void generate_path_graph();
+ bool is_part_of_closed_polygon(const Point& p0, const Point& p1);
+ static unsigned hash_line(const Point& from, const Point& to);
Vector<Segment> m_segments;
Optional<Vector<LineSegment>> m_split_lines {};
+
+ struct PathGraphNode {
+ PathGraphNode(u32 hash, const LineSegment& line)
+ : hash(hash)
+ , line(line)
+ {
+ }
+
+ Vector<const PathGraphNode*> children;
+ u32 hash;
+ LineSegment line;
+ };
+
+ Optional<HashMap<u32, OwnPtr<PathGraphNode>>> m_graph_node_map;
};
inline const LogStream& operator<<(const LogStream& stream, const Path& path)