I would have thought that the value should be 100% as well, since the array of 
points tested is within the rect of the object, not the colored part.


I tried something like this a while ago, where I filled a polygon with a color, 
and tested whether the pixelColor was white or not. Interestingly, the color 
RGB values are not constant, because, I assume, a certain color "blue", say, is 
a blend of others.


But it should be possible to do this, perhaps having to make sure that adjacent 
pixels are white, or maybe even three in a row, and then you are sure you are 
out of the visual colored polygon and in the white rect itself. Then you can 
compare the white with the color, and get the ratio.


Craig Newman



-----Original Message-----
From: Dar Scott <d...@swcp.com>
To: How to use LiveCode <use-livecode@lists.runrev.com>
Sent: Thu, Jun 6, 2013 9:07 pm
Subject: Re: Polygon's share of its rectangle inconsistent?


I'm doing something wrong.

I tried your function and I get almost 100%.  The function within seems to work 
on the bounding rectangle not the shape.

With this mod, I do get 100 percent:

function coverage obLID
  set the filled of obLID to true
  put the rect of obLID into r
  repeat with x = (item 1 of r) to (item 3 of r)-1
     repeat with y = (item 2 of r) to (item 4 of r)-1
        put x,y into pt
        if within(obLID,pt) then add 1 to isIn
        add 1 to all
     end repeat
  end repeat
  return isIn/all
end coverage

I subtracted 1 from the right and bottom.

Dar


On Jun 6, 2013, at 5:39 PM, David Epstein wrote:

> In order to properly adjust the relative area of two dissimilar polygons, I 
thought I would use a function to determine the fraction of each polygon's 
rectangle that is covered by the polygon.
> 
> function coverage obLID
>   set the filled of obLID to true
>   put the rect of obLID into r
>   repeat with x = (item 1 of r) to (item 3 of r)
>      repeat with y = (item 2 of r) to (item 4 of r)
>         put x,y into pt
>         if within(obLID,pt) then add 1 to isIn
>         add 1 to all
>      end repeat
>   end repeat
>   return isIn/all
> end coverage
> 
> This seems to work as expected, but I am perplexed by the fact that when I 
resize an object keeping its proportions constant (drag a corner with the shift 
key down; or script this) I get a surprising variation in the result.  E.g., a 
fairly simple shape I tried went from 0.48 coverage up to 0.59 coverage when I 
shrank its dimensions by about two-thirds.  With tens or hundreds of thousands 
of pixels being sampled in the calculation, I would not expect this variation.
> 
> Many thanks for any insights or suggestions.
> 
> David Epstein
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to