Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::FromCorners(Vector tl, Vector br) -> Rect2KImpl<Vector, UVector> {
- return Rect2KImpl<Vector, UVector>{
- .TopLeft = tl,
- .BottomRight = br,
- };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::FromHalfDim(Vector center, UScalar halfDimension) -> Rect2KImpl<Vector, UVector> {
- return Rect2KImpl<Vector, UVector>{
- .TopLeft = Vector{ center.x - halfDimension, center.y - halfDimension },
- .BottomRight = Vector{ center.x + halfDimension, center.y + halfDimension },
- };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::FromDim(Vector topLeft, UVector dimensions) -> Rect2KImpl<Vector, UVector> {
- return Rect2KImpl<Vector, UVector>{
- .TopLeft = Vector{ topLeft },
- .BottomRight = Vector{ topLeft.x + dimensions.x, topLeft.y + dimensions.y },
- };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::FromScalars(Scalar x, Scalar y, UScalar width, UScalar height) -> Rect2KImpl<Vector, UVector> {
- return Rect2KImpl<Vector, UVector>{
- .TopLeft = Vector{ x, y },
- .BottomRight = Vector{ x + width, y + height },
- };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetCenter() const -> Vector {
- UScalar halfWidth = (BottomRight.x - TopLeft.x) / 2;
- UScalar halfHeight = (BottomRight.y - TopLeft.y) / 2;
- return { TopLeft.x + halfWidth, TopLeft.y + halfHeight };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetTopRight() const -> Vector {
- return { BottomRight.x, TopLeft.y };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetTopRight(Vector topRight) -> void {
- BottomRight.x = topRight.x;
- TopLeft.y = topRight.y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetBottomLeft() const -> Vector {
- return { TopLeft.x, BottomRight.y };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetBottomLeft(Vector bottomLeft) -> void {
- TopLeft.x = bottomLeft.x;
- BottomRight.y = bottomLeft.y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetX() const -> Scalar {
- return TopLeft.x;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetX(Scalar x) -> void {
- TopLeft.x = x;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetY() const -> Scalar {
- return TopLeft.y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetY(Scalar y) -> void {
- TopLeft.y = y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetWidth() const -> UScalar {
- return BottomRight.x - TopLeft.x;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetWidth(UScalar width) -> void {
- BottomRight.x = TopLeft.x + width;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetHeight() const -> UScalar {
- return BottomRight.y - TopLeft.y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetHeight(UScalar height) -> void {
- BottomRight.y = TopLeft.y + height;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetDimensions() const -> UVector {
- return { Width, Height };
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetDimensions(UVector dimensions) -> void {
- Width = dimensions.x;
- Height = dimensions.y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::GetHalfDimensions() const -> UVector {
- return Dimensions / static_cast<UScalar>(2);
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::SetHalfDimensions(UVector halfDimensions) -> void {
- Dimensions = halfDimensions * static_cast<UScalar>(2);
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::HasPoint(Vector pt) const -> bool {
- return pt.x >= TopLeft.x &&
- pt.x <= BottomRight.y &&
- pt.y >= TopLeft.y &&
- pt.y <= BottomRight.y;
- }
- template <class Vector, class UVector>
- auto Rect2KImpl<Vector, UVector>::IntersectsWith(const Rect2KImpl<Vector, UVector>& rect) const -> bool {
- return rect.HasPoint(TopLeft) ||
- rect.HasPoint(TopRight) ||
- rect.HasPoint(BottomLeft) ||
- rect.HasPoint(BottomRight);
- }
- template struct Rect2KImpl<glm::ivec2, glm::uvec2>;
- template struct Rect2KImpl<glm::vec2, glm::vec2>;
Add Comment
Please, Sign In to add comment