Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.86.mcz ==================== Summary ==================== Name: Graphics-nice.86 Author: nice Time: 31 October 2009, 3:13:31 am UUID: 67835c13-ecca-4ff8-8635-e8f15d789607 Ancestors: Graphics-nice.85 while at arcTan: fix 2 ULP in Float theta Note that Float theta is in [0,2*pi[ while arcTan: is in [-pi,pi] (0@0) theta leads to pi/2 instead of 0 for new version of arcTan: (pi for old version) #arcTan: does handle case of negativeZero, #theta doesn't =============== Diff against Graphics-nice.85 =============== Item was changed: ----- Method: Point>>theta (in category 'polar coordinates') ----- theta "Answer the angle the receiver makes with origin in radians. right is 0; down is 90. Corrected the constants from single precision to 64 Bit precision and changed the sends in case of overflow to constants HK 2005-07-23" | tan theta | x = 0 ifTrue: [y >= 0 + ifTrue: [^ 1.5707963267948966 "90.0 degreesToRadians"] - ifTrue: [^ 1.570796326794897 "90.0 degreesToRadians"] ifFalse: [^ 4.71238898038469 "270.0 degreesToRadians"]] ifFalse: [tan := y asFloat / x asFloat. theta := tan arcTan. x >= 0 ifTrue: [y >= 0 ifTrue: [^theta] ifFalse: [^"360.0 degreesToRadians" 6.283185307179586 + theta]] ifFalse: [^"180.0 degreesToRadians" 3.141592653589793 + theta]]! |
Note that more variants of this code are found in
Complex>>#arg Point>>#degrees this one was probably unnecessary, ^self theta radiansToDegrees would be as accurate knowing that {Float halfPi radiansToDegrees - 90. Float pi radiansToDegrees - 180. (Float pi + Float halfPi) radiansToDegrees - 270. Float twoPi radiansToDegrees - 360} allSatisfy: [:e | e = 0] Point>>#bearingToPoint: (same as degrees but shifted 90° counterclockwise just to have 0° at north - that is upscreen). 2009/10/31 <[hidden email]>: > Nicolas Cellier uploaded a new version of Graphics to project The Trunk: > http://source.squeak.org/trunk/Graphics-nice.86.mcz > > ==================== Summary ==================== > > Name: Graphics-nice.86 > Author: nice > Time: 31 October 2009, 3:13:31 am > UUID: 67835c13-ecca-4ff8-8635-e8f15d789607 > Ancestors: Graphics-nice.85 > > while at arcTan: fix 2 ULP in Float theta > Note that Float theta is in [0,2*pi[ while arcTan: is in [-pi,pi] > (0@0) theta leads to pi/2 instead of 0 for new version of arcTan: (pi for old version) > #arcTan: does handle case of negativeZero, #theta doesn't > > > =============== Diff against Graphics-nice.85 =============== > > Item was changed: > ----- Method: Point>>theta (in category 'polar coordinates') ----- > theta > "Answer the angle the receiver makes with origin in radians. right is 0; > down is 90. > Corrected the constants from single precision to 64 Bit precision > and changed the sends in case of overflow to constants HK 2005-07-23" > > | tan theta | > x = 0 > ifTrue: [y >= 0 > + ifTrue: [^ 1.5707963267948966 "90.0 degreesToRadians"] > - ifTrue: [^ 1.570796326794897 "90.0 degreesToRadians"] > ifFalse: [^ 4.71238898038469 "270.0 degreesToRadians"]] > ifFalse: > [tan := y asFloat / x asFloat. > theta := tan arcTan. > x >= 0 > ifTrue: [y >= 0 > ifTrue: [^theta] > ifFalse: [^"360.0 degreesToRadians" 6.283185307179586 + theta]] > ifFalse: [^"180.0 degreesToRadians" 3.141592653589793 + theta]]! > > > |
Free forum by Nabble | Edit this page |