Fixed CPColor isEqual: for pattern images.

This commit is contained in:
Alexander Ljungberg
2011-05-09 21:38:32 -04:00
parent 3db05c94ab
commit 5a2e5a7de3
2 changed files with 26 additions and 8 deletions
+10 -5
View File
@@ -616,14 +616,19 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
if (aColor === self)
return YES;
if (![aColor isKindOfClass:CPColor])
return NO;
if (_patternImage || [aColor patternImage])
return [_patternImage isEqual:[aColor patternImage]];
// We don't require the components to be equal beyond 8 bits since otherwise
// simple rounding errors will make two colours which are exactly the same on
// screen compare unequal.
return [aColor isKindOfClass:CPColor] &&
ROUND([self redComponent] * 255.0) == ROUND([aColor redComponent] * 255.0) &&
ROUND([self greenComponent] * 255.0) == ROUND([aColor greenComponent] * 255.0) &&
ROUND([self blueComponent] * 255.0) == ROUND([aColor blueComponent] * 255.0) &&
[self alphaComponent] == [aColor alphaComponent];
return ROUND([self redComponent] * 255.0) == ROUND([aColor redComponent] * 255.0) &&
ROUND([self greenComponent] * 255.0) == ROUND([aColor greenComponent] * 255.0) &&
ROUND([self blueComponent] * 255.0) == ROUND([aColor blueComponent] * 255.0) &&
[self alphaComponent] == [aColor alphaComponent];
}
- (CPString)description
+16 -3
View File
@@ -27,15 +27,28 @@
var color1 = [CPColor colorWithCSSString:"rgba(127,127,127,1.0)"],
color2 = [CPColor colorWithCSSString:"rgba(127, 127, 127, 1.0)"],
color3 = [CPColor colorWithRed:127.0/255.0 green:127.0/255.0 blue:127.0/255.0 alpha:1.0],
color4 = [CPColor whiteColor];
color4 = [CPColor blackColor];
[self assertTrue:[color1 isEqual:color2] message:"[color1 isEqual:color2]"];
[self assertTrue:[color1 isEqual:color3] message:"[color1 isEqual:color3]"];
[self assertTrue:[color2 isEqual:color3] message:"[color2 isEqual:color3]"];
[self assertTrue:[color1 isEqual:color1] message:"[color1 isEqual:color1]"];
[self assertFalse:[color1 isEqual:color4] message:"[color1 isEqual:color4]"];
[self assertFalse:[color4 isEqual:color1] message:"[color4 isEqual:color1]"];
[self assertFalse:[color1 isEqual:color4] message:"![color1 isEqual:color4]"];
[self assertFalse:[color4 isEqual:color1] message:"![color4 isEqual:color1]"];
var image1 = [CPImage new],
image2 = [CPImage new],
color5 = [CPColor colorWithPatternImage:image1],
color6 = [CPColor colorWithPatternImage:image2],
color7 = [CPColor colorWithPatternImage:image1];
image2._filename = "othername";
[self assertTrue:[color5 isEqual:color5] message:"[color5 isEqual:color5]"];
[self assertTrue:[color5 isEqual:color7] message:"[color5 isEqual:color7]"];
[self assertFalse:[color5 isEqual:color6] message:"![color5 isEqual:color6]"];
[self assertFalse:[color4 isEqual:color5] message:"![color4 isEqual:color5]"];
}
@end