dimension2d has a operator+, +=. and -= but no - ?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

dimension2d has a operator+, +=. and -= but no - ?

Post by DtD »

I just noticed that irr::core::dimension2d< T > has no operator- but it does have operator-= and operator+= always has a operator+ so why no operator- ?

~DtD
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

IMO, most classes that have operator X= should have the similar operator X (where X is one of the C/C++ binary arithmetic operators). There are some special cases where you might not want them all, but this is not one of them.

Travis
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I agree. Doing something like "ares->getDriver()->getScreenSize()+core::dimension2ds(-40,-40)" works but it looks off and would not work with non-signed dimensions if you ever used them.

~DtD
In case sombody is confused by my snipet, ares it my game engine and dimension2ds is just a typecase of dimension2d<s32>
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Especially since the standard recommends implementing one with the other...
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I made a function for operator- for dimension2d just add it after operator+ in dimension2d.h on line 99.

Code: Select all

			//! Subtract two dimensions
			dimension2d<T> operator-(const dimension2d<T>& other) const
			{
				return dimension2d<T>(Width-other.Width, Height-other.Height);
			}
~DtD
Post Reply