Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copied axis point and rect methods over from elements:master branch #24

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/include/artist/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

namespace cycfi::artist
{
////////////////////////////////////////////////////////////////////////////
// Axis
////////////////////////////////////////////////////////////////////////////
enum class axis : bool { x = false, y = true};

inline constexpr axis other(axis a)
{
return axis(! bool(a));
}

////////////////////////////////////////////////////////////////////////////
// Points
////////////////////////////////////////////////////////////////////////////
Expand All @@ -25,6 +35,9 @@ namespace cycfi::artist
constexpr point move_to(float x, float y) const;
constexpr point reflect(point p) const;

constexpr float& operator[](axis a);
constexpr float operator[](axis a) const;

float x;
float y;
};
Expand Down Expand Up @@ -86,6 +99,16 @@ namespace cycfi::artist
{
return {x + (x - p.x), y + (y - p.y)};
}

constexpr float& point::operator[](axis a)
{
return a==axis::x ? x : y;
}

constexpr float point::operator[](axis a) const
{
return a==axis::x ? x : y;
}
}

#endif
35 changes: 35 additions & 0 deletions lib/include/artist/rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@ namespace cycfi::artist
r.right = 0.0;
r.bottom = 0.0;
}

inline constexpr float axis_extent(rect const &r, axis a)
{
return a == axis::x ? r.width() : r.height();
}

inline constexpr float axis_min(rect const &r, axis a)
{
return a == axis::x ? r.left : r.top;
}

inline constexpr float axis_max(rect const &r, axis a)
{
return a == axis::x ? r.right : r.bottom;
}

inline constexpr float& axis_min(rect &r, axis a)
{
return a == axis::x ? r.left : r.top;
}

inline constexpr float& axis_max(rect &r, axis a)
{
return a == axis::x ? r.right : r.bottom;
}

inline constexpr auto make_rect(axis a, float this_axis_min, float other_axis_min, float this_axis_max, float other_axis_max) -> rect
{
if (a == axis::x) {
return rect(this_axis_min, other_axis_min, this_axis_max, other_axis_max);
}
else {
return rect(other_axis_min, this_axis_min, other_axis_max, this_axis_max);
}
}
}

#endif
Loading