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

Author Topic: Vector's equality and inequality operators  (Read 2848 times)

0 Members and 1 Guest are viewing this topic.

Riyadh International

  • Newbie
  • *
  • Posts: 1
    • View Profile
Vector's equality and inequality operators
« on: September 12, 2011, 08:43:44 am »
Hello everybody. Thanks for SFML loking forward to new release and more tutorials like Joystick.

Anyway I see this in Vector2.inl and Vector3.inl:
Code: [Select]

template <typename T>
bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2)
{
    return (V1.x == V2.x) && (V1.y == V2.y);
}


template <typename T>
bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2)
{
    return (V1.x != V2.x) || (V1.y != V2.y);
}

template <typename T>
bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2)
{
    return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z);
}

template <typename T>
bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2)
{
    return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z);
}


This will not work reliable for Floats but only Integers.
I found article which helped me and maybe you too:
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Vector's equality and inequality operators
« Reply #1 on: September 12, 2011, 08:58:21 am »
I know. But it's up to users to define how they want to compare their float vectors, if they want to use a delta. SFML only provides the "strict" operator==, like the language provides the strict operator== for float and double types.
Laurent Gomila - SFML developer

Silvah

  • Guest
Re: Vector's equality and inequality operators
« Reply #2 on: September 12, 2011, 05:51:38 pm »
Quote from: "Riyadh International"
This will not work reliable for Floats but only Integers.
This will work reliably for floats. I'm using operator== when I want to check if two things are equal, not "almost equal". So there's nothing wrong with that code.

Quote from: "Laurent"
But it's up to users to define how they want to compare their float vectors, if they want to use a delta.
Actually, it's called epsilon, not delta ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Vector's equality and inequality operators
« Reply #3 on: September 12, 2011, 06:00:47 pm »
Quote
Actually, it's called epsilon, not delta

Oh, I didn't know that there was a strict naming for this. But actually I always use "epsilon", don't know why I chose "delta" this time :lol:
Laurent Gomila - SFML developer

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Vector's equality and inequality operators
« Reply #4 on: September 12, 2011, 09:18:47 pm »
Quote from: "Laurent"
Quote
Actually, it's called epsilon, not delta

Oh, I didn't know that there was a strict naming for this. But actually I always use "epsilon", don't know why I chose "delta" this time :lol:
Epsilon is a mathematics term which refers to an infinitesimally small positive number whose square is 0. Delta refers to a change in a number. So yes, it's kind of strict and delta is definitely the wrong term.
Sorry, math geek here.
I use the latest build of SFML2