diff options
author | thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2008-06-13 19:21:50 +0000 |
---|---|---|
committer | thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2008-06-13 19:21:50 +0000 |
commit | c53ec5520e39096e0804ce8d89a21378c0904481 (patch) | |
tree | d36a0055b59b1376d86c4ba4a01f9c479c2101a7 /Foundation/GTMCalculatedRange.m | |
parent | 80d493da05c8d461d74bfaa919ffc487be03ffe6 (diff) |
Landing a log of AppleScript/AppleEvent support code.
Landing GTMHTTPServer as a simple server but mainly for use in unittesting.
_GTMCompileAssert for doing compile time assertions to GTMDefines.h
Lots of improvments for UnitTesting, Dave's gonna put up a wiki page shortly with the full details of what can be done.
Diffstat (limited to 'Foundation/GTMCalculatedRange.m')
-rw-r--r-- | Foundation/GTMCalculatedRange.m | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/Foundation/GTMCalculatedRange.m b/Foundation/GTMCalculatedRange.m index 435ad65..218b811 100644 --- a/Foundation/GTMCalculatedRange.m +++ b/Foundation/GTMCalculatedRange.m @@ -30,6 +30,9 @@ - (CGFloat)position; @end +CG_INLINE BOOL FPEqual(CGFloat a, CGFloat b) { + return (fpclassify(a - b) == FP_ZERO); +} @implementation GTMCalculatedRangeStopPrivate + (id)stopWithObject:(id)item position:(CGFloat)inPosition { @@ -77,52 +80,52 @@ } - (void)insertStop:(id)item atPosition:(CGFloat)position { - NSUInteger index = 0; + NSUInteger positionIndex = 0; NSEnumerator *theEnumerator = [storage_ objectEnumerator]; GTMCalculatedRangeStopPrivate *theStop; while (nil != (theStop = [theEnumerator nextObject])) { if ([theStop position] < position) { - index += 1; + positionIndex += 1; } - else if ([theStop position] == position) { + else if (FPEqual([theStop position], position)) { // remove and stop the enum since we just modified the object - [storage_ removeObjectAtIndex:index]; + [storage_ removeObjectAtIndex:positionIndex]; break; } } [storage_ insertObject:[GTMCalculatedRangeStopPrivate stopWithObject:item position:position] - atIndex:index]; + atIndex:positionIndex]; } - (BOOL)removeStopAtPosition:(CGFloat)position { - NSUInteger index = 0; + NSUInteger positionIndex = 0; BOOL foundStop = NO; NSEnumerator *theEnumerator = [storage_ objectEnumerator]; GTMCalculatedRangeStopPrivate *theStop; while (nil != (theStop = [theEnumerator nextObject])) { - if ([theStop position] == position) { + if (FPEqual([theStop position], position)) { break; } else { - index += 1; + positionIndex += 1; } } if (nil != theStop) { - [self removeStopAtIndex:index]; + [self removeStopAtIndex:positionIndex]; foundStop = YES; } return foundStop; } -- (void)removeStopAtIndex:(NSUInteger)index { - [storage_ removeObjectAtIndex:index]; +- (void)removeStopAtIndex:(NSUInteger)positionIndex { + [storage_ removeObjectAtIndex:positionIndex]; } - (NSUInteger)stopCount { return [storage_ count]; } -- (id)stopAtIndex:(NSUInteger)index position:(CGFloat*)outPosition { - GTMCalculatedRangeStopPrivate *theStop = [storage_ objectAtIndex:index]; +- (id)stopAtIndex:(NSUInteger)positionIndex position:(CGFloat*)outPosition { + GTMCalculatedRangeStopPrivate *theStop = [storage_ objectAtIndex:positionIndex]; if (nil != outPosition) { *outPosition = [theStop position]; } @@ -134,7 +137,7 @@ GTMCalculatedRangeStopPrivate *theStop; NSEnumerator *theEnumerator = [storage_ objectEnumerator]; while (nil != (theStop = [theEnumerator nextObject])) { - if ([theStop position] == position) { + if (FPEqual([theStop position], position)) { theValue = [theStop item]; break; } |