Results 1 to 7 of 7

Thread: Why doesn't QPointF have a norm function?

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Why doesn't QPointF have a norm function?

    I find it so annoying that when working with QPointF objects I always have to type out the Euklidean norm or transform it to some other object or to find a whatever workaround for something so simple and obvious. It has a (in my opinion mostly useless) manhattan norm. Why can't it just have a norm() function as well?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why doesn't QPointF have a norm function?

    Can you explain what you mean by "norm" in this context? QPointF is supposed to be a pair of coordinates, nothing more, nothing less.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Why doesn't QPointF have a norm function?

    Cruz means the Euclidean norm, aka length, of the the vector... if QPointF represented a vector. QVector2D, which as its name suggests represents a 2d vector, has a length() function that returns what Cruz is expecting (at a cost), and other functions supporting the mathematical notion of a vector.

    The "mostly useless" manhattan length is used as a fast, approximate measure of distance between points for UI purposes like the one described in the doc for QPoint::manhattanLength(). Such operations are as common as muck in any GUI.

  4. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why doesn't QPointF have a norm function?

    I don't know about "any gui". I have written plenty and never used the manhattan distance before. I do, however, frequently feel the need to calculate the distance between the mouse pointer and something else and I also have the extra nanosecond to spare to evaluate a square root to get the real thing instead of an approximation. I just don't understand why somebody would bother to include a method to calculate the manhattan distance and "forget" about the much more common euklidean norm. If a square root is too slow for you for some obscure reason, you can still use the manhattan length, but why make life harder for every day QPointF users who just want to evaluate a natural, circular shaped distance and not provide a plain vanilla norm()?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why doesn't QPointF have a norm function?

    Quote Originally Posted by Cruz View Post
    I don't know about "any gui". I have written plenty and never used the manhattan distance before. I do, however, frequently feel the need to calculate the distance between the mouse pointer and something else and I also have the extra nanosecond to spare to evaluate a square root to get the real thing instead of an approximation. I just don't understand why somebody would bother to include a method to calculate the manhattan distance and "forget" about the much more common euklidean norm. If a square root is too slow for you for some obscure reason, you can still use the manhattan length, but why make life harder for every day QPointF users who just want to evaluate a natural, circular shaped distance and not provide a plain vanilla norm()?
    Manhattan distance is more commonly used than you think. Usually it is a good enough approximation of 2D (or actually N-D) length, especially for small distances. It is used by Qt (probably among other things) to evaluate whether a mouse movement is big enough that it should start a drag operation and probably this is why it was included in QPoint API. Qt doesn't have any use for Euclidean distance with QPoint (it's quite slow to calculate, contrary to what you may think -- remember not every computer is powered by a GHz processor) and thus it was not included in the API.

    For more info read about Minkowski distance.

    If you frequently do something and you have nanoseconds to spare then writing a function that does it should not pose a problem. You could even spend some extra nanoseconds and contribute that function to Qt.

    By the way, it is quite similar to avoiding calculating sine value for small angles by approximating the result with the angle itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why doesn't QPointF have a norm function?

    I happen to be looking for the same function today. I know it is not that hard to come up with your own sqrt on sum of power of 2. The disappointment is why such a common utility function is missing in qt.

  7. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why doesn't QPointF have a norm function?

    Quote Originally Posted by Cruz View Post
    I do, however, frequently feel the need to calculate the distance between the mouse pointer and something else ...
    This would be QLineF( pos1, pos2 ).length().

    Uwe

  8. The following user says thank you to Uwe for this useful post:

    embeddedmz (18th August 2022)

Similar Threads

  1. QComboBox Signals doesn't invoke the called function
    By ladiesfinger in forum Qt Programming
    Replies: 6
    Last Post: 30th December 2010, 16:20
  2. QPointF == operator usage
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2010, 08:41
  3. QPointF equality operator
    By jenova_project in forum Newbie
    Replies: 1
    Last Post: 22nd September 2008, 16:42
  4. QPointF transformation
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 10:11
  5. qSort doesn't work with member function
    By ber_44 in forum Qt Programming
    Replies: 10
    Last Post: 2nd June 2007, 12:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.