PDA

View Full Version : Value compare - close enough?


Mathieson
12-11-2009, 05:47 PM
I vaguely remember mention of some method along the lines of "closeEnough" to get around Max's rounding issues when comparing values. I'm trying to find it in the reference and on here, but am not having any luck. Does something like this actually exist, or did I just imagine it in some kind of wonderful dream?

I can write up a quick function, if needed, but it would be good to know if there is already something ready to go. Maybe I'm just not looking in the right place.

Thanks!

j-man
12-11-2009, 06:17 PM
Hi Mathieson,

I'm not sure I understand, are you looking to compare two values or two lines?

This is the post regarding calculation a line / line intersection:

http://forums.cgsociety.org/showpost.php?p=3398267&postcount=3

J.

Mathieson
12-11-2009, 06:35 PM
Nope, just regular old values (although I just bookmarked that thread.. looks like a good one to have on file!)

I am running into the problem right now that usually appears when trying to compare color values, but it is happening with point3 values at the moment. I print the values to the listener and it shows both are equal, but then a formatted print shows they are not equal after the 6th or 7th decimal place.

I've written small functions to get around this in the past, but I thought I remembered some sort of "closeEnough" comparison method mentioned somewhere and thought I would double check it. I could just be going crazy though.

labbejason
12-11-2009, 06:40 PM
Mat, check out close_enough in the reference. It was implemented in 2008.

Mathieson
12-11-2009, 06:45 PM
Ah, awesome. For some reason searching for "close enough" doesn't return it, and it doesn't seem to be on the page talking about comparing values. At least I know my memory isn't going on me yet. Thanks Jay!

Bobo
12-11-2009, 07:00 PM
Ah, awesome. For some reason searching for "close enough" doesn't return it, and it doesn't seem to be on the page talking about comparing values. At least I know my memory isn't going on me yet. Thanks Jay!

Stupid CHM Search Engline :)
I will add the words "close enough" in the description of the method so it would appear in the full text Search...

Typing "close" in the Index shows "close_enough" near the top of the list.

Mathieson
12-14-2009, 02:47 PM
Stupid CHM Search Engline :)
I will add the words "close enough" in the description of the method so it would appear in the full text Search...

Typing "close" in the Index shows "close_enough" near the top of the list.
I actually can't believe I didn't spot it in the index! I went and checked again immediately after Jay's response, then hung my head in shame. I guess I didn't have much faith in what I thought it might be called and ended up looking right past it. There should be a face-palm smiley on CGTalk for moments like this! haha

LoneRobot
12-14-2009, 03:41 PM
maybe your search terms were not close enough, mat? :-D

Bobo
12-15-2009, 12:18 AM
maybe your search terms were not close enough, mat? :-D

Nope. I tested in 2010 and in the current WIP build - the old one only found two irrelevant topics that contain the words. The new build finds 5 topics, the 4th is the Number Values where the method is documented. This is either because I removed the _ from the title so it now contains the words "close enough" with a space, or because I had to switch the authoring environment for various technical reasons (or both).

So in the next Max version this should be "fixed".
(Another side effect from switching the software is that the new build finally remembers its position and size between sessions).

Mathieson
12-15-2009, 02:53 PM
maybe your search terms were not close enough, mat? :-D
LOL.. The pun police are going to be out in full force after that one! Very subtle. Well played Pete haha. :beer:

TzMtN
12-15-2009, 03:30 PM
you've mentioned the need to check if two point3 values are close enough,
so here is a different way to do this that I like to use:


fn closeEnoughPoint3 p1 p2 thresh =
(
distance (p1 as point3) (p2 as point3) < thresh
)


I'm casting p1 and p2 to point3 so that this function will also work with color values.

Mathieson
12-15-2009, 03:35 PM
Very cool. I like that solution. Nice and simple. Much more elegant than what I have been doing. Thanks for sharing that Matan.

biddle
12-16-2009, 03:52 PM
<off topic, search related>

When you are pretty sure there is something in MXS lexicon that you need, and the help index is no help, 'apropos' is your friend. It is often better at matching partial words.

Running:

apropos "enou"

generates:

close_enough (const Primitive): close_enough()

...which you can then feed back into the help search dialog to find the correct location.

Mathieson
12-16-2009, 06:29 PM
Good tip, thanks Mike. I had forgotten about apropos. Seen it in the help so many times, but whenever a good chance to use it comes up I totally forget about it.

Another one I like is <superclass>.classes.. ie. modifier.classes or positioncontroller.classes.. I've used that a few times when I couldn't quite remember the name of a class I was thinking of. Also used it a few times to populate UI controls with entire class collections, rather than typing them all out by hand in an array.

CGTalk Moderation
12-16-2009, 06:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.