• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: Maths Calculation Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Maths Calculation Problem


  • Subject: Fwd: Maths Calculation Problem
  • From: "Mark J. Reed" <email@hidden>
  • Date: Fri, 14 Nov 2008 16:29:19 -0500

Whups, Yvan pointed out that my original reply didn't go to the list.  Apologies.  Here it is.

---------- Forwarded message ----------
From: Mark J. Reed <email@hidden>
Date: Fri, Nov 14, 2008 at 12:34 PM
Subject: Re: Maths Calculation Problem
To: Simon Topliss <email@hidden>


On Fri, Nov 14, 2008 at 12:10 PM, Simon Topliss <email@hidden> wrote:
Object 1: bounds: {523.7314453125, 520.07958984375, 750.03515625, 464.88330078125}, width: 226.3037109375, height: 55.1962890625.
Object 2: bounds: {501.5654296875, 569.4541015625, 738.6728515625, 514.2578125}, width: 237.107421875, height: 55.1962890625.

A surplus of information!  It appears these are just rectangles; object one has one corner at (523.7314453125, 520.07958984375) and another at (750.03515625,464.88330078125) - crazily-precise units, I must say; object two has one corner at (501.5654296875, 569.4541015625) and another at (738.6728515625, 514.2578125).  The width and height are calculated for you, but you could easily do it yourself with subtraction (750.03515625 - 523.7314453125 = 226.3037109375, etc).

How would I write the AppleScript function to return true if they do intersect and false if they don't?

The easiest way is to determine if they intersect is to ask what it means for them *not* to intersect and return false for those cases, otherwise true.  This should do the trick:

on testIntersection(rect1, rect2)

set {left1, top1, right1, bottom1} to bounds of rect1

set {left2, top2, right2, bottom2} to bounds of rect2

if left1 > right1 then

set {left1, right1} to {right1, left1}

end if

if top1 > bottom1 then

set {top1, bottom1} to {bottom1, top1}

end if

if left2 > right2 then

set {left2, right2} to {right2, left2}

end if

if top2 > bottom2 then

set {top2, bottom2} to {bottom2, top2}

end if

if left1 > right2 then return false

if left2 > right1 then return false

if top1 > bottom2 then return false

if top2 > bottom1 then return false

return true

end testIntersection


set Object1 to {bounds:{523.7314453125, 520.07958984375, 750.03515625, 464.88330078125}, width:226.3037109375, height:55.1962890625}

set Object2 to {bounds:{501.5654296875, 569.4541015625, 738.6728515625, 514.2578125}, width:237.107421875, height:55.1962890625}


testIntersection(Object1, Object2)


--
Mark J. Reed <email@hidden>




--
Mark J. Reed <email@hidden>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Maths Calculation Problem (From: Simon Topliss <email@hidden>)

  • Prev by Date: Re: Maths Calculation Problem
  • Next by Date: Rép: Maths Calculation Problem
  • Previous by thread: Re: Maths Calculation Problem
  • Next by thread: Re: create duplicate event in iCal
  • Index(es):
    • Date
    • Thread