Notifications
Clear all

[Closed] Value compare – close enough?

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!

13 Replies

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.

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.

Mat, check out close_enough in the reference. It was implemented in 2008.

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!

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

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

maybe your search terms were not close enough, mat?

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).

LOL… The pun police are going to be out in full force after that one! Very subtle. Well played Pete haha.

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.

Page 1 / 2