Implementation of Linear converter

This commit is contained in:
Gregory John Casamento 2019-10-02 02:05:18 -04:00
parent b2f4495a75
commit 7aee0a7c6a
2 changed files with 61 additions and 3 deletions

View file

@ -39,7 +39,20 @@ extern "C" {
- (double)valueFromBaseUnitValue:(double)baseUnitValue;
@end
@interface NSUnitConverterLinear : NSUnitConverter <NSCoding>
{
double _coefficient;
double _constant;
}
- (instancetype) initWithCoefficient: (double)coefficient;
- (instancetype) initWithCoefficient: (double)coefficient
constant: (double)constant;
- (double) coefficient;
- (double) constant;
@end
@interface NSUnit : NSObject <NSCopying, NSCoding>
{
NSString *_symbol;

View file

@ -38,8 +38,54 @@
}
@end
@implementation NSUnitConverterLinear
- (instancetype) initWithCoefficient: (double)coefficient
{
self = [super init];
if(self != nil)
{
_coefficient = coefficient;
_constant = 0.0;
}
return self;
}
- (instancetype) initWithCoefficient: (double)coefficient
constant: (double)constant
{
self = [super init];
if(self != nil)
{
_coefficient = coefficient;
_constant = constant;
}
return self;
}
- (id) initWithCoder: (NSCoder *)coder
{
return nil;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
}
- (double) coefficient
{
return _coefficient;
}
- (double) constant
{
return _constant;
}
@end
@implementation NSUnit
+ (instancetype)new
{
return [[self alloc] init];
@ -100,6 +146,5 @@
{
return _symbol;
}
@end