mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 09:49:21 +00:00
LibGfx: Add Path::contains()
With this new method, it is possible to check whether a 2D point is inside of the path.
This commit is contained in:
parent
76daba3069
commit
18bc5972f4
Notes:
github-actions[bot]
2024-09-18 20:22:59 +00:00
Author: https://github.com/mierenhoop 🔰
Commit: 18bc5972f4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1423
Reviewed-by: https://github.com/AtkinsSJ
3 changed files with 21 additions and 0 deletions
|
@ -39,6 +39,7 @@ public:
|
||||||
[[nodiscard]] virtual bool is_empty() const = 0;
|
[[nodiscard]] virtual bool is_empty() const = 0;
|
||||||
virtual Gfx::FloatPoint last_point() const = 0;
|
virtual Gfx::FloatPoint last_point() const = 0;
|
||||||
virtual Gfx::FloatRect bounding_box() const = 0;
|
virtual Gfx::FloatRect bounding_box() const = 0;
|
||||||
|
virtual bool contains(FloatPoint point, Gfx::WindingRule) const = 0;
|
||||||
|
|
||||||
virtual NonnullOwnPtr<PathImpl> clone() const = 0;
|
virtual NonnullOwnPtr<PathImpl> clone() const = 0;
|
||||||
virtual NonnullOwnPtr<PathImpl> copy_transformed(Gfx::AffineTransform const&) const = 0;
|
virtual NonnullOwnPtr<PathImpl> copy_transformed(Gfx::AffineTransform const&) const = 0;
|
||||||
|
@ -84,6 +85,7 @@ public:
|
||||||
[[nodiscard]] bool is_empty() const { return impl().is_empty(); }
|
[[nodiscard]] bool is_empty() const { return impl().is_empty(); }
|
||||||
Gfx::FloatPoint last_point() const { return impl().last_point(); }
|
Gfx::FloatPoint last_point() const { return impl().last_point(); }
|
||||||
Gfx::FloatRect bounding_box() const { return impl().bounding_box(); }
|
Gfx::FloatRect bounding_box() const { return impl().bounding_box(); }
|
||||||
|
bool contains(FloatPoint point, Gfx::WindingRule winding_rule) const { return impl().contains(point, winding_rule); }
|
||||||
|
|
||||||
Gfx::Path clone() const { return Gfx::Path { impl().clone() }; }
|
Gfx::Path clone() const { return Gfx::Path { impl().clone() }; }
|
||||||
Gfx::Path copy_transformed(Gfx::AffineTransform const& transform) const { return Gfx::Path { impl().copy_transformed(transform) }; }
|
Gfx::Path copy_transformed(Gfx::AffineTransform const& transform) const { return Gfx::Path { impl().copy_transformed(transform) }; }
|
||||||
|
|
|
@ -199,6 +199,24 @@ Gfx::FloatRect PathImplSkia::bounding_box() const
|
||||||
return { bounds.fLeft, bounds.fTop, bounds.fRight - bounds.fLeft, bounds.fBottom - bounds.fTop };
|
return { bounds.fLeft, bounds.fTop, bounds.fRight - bounds.fLeft, bounds.fBottom - bounds.fTop };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SkPathFillType to_skia_path_fill_type(Gfx::WindingRule winding_rule)
|
||||||
|
{
|
||||||
|
switch (winding_rule) {
|
||||||
|
case Gfx::WindingRule::Nonzero:
|
||||||
|
return SkPathFillType::kWinding;
|
||||||
|
case Gfx::WindingRule::EvenOdd:
|
||||||
|
return SkPathFillType::kEvenOdd;
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PathImplSkia::contains(FloatPoint point, Gfx::WindingRule winding_rule) const
|
||||||
|
{
|
||||||
|
SkPath temp_path = *m_path;
|
||||||
|
temp_path.setFillType(to_skia_path_fill_type(winding_rule));
|
||||||
|
return temp_path.contains(point.x(), point.y());
|
||||||
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<PathImpl> PathImplSkia::clone() const
|
NonnullOwnPtr<PathImpl> PathImplSkia::clone() const
|
||||||
{
|
{
|
||||||
auto new_path = PathImplSkia::create();
|
auto new_path = PathImplSkia::create();
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
[[nodiscard]] virtual bool is_empty() const override;
|
[[nodiscard]] virtual bool is_empty() const override;
|
||||||
virtual Gfx::FloatPoint last_point() const override;
|
virtual Gfx::FloatPoint last_point() const override;
|
||||||
virtual Gfx::FloatRect bounding_box() const override;
|
virtual Gfx::FloatRect bounding_box() const override;
|
||||||
|
virtual bool contains(FloatPoint point, Gfx::WindingRule) const override;
|
||||||
|
|
||||||
virtual NonnullOwnPtr<PathImpl> clone() const override;
|
virtual NonnullOwnPtr<PathImpl> clone() const override;
|
||||||
virtual NonnullOwnPtr<PathImpl> copy_transformed(Gfx::AffineTransform const&) const override;
|
virtual NonnullOwnPtr<PathImpl> copy_transformed(Gfx::AffineTransform const&) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue