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

Author Topic: Why SFML's vectors are really dump?  (Read 7260 times)

0 Members and 1 Guest are viewing this topic.

lineBreaker

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
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 }; }
};

lineBreaker

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Also:
« Reply #1 on: October 31, 2021, 09:20:20 am »
If you want a I can make vector3, and vector4 for donating you. It would not be a throuble for me. I can complate them within one week.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Why SFML's vectors are really dump?
« Reply #2 on: November 02, 2021, 10:41:15 am »
You can find a lot of discussions about SFML's vector and rect classes already on the forum.

Some common arguments you'll find, may include:
  • Multiplication of two vectors can have different meanings: Dot product, cross product, etc.
  • The scope of the classes are defined by the usage within SFML
  • SFML isn't trying to be a math library, that would break the scope and there are way better libraries for that
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

lineBreaker

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Why SFML's vectors are really dump?
« Reply #3 on: November 02, 2021, 02:24:21 pm »
You can find a lot of discussions about SFML's vector and rect classes already on the forum.

Multiplication of two vectors can have different meanings:
Dot product, cross product
So will you add those ready code?

« Last Edit: November 04, 2021, 05:24:13 am by lineBreaker »

 

anything