Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - lineBreaker

Pages: [1]
1
General discussions / Why SFML's vectors are really dump?
« on: October 31, 2021, 07:27:50 am »
I mean if it has a reason I don't know what it is. Also if it has no reason there is a really good vector struct:

template<typename T>
struct vector2 {
   T r, i;// r: Real, i: Imaginary
   template<typename T0> vector2(const vector2<T0>& R) : r(R.r), i(R.i) {} vector2() : r(0.f), i(0.f) {}
   template<typename T1, typename T2> vector2(const T1& i1, const T2& i2) : r(i1), i(i2) {}
   template<typename T0> vector2(const T0 R[2]) : r(R[0]), i(R[1]) {}

   template<typename T0> const vector2<T>& operator =(const vector2<T0>& R) { r = R.r; i = R.i; return this; }
   template<typename T0> const vector2<T>& operator%=(const vector2<T0>& R) { r %= R.r; i %= R.i; return this; }
   template<typename T0> const vector2<T>& operator+=(const vector2<T0>& R) { r += R.r; i += R.i; return this; }
   template<typename T0> const vector2<T>& operator-=(const vector2<T0>& R) { r -= R.r; i -= R.i; return this; }
   template<typename T0> const vector2<T>& operator*=(const vector2<T0>& R) { r *= R.r; i *= R.i; return this; }
   template<typename T0> const vector2<T>& operator/=(const vector2<T0>& R) { r /= R.r; i /= R.i; return this; }
   template<typename T0> const vector2<T>& operator&=(const vector2<T0>& R) { r &= R.r; i &= R.i; return this; }
   template<typename T0> const vector2<T>& operator|=(const vector2<T0>& R) { r |= R.r; i |= R.i; return this; }
   template<typename T0> const vector2<T>& operator^=(const vector2<T0>& R) { r ^= R.r; i ^= R.i; return this; }
   template<typename T0> const vector2<T>& operator<<=(const vector2<T0>& R) { r <<= R.r; i <<= R.i; return this; }
   template<typename T0> const vector2<T>& operator>>=(const vector2<T0>& R) { r >>= R.r; i >>= R.i; return this; }

   template<typename T0> const vector2<T>& operator =(const T0& R) { r = R; i = R; return this; }
   template<typename T0> const vector2<T>& operator%=(const T0& R) { r %= R; i %= R; return this; }
   template<typename T0> const vector2<T>& operator+=(const T0& R) { r += R; i += R; return this; }
   template<typename T0> const vector2<T>& operator-=(const T0& R) { r -= R; i -= R; return this; }
   template<typename T0> const vector2<T>& operator*=(const T0& R) { r *= R; i *= R; return this; }
   template<typename T0> const vector2<T>& operator/=(const T0& R) { r /= R; i /= R; return this; }
   template<typename T0> const vector2<T>& operator&=(const T0& R) { r &= R; i &= R; return this; }
   template<typename T0> const vector2<T>& operator|=(const T0& R) { r |= R; i |= R; return this; }
   template<typename T0> const vector2<T>& operator^=(const T0& R) { r ^= R; i ^= R; return this; }
   template<typename T0> const vector2<T>& operator<<=(const T0& R) { r <<= R; i <<= R; return this; }
   template<typename T0> const vector2<T>& operator<<=(const T0& R) { r <<= R; i <<= R; return this; }

   template<typename T0> const vector2<T>& operator+(const vector2<T0>& R) const { return vector2<T>(r + R.r, i + R.i); }
   template<typename T0> const vector2<T>& operator-(const vector2<T0>& R) const { return vector2<T>(r - R.r, i - R.i); }
   template<typename T0> const vector2<T>& operator*(const vector2<T0>& R) const { return vector2<T>(r * R.r, i * R.i); }
   template<typename T0> const vector2<T>& operator/(const vector2<T0>& R) const { return vector2<T>(r / R.r, i / R.i); }
   template<typename T0> const vector2<T>& operator%(const vector2<T0>& R) const { return vector2<T>(r % R.r, i % R.i); }
   template<typename T0> const vector2<T>& operator&(const vector2<T0>& R) const { return vector2<T>(r & R.r, i & R.i); }
   template<typename T0> const vector2<T>& operator|(const vector2<T0>& R) const { return vector2<T>(r | R.r, i | R.i); }
   template<typename T0> const vector2<T>& operator<<(const vector2<T0>& R) const { return vector2<T>(r << R.r, i << R.i); }
   template<typename T0> const vector2<T>& operator>>(const vector2<T0>& R) const { return vector2<T>(r >> R.r, i >> R.i); }
   template<typename T0> const bool& operator&&(const vector2<T0>& R) const { return (r && R.r) || (i && R.i); }
   template<typename T0> const bool& operator||(const vector2<T0>& R) const { return (r || R.r) || (i || R.i); }

   template<typename T0> const vector2<T>& operator+(const T0& sc) const { return vector2<T>(r + sc, i + sc); }
   template<typename T0> const vector2<T>& operator-(const T0& sc) const { return vector2<T>(r - sc, i - sc); }
   template<typename T0> const vector2<T>& operator*(const T0& sc) const { return vector2<T>(r * sc, i * sc); }
   template<typename T0> const vector2<T>& operator/(const T0& sc) const { return vector2<T>(r / sc, i / sc); }
   template<typename T0> const vector2<T>& operator%(const T0& sc) const { return vector2<T>(r % sc, i % sc); }
   template<typename T0> const vector2<T>& operator&(const T0& sc) const { return vector2<T>(r & sc, i & sc); }
   template<typename T0> const vector2<T>& operator|(const T0& sc) const { return vector2<T>(r | sc, i | sc); }
   template<typename T0> const vector2<T>& operator^(const T0& sc) const { return vector2<T>(r ^ sc, i ^ sc); }
   template<typename T0> const vector2<T>& operator<<(const T0& sc) const { return vector2<T>(r << sc, i << sc); }
   template<typename T0> const vector2<T>& operator>>(const T0& sc) const { return vector2<T>(r >> sc, i >> sc); }
   template<typename T0> const bool& operator&&(const T0& sc) const { return (r && sc) || (i && sc); }
   template<typename T0> const bool& operator||(const T0& sc) const { return (r || sc) || (i || sc); }

   template<typename T0> const vector2<T>& operator* () const { return vector2<T>(*r, *i); }
   template<typename T0> const vector2<T>& operator- () const { return vector2<T>(-r, -i); }
   const bool& operator!() const { return !(r || i); } operator bool() const { return (r || i); }

   T& operator[](bool ID)  { return ID ? i : r; }
   const T& operator[](bool ID) const { return ID ? i : r; }

   template<typename T0> operator vector2<T0>() const { return {r, i }; }
};

Pages: [1]