hnOsmium0001

rect2 + rect2i hpp

Sep 11th, 2020
1,060
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. template <class Vector, class UVector>
  3. struct Rect2KImpl {
  4.     using Scalar = typename Vector::value_type;
  5.     using UScalar = typename UVector::value_type;
  6.  
  7.     Vector TopLeft;
  8.     Vector BottomRight;
  9.  
  10.     static Rect2KImpl FromCorners(Vector tl, Vector br);
  11.     static Rect2KImpl FromHalfDim(Vector center, UScalar halfDimension);
  12.     static Rect2KImpl FromDim(Vector topLeft, UVector dimensions);
  13.     static Rect2KImpl FromScalars(Scalar x, Scalar y, UScalar width, UScalar height);
  14.  
  15.     __declspec(property(get = GetCenter)) Vector Center;
  16.     Vector GetCenter() const;
  17.     __declspec(property(get = GetTopRight, put = SetTopRight)) Vector TopRight;
  18.     Vector GetTopRight() const;
  19.     void SetTopRight(Vector topRight);
  20.     __declspec(property(get = GetBottomLeft, put = SetBottomLeft)) Vector BottomLeft;
  21.     Vector GetBottomLeft() const;
  22.     void SetBottomLeft(Vector bottomLeft);
  23.     __declspec(property(get = GetX, put = SetX)) Scalar X;
  24.     Scalar GetX() const;
  25.     void SetX(Scalar x);
  26.     __declspec(property(get = GetY, put = SetY)) Scalar Y;
  27.     Scalar GetY() const;
  28.     void SetY(Scalar y);
  29.     __declspec(property(get = GetWidth, put = SetWidth)) UScalar Width;
  30.     UScalar GetWidth() const;
  31.     void SetWidth(UScalar width);
  32.     __declspec(property(get = GetHeight, put = SetHeight)) UScalar Height;
  33.     UScalar GetHeight() const;
  34.     void SetHeight(UScalar height);
  35.     __declspec(property(get = GetDimensions, put = SetDimensions)) UVector Dimensions;
  36.     UVector GetDimensions() const;
  37.     void SetDimensions(UVector dimensions);
  38.     __declspec(property(get = GetHalfDimensions, put = SetHalfDimensions)) UVector HalfDimensions;
  39.     UVector GetHalfDimensions() const;
  40.     void SetHalfDimensions(UVector halfDimensions);
  41.  
  42.     bool HasPoint(Vector pt) const;
  43.     bool IntersectsWith(const Rect2KImpl<Vector, UVector>& rect) const;
  44.  
  45.     template <typename = std::enable_if_t<std::is_same_v<UScalar, Diligent::Uint32>>>
  46.     Diligent::Box ToDiligentBox() const;
  47. };
  48.  
  49. using Rect2i = Rect2KImpl<glm::ivec2, glm::uvec2>;
  50. using Rect2 = Rect2KImpl<glm::vec2, glm::vec2>;
  51.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×