Rect2.h
Rect2.h
CPP1/* Copyright Statement:2 *3 * (C) 2021-2025 Cubios Inc. All rights reserved.4 */5#ifndef WASMLIBS_CPP_RECT2_H_6#define WASMLIBS_CPP_RECT2_H_78#include "Vec2.h"910namespace Cubios11{12namespace Math13{14class Rect215{16public:17 /// default constructor18 Rect2();19 Rect2(const Vec2i& topLeft, const Vec2i& bottomRight);20 Rect2(int16_t x, int16_t y, int16_t width, int16_t height);2122 void Set(const Vec2i& topLeft, const Vec2i& bottomRight);2324 bool IsInside(const Vec2i& p) const;2526 Vec2i Midpoint() const;2728 Vec2i v0;29 Vec2i v1;30 int16_t W;31 int16_t H;32};3334inline Rect2::Rect2():W(0),H(0)35{36}3738inline Rect2::Rect2(const Vec2i& topLeft, const Vec2i& bottomRight) :39 v0(topLeft),40 v1(bottomRight)41{42 this->W = this->v1.X - this->v0.X;43 this->H = this->v1.Y - this->v0.Y;44}4546inline Rect2::Rect2(int16_t x, int16_t y, int16_t width, int16_t height):47 v0(x,y),48 v1(x+width, y+height),W(width),H(height)49{50}5152inline void Rect2::Set(const Vec2i& topLeft, const Vec2i& bottomRight)53{54 this->v0 = topLeft;55 this->v1 = bottomRight;5657 this->W = this->v1.X - this->v0.X;58 this->H = this->v1.Y - this->v0.Y;59}6061inline bool Rect2::IsInside(const Vec2i& p) const62{63 return ((this->v0.X <= p.X) && (p.X <= this->v1.X) &&64 (this->v0.Y <= p.Y) && (p.Y <= this->v1.Y));65}6667inline Vec2i Rect2::Midpoint() const68{69 return (this->v0 + this->v1) * 0.5f;70}7172}73}74#endif /* WASMLIBS_CPP_RECT2_H_ */7576
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.