Date: Wed, 25 Oct 1995 09:40:45 EDT From: John Dowdell <71333.42@compuserve.com> Subject: Re: How To:Make a list a RectPeter Wolf writes on Oct 24,
"I need to make a list of 4 items [2,3,4,5] be seen by lingo as a rect(2,3,4,5) so that ilk(list,#rect) = 1. If I can do this simply, I can quickly assess a intersect btw 2 rects (if intersect RectA,RectB then ...). Although this should be easy (and probably is) I can't seem to find it. Right now I'm having to parse it up into 4 variables, (LT,TOP,RT,BOT) and then set myRect = rect(LT,TOP,RT,BOT) . This just takes too long. Unfortunately, I can't seem to make that work with something like "set myRect = rect(mylist)", (it wants to see 4 paramenters) or even "set myRect = "rect" & "(" & myList & "(" ", which returns a string - again not useful. Any ideas?"Bit of obscura here. Rects are related to 4-element property lists: you can refer to "the right of rectA" and such. (Points are related to 2-element property lists, and you can get and set the "locV of pt1".) Lists and rects are still slightly different critters though, as an "ilk" test shows.
(Note on "ilk": There was a typo in the first printing of the Lingo Dictionary, and it should be "#propList", not "#propertyList".) Lists and rects can be used in the same arithmetic operation, as can lists and points, or rects and integers. There are some rules:
-- When an integer is applied to a list of any type, then the integer is a scalar and is applied to all elements individually:
set rectA to rect(0, 0, 320, 240) put rectA + 50 -- rect(50, 50, 370, 290) put rectA / 2 -- rect(0, 0, 160, 120)-- When two lists of the same type and same count are arithmetically manipulated, then each element maps to its corresponding element in the other list:
set list1 to [10, 20, 30] set list2 to [17, 23, 33] put list1 + list2 -- [27, 43, 63] put list2/list1 -- [1, 1, 1] -- Integer math, not floats set rectA to rect(0, 0, 320, 240) set rectB to rect(10, 30, 20, 40) put rectA - rectB -- rect(-10, -30, 300, 200)-- When two lists of same type but differing count are arithmetically manipulated, then the one with smaller count controls the result:
set list1 to [80, 83, 87, 92, 95] set list2 to [15, 30] put list1 + list2 -- [95, 113] put list2 + list1 -- [95, 113]-- (Here comes the punchline!) When two lists of different type are arithmetically manipulated, then the result is not commutative -- the first argument controls the type:
set list1 to [60, 80, 380, 320] set identityRect to rect(1,1,1,1) put list1 * identityRect -- [80, 83, 87, 92] put identityRect * list1 -- rect(80, 83, 87, 92) -- bingo!-- Property lists get really weird... they make sense, but they're weird:
set propList1 to [#color: 13, #size: 5] put propList1 * 2 -- [#color: 26, #size: 10] set increment to [2, 1] put propList1 + increment -- [#color: [15, 14], #size: [7, 6]] -- matrix set propList2 to [#color: 6, #size: 3] put propList1 * propList2 -- [#color: 78, #size: 15] set propList3 to [#neck: 8, #wrists: 11] put propList1 + propList3 -- [#color: 21, #size: 16] put propList3 + propList1 -- [#neck: 21, #wrists: 16] -- first element controls propsSo the key for this issue of "how to make a list a rect?" would be to have this list arithmetically modify an existing rect, as in "set myNewRect to rect(0,0,0,0) + myOld4elementList".
Fun?