diff --git a/AppKit/CPColor.j b/AppKit/CPColor.j index 3465341b5..e16942f78 100644 --- a/AppKit/CPColor.j +++ b/AppKit/CPColor.j @@ -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 diff --git a/Tests/AppKit/CPColorTest.j b/Tests/AppKit/CPColorTest.j index a772438e9..1eb261fd5 100644 --- a/Tests/AppKit/CPColorTest.j +++ b/Tests/AppKit/CPColorTest.j @@ -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