Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
1.1 kB · 38 lines
C++
1234567891011121314151617181920212223242526272829303132333435363738#include "Geometry.h"#include <algorithm>
namespace UI {
bool Rect::Contains(float px, float py) const { return px >= X && px <= (X + Width) && py >= Y && py <= (Y + Height);}
bool Rect::Contains(Point p) const { return Contains(p.x, p.y);}
Rect Rect::Intersect(const Rect& other) const { float newX = std::max(X, other.X); float newY = std::max(Y, other.Y); float newRight = std::min(X + Width, other.X + other.Width); float newBottom = std::min(Y + Height, other.Y + other.Height);
float newWidth = std::max(0.0f, newRight - newX); float newHeight = std::max(0.0f, newBottom - newY);
return Rect(newX, newY, newWidth, newHeight);}
/*Rect Rect::Deflate(const Thickness& t) const { float newX = X + t.Left; float newY = Y + t.Top; float newWidth = std::max(0.0f, Width - t.HorizontalTotal()); float newHeight = std::max(0.0f, Height - t.VerticalTotal()); return Rect(newX, newY, newWidth, newHeight);}
Rect Rect::Inflate(const Thickness& t) const { return Rect(X - t.Left, Y - t.Top, Width + t.HorizontalTotal(), Height + t.VerticalTotal());} */
}