> snappedX = userCoord.x*Math.round( gridSizeX/gridSizeX );
>
> Which makes a lot more sense than what I said before.
well, not really - gridSizeX/gridSizeX will always be 1 (except if
gridSizeX is zero ...), so let me try again - here's my solution ;-)
snappedX = Math.round(userCoord.x/gridSizeX)*gridSizeX
example 1:
gridSizeX = 1
userCoord.x = 12.5
Math.round(userCoord.x/gridSizeX) = 13
snappedX = 13*1 = 13
example 2:
gridSizeX = 5
userCoord.x = 12.5
Math.round(userCoord.x/gridSizeX) = 3
snappedX = 3*5 = 15
example 3:
gridSizeX = 3.365
userCoord.x = 12.5
Math.round(userCoord.x/gridSizeX) = 4
snappedX = 4*3.365 = 13.46
i think this should be correct, is it?
klaus
G. Wade Johnson wrote:
> Thanks for pointing out that I shouldn't snap off a reply early in the
> morning. Obviously I meant
>
> snappedX = userCoord.x*Math.round( gridSizeX/gridSizeX );
>
> Which makes a lot more sense than what I said before.
>
> G. Wade
>
> On Thu, 17 Nov 2005 13:08:50 +0000
> Martyn Eggleton <[EMAIL PROTECTED]> wrote:
>
>
>>G. Wade Johnson wrote:
>>
>>>Sorry to break in on this, but ...
>>>
>>>On Thu, 17 Nov 2005 10:34:18 +0000
>>>Martyn Eggleton <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>
>>>>Ok I'll try (forgive if i end up patronising or not clear)
>>>>
>>>>
>>>
>>>[snip]
>>>
>>>
>>>
>>>>function mousemove(evt)
>>>>{
>>>>
>>>> var gridSizeX = 1; //The length of each element of the grid in the
>>>>userCordinate space, 0 is now snapping;
>>>> var gridSizeY= 1;
>>>> var userCoord = getUserCoordinate(evt.ClientX, evt.ClientY) //you
>>>>will either have your own getUserCoordinate equivelant or go look one up
>>>>(eg kevlindev), I'm assuming it returns a point);
>>>> var snappedX = userCoord.x;
>>>> var snappedY = userCoord.y;
>>>>
>>>> if (gridSizeX)
>>>> {
>>>> snappedX = Math.round(userCoord.x*gridSizeX)/gridSizeX;
>>>>
>>>
>>>shouldn't this be
>>>
>>> snappedX = Math.round( userCoord.x*gridSizeX/gridSizeX );
>>>
>>>You want to round after the divide.
>>>
>>
>>Sorry but mathatically that its the same as
>>
>>snappedX = Math.round( userCoord.x);
>>
>>which doesn't allow you to specify the gridSizre at all
>>
>>
>>
>>>
>>>
>>>> }
>>>>
>>>> if (gridSizeY)
>>>> {
>>>> snappedY = Math.round(userCoord.y*gridSizeY)/gridSizeY;
>>>>
>>>
>>>And, equivalently,
>>>
>>> snappedY = Math.round( userCoord.y*gridSizeY/gridSizeY );
>>>
>>>
>>>
>>>> }
>>>>
>>>> // do what you want from here on out.
>>>>
>>>>}
>>>>
>>>
>>>G. Wade
>>>
>>>
>>
>>
>>
>>[Non-text portions of this message have been removed]
>>
>>
>>
>>
>>-----
>>To unsubscribe send a message to: [EMAIL PROTECTED]
>>-or-
>>visit http://groups.yahoo.com/group/svg-developers and click "edit my
>>membership"----
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>
>
>
--
O-.
/_ )
| (U
klaus* /|
/ /
~ ~
------------------------ Yahoo! Groups Sponsor --------------------~-->
AIDS in India: A "lurking bomb." Click and help stop AIDS now.
http://us.click.yahoo.com/VpTY2A/lzNLAA/yQLSAA/1U_rlB/TM
--------------------------------------------------------------------~->
-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my
membership"
----
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/