From 74431972d81792c1e64036b9cfc14cf126607de0 Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Sat, 21 Apr 2012 10:12:20 -0400 Subject: [PATCH 1/2] added missing LOG math global and replaced any math. with correspoinding global --- AppKit/CPGeometry.j | 16 ++++---- AppKit/CPShadow.j | 2 +- AppKit/CPStepper.j | 4 +- AppKit/CoreGraphics/CGContextCanvas.j | 2 +- Foundation/CPCharacterSet.j | 2 +- Objective-J/Constants.js | 1 + Tests/AppKit/CGAffineTransformTest.j | 38 +++++++++---------- Tests/AppKit/CPColorTest.j | 8 ++-- Tests/AppKit/CPTableViewTest.j | 6 +-- Tests/Foundation/CPDateTest.j | 2 +- Tests/Manual/CPFormatterTest/AppController.j | 2 +- Tests/Manual/LoadTimeTest/AppController.j | 10 ++--- Tests/Manual/NSBoxTest/AppController.j | 4 +- Tests/Manual/PlatformWindows/AppController.j | 2 +- .../Preprocessor/BehaviorTests/MethodTest.j | 2 +- 15 files changed, 51 insertions(+), 50 deletions(-) diff --git a/AppKit/CPGeometry.j b/AppKit/CPGeometry.j index 599e0a3851..7e7fa2079b 100644 --- a/AppKit/CPGeometry.j +++ b/AppKit/CPGeometry.j @@ -96,12 +96,12 @@ function CPRectIntegral(aRect) function CPRectIntersection(lhsRect, rhsRect) { var intersection = CPRectMake( - Math.max(CPRectGetMinX(lhsRect), CPRectGetMinX(rhsRect)), - Math.max(CPRectGetMinY(lhsRect), CPRectGetMinY(rhsRect)), + MAX(CPRectGetMinX(lhsRect), CPRectGetMinX(rhsRect)), + MAX(CPRectGetMinY(lhsRect), CPRectGetMinY(rhsRect)), 0, 0); - intersection.size.width = Math.min(CPRectGetMaxX(lhsRect), CPRectGetMaxX(rhsRect)) - CPRectGetMinX(intersection); - intersection.size.height = Math.min(CPRectGetMaxY(lhsRect), CPRectGetMaxY(rhsRect)) - CPRectGetMinY(intersection); + intersection.size.width = MIN(CPRectGetMaxX(lhsRect), CPRectGetMaxX(rhsRect)) - CPRectGetMinX(intersection); + intersection.size.height = MIN(CPRectGetMaxY(lhsRect), CPRectGetMaxY(rhsRect)) - CPRectGetMinY(intersection); return CPRectIsEmpty(intersection) ? CPRectMakeZero() : intersection; } @@ -179,10 +179,10 @@ function CPRectStandardize(aRect) */ function CPRectUnion(lhsRect, rhsRect) { - var minX = Math.min(CPRectGetMinX(lhsRect), CPRectGetMinX(rhsRect)), - minY = Math.min(CPRectGetMinY(lhsRect), CPRectGetMinY(rhsRect)), - maxX = Math.max(CPRectGetMaxX(lhsRect), CPRectGetMaxX(rhsRect)), - maxY = Math.max(CPRectGetMaxY(lhsRect), CPRectGetMaxY(rhsRect)); + var minX = MIN(CPRectGetMinX(lhsRect), CPRectGetMinX(rhsRect)), + minY = MIN(CPRectGetMinY(lhsRect), CPRectGetMinY(rhsRect)), + maxX = MAX(CPRectGetMaxX(lhsRect), CPRectGetMaxX(rhsRect)), + maxY = MAX(CPRectGetMaxY(lhsRect), CPRectGetMaxY(rhsRect)); return CPRectMake(minX, minY, maxX - minX, maxY - minY); } diff --git a/AppKit/CPShadow.j b/AppKit/CPShadow.j index 325e7b3864..98a3bf0145 100644 --- a/AppKit/CPShadow.j +++ b/AppKit/CPShadow.j @@ -61,7 +61,7 @@ _blurRadius = aBlurRadius; _color = aColor; - _cssString = [_color cssString] + " " + Math.round(anOffset.width) + @"px " + Math.round(anOffset.height) + @"px " + Math.round(_blurRadius) + @"px"; + _cssString = [_color cssString] + " " + ROUND(anOffset.width) + @"px " + ROUND(anOffset.height) + @"px " + ROUND(_blurRadius) + @"px"; } return self; diff --git a/AppKit/CPStepper.j b/AppKit/CPStepper.j index 6ad75afe1a..cd1937e191 100644 --- a/AppKit/CPStepper.j +++ b/AppKit/CPStepper.j @@ -144,8 +144,8 @@ minSize = _CGSizeMake(upSize.width, upSize.height + downSize.height), frame = _CGRectMakeCopy(aFrame); - frame.size.width = Math.max(minSize.width, frame.size.width); - frame.size.height = Math.max(minSize.height, frame.size.height); + frame.size.width = MAX(minSize.width, frame.size.width); + frame.size.height = MAX(minSize.height, frame.size.height); [super setFrame:frame]; } diff --git a/AppKit/CoreGraphics/CGContextCanvas.j b/AppKit/CoreGraphics/CGContextCanvas.j index a6f66fcdaf..5660c9cc3b 100644 --- a/AppKit/CoreGraphics/CGContextCanvas.j +++ b/AppKit/CoreGraphics/CGContextCanvas.j @@ -323,7 +323,7 @@ function CGContextTranslateCTM(aContext, tx, ty) #define rotate_scale(a, b, c, d) \ var sign = (a * d < 0.0 || b * c > 0.0) ? -1.0 : 1.0;\ - a1 = (Math.atan2(sign * b, sign * a) + Math.atan2(-c, d)) / 2.0,\ + a1 = (ATAN2(sign * b, sign * a) + ATAN2(-c, d)) / 2.0,\ cos = COS(a1),\ sin = SIN(a1);\ \ diff --git a/Foundation/CPCharacterSet.j b/Foundation/CPCharacterSet.j index a72cf7c4c5..8a372e0a5b 100644 --- a/Foundation/CPCharacterSet.j +++ b/Foundation/CPCharacterSet.j @@ -255,7 +255,7 @@ var CPCharacterSetInvertedKey = @"CPCharacterSetInvertedKey"; // FIXME: range is undefined... don't know what's supposed to be going on here. // the highest Unicode plane we reach. // (There are 65536 code points in each plane.) - var maxPlane = Math.floor((range.start + range.length - 1) / 65536); // FIXME: should iterate _ranges + var maxPlane = FLOOR((range.start + range.length - 1) / 65536); // FIXME: should iterate _ranges return (plane <= maxPlane); } diff --git a/Objective-J/Constants.js b/Objective-J/Constants.js index 90e26620f2..5182e1d90f 100644 --- a/Objective-J/Constants.js +++ b/Objective-J/Constants.js @@ -64,6 +64,7 @@ GLOBAL(SQRT) = Math.sqrt; GLOBAL(E) = Math.E; GLOBAL(LN2) = Math.LN2; GLOBAL(LN10) = Math.LN10; +GLOBAL(LOG) = Math.LOG; GLOBAL(LOG2E) = Math.LOG2E; GLOBAL(LOG10E) = Math.LOG10E; diff --git a/Tests/AppKit/CGAffineTransformTest.j b/Tests/AppKit/CGAffineTransformTest.j index f1d47a0343..93eadea7dc 100644 --- a/Tests/AppKit/CGAffineTransformTest.j +++ b/Tests/AppKit/CGAffineTransformTest.j @@ -131,8 +131,8 @@ }, "rotation" : { - testdata: CGAffineTransformConcat(CGAffineTransformMakeRotation(Math.PI), - CGAffineTransformMakeRotation(-Math.PI)), + testdata: CGAffineTransformConcat(CGAffineTransformMakeRotation(PI), + CGAffineTransformMakeRotation(-PI)), expdata: CGAffineTransformMakeIdentity() }, }; @@ -234,8 +234,8 @@ }, "rotation" : { - testdata: CGAffineTransformConcat(CGAffineTransformMakeRotation(-Math.PI), - CGAffineTransformMakeRotation(Math.PI)), + testdata: CGAffineTransformConcat(CGAffineTransformMakeRotation(-PI), + CGAffineTransformMakeRotation(PI)), }, }; @@ -262,12 +262,12 @@ }, "rotation" : { - testdata: CGAffineTransformMakeRotation(Math.PI), + testdata: CGAffineTransformMakeRotation(PI), }, // TODO a two-pi rotation is actually identity "2PI rotation is NOT identity?" : { - testdata: CGAffineTransformMakeRotation(Math.PI * 2), + testdata: CGAffineTransformMakeRotation(PI * 2), }, }; @@ -300,8 +300,8 @@ }, "rotation" : { - lhs: CGAffineTransformMakeRotation(Math.PI), - rhs: CGAffineTransformMakeRotation(Math.PI), + lhs: CGAffineTransformMakeRotation(PI), + rhs: CGAffineTransformMakeRotation(PI), expdata: YES }, @@ -373,22 +373,22 @@ }, "rotation - pi" : { - testdata: CGAffineTransformMakeRotation(Math.PI), + testdata: CGAffineTransformMakeRotation(PI), expdata: "{-1, 1.2246467991473532e-16, -1.2246467991473532e-16, -1, 0, 0}" }, "rotation - 2pi" : { - testdata: CGAffineTransformMakeRotation(2 * Math.PI), + testdata: CGAffineTransformMakeRotation(2 * PI), expdata: "{1, -2.4492935982947064e-16, 2.4492935982947064e-16, 1, 0, 0}" }, "rotation - 3pi" : { - testdata: CGAffineTransformMakeRotation(3 * Math.PI), + testdata: CGAffineTransformMakeRotation(3 * PI), expdata: "{-1, 3.6739403974420594e-16, -3.6739403974420594e-16, -1, 0, 0}" }, "scale and translation and rotate" : { - testdata: CGAffineTransformRotate(CGAffineTransformTranslate(CGAffineTransformMakeScale(3,4),5,6),Math.PI), + testdata: CGAffineTransformRotate(CGAffineTransformTranslate(CGAffineTransformMakeScale(3,4),5,6),PI), expdata: "{-3, 4.898587196589413e-16, -3.6739403974420594e-16, -4, 15, 24}" }, }; @@ -401,7 +401,7 @@ - (void)testAffineTransformRotate { - var ang = Math.PI + 0.5 * Math.PI, + var ang = PI + 0.5 * PI, transform = CGAffineTransformMake( 1,2,3,4, 5,6 ), cos = COS(ang), sin = SIN(ang); @@ -417,7 +417,7 @@ }, "rotation negation" : { - testdata: CGAffineTransformRotate(CGAffineTransformRotate(CGAffineTransformMakeScale(3,4),Math.PI),-Math.PI), + testdata: CGAffineTransformRotate(CGAffineTransformRotate(CGAffineTransformMakeScale(3,4),PI),-PI), expdata: CGAffineTransformMakeScale(3,4) } }; @@ -428,7 +428,7 @@ - (void)testAffineTransformInvert { - var transform = CGAffineTransformRotate(CGAffineTransformTranslate(CGAffineTransformMakeScale(3,4),5,6),Math.PI), + var transform = CGAffineTransformRotate(CGAffineTransformTranslate(CGAffineTransformMakeScale(3,4),5,6),PI), determinant = 1 / (transform.a * transform.d - transform.b * transform.c), invertedtransform = CGAffineTransformMake(determinant * transform.d, -determinant * transform.b, @@ -451,8 +451,8 @@ }, "rotation" : { - testdata: CGAffineTransformMakeRotation(-Math.PI), - expdata: CGAffineTransformMakeRotation(Math.PI), + testdata: CGAffineTransformMakeRotation(-PI), + expdata: CGAffineTransformMakeRotation(PI), }, "translation" : { @@ -483,7 +483,7 @@ }, "rotation 90 degrees" : { - testdata: CGRectApplyAffineTransform(rect, CGAffineTransformMakeRotation(Math.PI/2)), + testdata: CGRectApplyAffineTransform(rect, CGAffineTransformMakeRotation(PI/2)), expdata: CGRectMake( -10,3.0000000000000004,6,5 ) }, @@ -498,7 +498,7 @@ }, "rotate, translate and scale" : { - testdata: CGRectApplyAffineTransform(rect, CGAffineTransformRotate(CGAffineTransformTranslate(CGAffineTransformMakeScale(3,4),5,6),Math.PI)), + testdata: CGRectApplyAffineTransform(rect, CGAffineTransformRotate(CGAffineTransformTranslate(CGAffineTransformMakeScale(3,4),5,6),PI)), expdata: CGRectMake( -9.000000000000004, -16, 15.000000000000002, 24.000000000000004 ) }, diff --git a/Tests/AppKit/CPColorTest.j b/Tests/AppKit/CPColorTest.j index 09deb602cb..a0ee065f1a 100644 --- a/Tests/AppKit/CPColorTest.j +++ b/Tests/AppKit/CPColorTest.j @@ -15,10 +15,10 @@ { var rgbaColour = [CPColor colorWithCSSString:@"rgba(32, 64, 128, 0.5)"]; - [self assert:32 equals:Math.round([rgbaColour redComponent] * 255) message:"red component"]; - [self assert:64 equals:Math.round([rgbaColour greenComponent] * 255) message:"green component"]; - [self assert:128 equals:Math.round([rgbaColour blueComponent] * 255) message:"blue component"]; - [self assert:128 equals:Math.round([rgbaColour alphaComponent] * 255) message:"alpha component"]; + [self assert:32 equals:ROUND([rgbaColour redComponent] * 255) message:"red component"]; + [self assert:64 equals:ROUND([rgbaColour greenComponent] * 255) message:"green component"]; + [self assert:128 equals:ROUND([rgbaColour blueComponent] * 255) message:"blue component"]; + [self assert:128 equals:ROUND([rgbaColour alphaComponent] * 255) message:"alpha component"]; } - (void)testIsEqual_ diff --git a/Tests/AppKit/CPTableViewTest.j b/Tests/AppKit/CPTableViewTest.j index 18c776056f..48edb6f4e0 100644 --- a/Tests/AppKit/CPTableViewTest.j +++ b/Tests/AppKit/CPTableViewTest.j @@ -193,7 +193,7 @@ { var view = allViews[i], column = i % 2, - row = startingRow + Math.floor(i / 2); // Two columns per row. + row = startingRow + FLOOR(i / 2); // Two columns per row. //CPLog.error([view stringValue] + " frame: " + CPStringFromRect([tableView convertRect:[view frame] toView:nil])); [self assert:("R" + row + "C" + column) equals:[view stringValue] message:"(" + row + ", " + column + ") string value"]; [self assert:"CustomTextView" + column equals:[[view class] description] message:"(" + row + ", " + column + ") data view"]; @@ -205,11 +205,11 @@ var allViews = AssertCorrectCellsVisible(0), visibleHeight = [tableView visibleRect].size.height, fullRowHeight = [tableView rowHeight] + [tableView intercellSpacing].height, - visibleRows = Math.ceil(visibleHeight / fullRowHeight); + visibleRows = CEIL(visibleHeight / fullRowHeight); [self assert:2 * visibleRows equals:[allViews count] message:"only as many data views as necessary should be present"]; // Now if we scroll down, new views should come in and others should go out. - var rowTwentyFiveAndAHalfY = Math.floor(25.5 * fullRowHeight); + var rowTwentyFiveAndAHalfY = FLOOR(25.5 * fullRowHeight); [tableView scrollPoint:CGPointMake(0, rowTwentyFiveAndAHalfY)]; [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; diff --git a/Tests/Foundation/CPDateTest.j b/Tests/Foundation/CPDateTest.j index 63e0b1a0c6..f4a2859894 100644 --- a/Tests/Foundation/CPDateTest.j +++ b/Tests/Foundation/CPDateTest.j @@ -85,7 +85,7 @@ expectedMinute = 31, offset = -date.getTimezoneOffset(), offsetPositive = offset >= 0, - offsetHours = offsetPositive ? Math.floor(offset / 60) : Math.ceil(offset / 60), + offsetHours = offsetPositive ? FLOOR(offset / 60) : CEIL(offset / 60), offsetMinutes = offset - offsetHours * 60, expectedString; expectedHour += offsetHours; diff --git a/Tests/Manual/CPFormatterTest/AppController.j b/Tests/Manual/CPFormatterTest/AppController.j index 26b42c5953..b1c3728d89 100644 --- a/Tests/Manual/CPFormatterTest/AppController.j +++ b/Tests/Manual/CPFormatterTest/AppController.j @@ -17,7 +17,7 @@ var RecordData = [ var randomFromTo = function(from, to) { - return Math.floor(Math.random() * (to - from + 1) + from); + return FLOOR(RAND() * (to - from + 1) + from); }; @implementation AppController : CPObject diff --git a/Tests/Manual/LoadTimeTest/AppController.j b/Tests/Manual/LoadTimeTest/AppController.j index bdb9a6c305..8430ec74c5 100644 --- a/Tests/Manual/LoadTimeTest/AppController.j +++ b/Tests/Manual/LoadTimeTest/AppController.j @@ -42,12 +42,12 @@ launchAvg /= data.length; for (var i = 0; i < data.length; i++) { - loadStdev += Math.pow(data[i][0] - loadAvg, 2); - launchStdev += Math.pow(data[i][1] - launchAvg, 2); + loadStdev += POW(data[i][0] - loadAvg, 2); + launchStdev += POW(data[i][1] - launchAvg, 2); } - loadStdev = Math.sqrt(loadStdev / data.length); - launchStdev = Math.sqrt(launchStdev / data.length); + loadStdev = SQRT(loadStdev / data.length); + launchStdev = SQRT(launchStdev / data.length); if (window.parent.BCOMM) { window.parent.BCOMM.finishTest({ @@ -63,7 +63,7 @@ var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; - [label setStringValue:"load avg="+Math.round(loadAvg)+" (stdev="+Math.round(loadStdev)+"); launch avg="+Math.round(launchAvg)+" (stdev="+Math.round(launchStdev)+")"]; + [label setStringValue:"load avg="+ROUND(loadAvg)+" (stdev="+ROUND(loadStdev)+"); launch avg="+ROUND(launchAvg)+" (stdev="+ROUND(launchStdev)+")"]; [label setFont:[CPFont boldSystemFontOfSize:24.0]]; [label sizeToFit]; diff --git a/Tests/Manual/NSBoxTest/AppController.j b/Tests/Manual/NSBoxTest/AppController.j index 139bb2501f..720e33dc5a 100644 --- a/Tests/Manual/NSBoxTest/AppController.j +++ b/Tests/Manual/NSBoxTest/AppController.j @@ -59,13 +59,13 @@ - (void)changeBorderWidth:(id)sender { - [standardBox setBorderWidth:ROUND(Math.random() * 7)]; + [standardBox setBorderWidth:ROUND(RAND() * 7)]; } - (void)changeBorderColor:(id)sender { [customBox setBorderColor:[CPColor randomColor]]; - [customBox setCornerRadius:ROUND(Math.random() * 10)]; + [customBox setCornerRadius:ROUND(RAND() * 10)]; } - (void)changeContentView:(id)sender diff --git a/Tests/Manual/PlatformWindows/AppController.j b/Tests/Manual/PlatformWindows/AppController.j index 5025379d53..5c4ba77ed4 100644 --- a/Tests/Manual/PlatformWindows/AppController.j +++ b/Tests/Manual/PlatformWindows/AppController.j @@ -86,7 +86,7 @@ - (IBAction)randomTitle:(id)aSender { - [theWindow setTitle:@"Window random number " + Math.random(1000)]; + [theWindow setTitle:@"Window random number " + RAND(1000)]; } @end diff --git a/Tests/Objective-J/Preprocessor/BehaviorTests/MethodTest.j b/Tests/Objective-J/Preprocessor/BehaviorTests/MethodTest.j index e1e9a6df9b..6aba67c391 100644 --- a/Tests/Objective-J/Preprocessor/BehaviorTests/MethodTest.j +++ b/Tests/Objective-J/Preprocessor/BehaviorTests/MethodTest.j @@ -11,7 +11,7 @@ - (CPNumber)sqrt:(CPNumber)operand { - return Math.sqrt(operand); + return SQRT(operand); } - (CPNumber)multiply:(CPNumber)firstOperand with:(CPNumber)secondOperand From 1ffdaf0f8b72f0737812aeebc4233ca01460f98d Mon Sep 17 00:00:00 2001 From: Blair Duncan Date: Thu, 10 May 2012 09:01:03 -0400 Subject: [PATCH 2/2] typo, LOG should be log --- Objective-J/Constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/Constants.js b/Objective-J/Constants.js index 5182e1d90f..a7aee6bad4 100644 --- a/Objective-J/Constants.js +++ b/Objective-J/Constants.js @@ -64,7 +64,7 @@ GLOBAL(SQRT) = Math.sqrt; GLOBAL(E) = Math.E; GLOBAL(LN2) = Math.LN2; GLOBAL(LN10) = Math.LN10; -GLOBAL(LOG) = Math.LOG; +GLOBAL(LOG) = Math.log; GLOBAL(LOG2E) = Math.LOG2E; GLOBAL(LOG10E) = Math.LOG10E;