Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Rect_ operators overloading suggestion
Rect_ operators overloading suggestion [message #13412] Fri, 04 January 2008 18:25 Go to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
I would like to make a suggestion. I may have missed an important point so my suggestion would not make sense; don't hesitate to blame me for that. Smile

I can see these overloads:
Rect_& operator+=(Sz sz){ Offset(sz); return *this; }
Rect_& operator+=(Pt p) { Offset(p); return *this; }
[...]
Rect_& operator-=(Sz sz){ Offset(-sz); return *this; }
Rect_& operator-=(Pt p) { Offset(-p); return *this; }

I agree with the Pt-argumented functions but I think it would make more sense for Sz-argumented functions to modify the size of the Rectangle instead of translating it...

For example, the following code could be used (I've not tested it):
Rect_& operator+=(Sz sz){ SetSize(Size()+sz); return *this; }
[...]
Rect_& operator-=(Sz sz){ SetSize(Size()-sz); return *this; }

What do you think about it ?

regards,
Lionel
Re: Rect_ operators overloading suggestion [message #13426 is a reply to message #13412] Sat, 05 January 2008 11:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chickenk wrote on Fri, 04 January 2008 12:25

I would like to make a suggestion. I may have missed an important point so my suggestion would not make sense; don't hesitate to blame me for that. Smile

I can see these overloads:
Rect_& operator+=(Sz sz){ Offset(sz); return *this; }
Rect_& operator+=(Pt p) { Offset(p); return *this; }
[...]
Rect_& operator-=(Sz sz){ Offset(-sz); return *this; }
Rect_& operator-=(Pt p) { Offset(-p); return *this; }

I agree with the Pt-argumented functions but I think it would make more sense for Sz-argumented functions to modify the size of the Rectangle instead of translating it...

For example, the following code could be used (I've not tested it):
Rect_& operator+=(Sz sz){ SetSize(Size()+sz); return *this; }
[...]
Rect_& operator-=(Sz sz){ SetSize(Size()-sz); return *this; }

What do you think about it ?

regards,
Lionel



I think this classically ambiguos case.... I see good reasons for current overload as well for the proposed one...

Mirek
Re: Rect_ operators overloading suggestion [message #13431 is a reply to message #13426] Sat, 05 January 2008 20:04 Go to previous messageGo to next message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
Thank you Mirek for your answer.

Unless it is too personal Wink I'd like to know about the reasons for current implementation. It would fill an empty space in my brain Smile

Thanks a lot
Lionel
Re: Rect_ operators overloading suggestion [message #13432 is a reply to message #13431] Sat, 05 January 2008 23:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chickenk wrote on Sat, 05 January 2008 14:04

Thank you Mirek for your answer.

Unless it is too personal Wink I'd like to know about the reasons for current implementation. It would fill an empty space in my brain Smile

Thanks a lot
Lionel


Well, Size can also have "offset" meaning. Adding Size to top-left point of Rect you get bottom-right point. Therefore it seems logical to interpret adding a Size as offset.

Meanwhile, r.Inflate(sz) is not much more verbose and certainly has quite clear meaning Smile

Mirek

[Updated on: Sat, 05 January 2008 23:29]

Report message to a moderator

Re: Rect_ operators overloading suggestion [message #13433 is a reply to message #13432] Sat, 05 January 2008 23:44 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
BTW, in CAD terminology 'offset' would mean 'inflate' or 'deflate', not 'move' as upp interpretation Very Happy
I got half an hour to get the upp meaning Embarassed

Ciao

Max
Re: Rect_ operators overloading suggestion [message #13439 is a reply to message #13432] Sun, 06 January 2008 18:57 Go to previous message
chickenk is currently offline  chickenk
Messages: 169
Registered: May 2007
Location: Grenoble, France
Experienced Member
Well before reading your answer I ended up using Deflate/Inflate actually. It makes my code nicely readable indeed. That's really enough for my needs, at least for now !

Thank you for your explanation.

Lionel
Previous Topic: A couple of issues with a test app
Next Topic: Dynamic Variable Names
Goto Forum:
  


Current Time: Fri Mar 29 03:21:04 CET 2024

Total time taken to generate the page: 0.01376 seconds