Add ui::triangle_shape

This commit is contained in:
Nikita Lisitsa 2021-03-05 22:50:09 +03:00
parent 6ad43ff0a5
commit c54a9944f1
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#pragma once
#include <psemek/ui/shape.hpp>
#include <psemek/geom/simplex.hpp>
namespace psemek::ui
{
struct triangle_shape
: shape
{
geom::triangle<geom::point<float, 2>> triangle{{{0.f, 0.f}, {0.f, 0.f}, {0.f, 0.f}}};
triangle_shape() = default;
triangle_shape(geom::triangle<geom::point<float, 2>> triangle)
: triangle{triangle}
{}
bool contains(geom::point<float, 2> const & point) const override;
geom::box<float, 2> bbox() const override;
};
}

View file

@ -0,0 +1,22 @@
#include <psemek/ui/triangle_shape.hpp>
#include <psemek/geom/contains.hpp>
namespace psemek::ui
{
bool triangle_shape::contains(geom::point<float, 2> const & point) const
{
return geom::contains(triangle, point);
}
geom::box<float, 2> triangle_shape::bbox() const
{
geom::box<float, 2> b;
b |= triangle[0];
b |= triangle[1];
b |= triangle[2];
return b;
}
}