Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion Source/NSUnit.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,35 @@ - (double) constant

- (double) baseUnitValueFromValue: (double)value
{
return (_coefficient* value) + _constant;
return (_coefficient * value) + _constant;
}

- (double) valueFromBaseUnitValue: (double)baseUnitValue
{
return (baseUnitValue - _constant) / _coefficient;
}

- (BOOL)isEqual: (id)object {
NSUnitConverterLinear * otherLinear;

if (self == object)
{
return YES;
}
if ([object isKindOfClass:[NSUnitConverterLinear class]] == NO)
{
return NO;
}

otherLinear = (NSUnitConverterLinear *)object;

return ([self coefficient] == [otherLinear coefficient] && [self constant] == [otherLinear constant]);
}

- (NSUInteger)hash {
return (NSUInteger)(_coefficient * 1000) ^ (NSUInteger)_constant;
}

@end

// Abstract unit...
Expand Down Expand Up @@ -246,6 +268,38 @@ - (void) encodeWithCoder: (NSCoder*)coder
}
}

- (BOOL) isEqual: (id)object {
NSDimension *other;

if (self == object)
{
return YES;
}
if ([object isKindOfClass:[NSDimension class]] == NO)
{
return NO;
}

other = (NSDimension *)object;
if ([self isMemberOfClass:[other class]] == NO)
{
return NO;
}
if ([[self symbol] isEqualToString:[other symbol]] == NO)
{
return NO;
}
if ([[self converter] isEqual:[other converter]] == NO)
{
return NO;
}
return YES;
}

- (NSUInteger)hash {
return [self.class hash] ^ [_symbol hash];
}

@end


Expand Down