2019-09-30 19:59:50 +00:00
|
|
|
/* Implementation of class NSUnit
|
|
|
|
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
By: heron
|
|
|
|
Date: Mon Sep 30 15:58:21 EDT 2019
|
|
|
|
|
|
|
|
This file is part of the GNUstep Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Foundation/NSUnit.h>
|
2019-10-02 04:57:17 +00:00
|
|
|
#include <Foundation/NSArchiver.h>
|
2019-10-02 09:47:03 +00:00
|
|
|
#include <Foundation/NSKeyedArchiver.h>
|
2019-09-30 19:59:50 +00:00
|
|
|
|
2019-10-07 02:33:23 +00:00
|
|
|
// Private methods...
|
|
|
|
@interface NSDimension (Private)
|
|
|
|
- (instancetype) initWithSymbol: (NSString *)symbol
|
|
|
|
coefficient: (double)coefficient
|
|
|
|
constant: (double)constant;
|
|
|
|
@end
|
|
|
|
|
2019-10-02 09:47:03 +00:00
|
|
|
// Abstract conversion...
|
2019-10-02 04:57:17 +00:00
|
|
|
@implementation NSUnitConverter
|
2019-10-04 08:05:34 +00:00
|
|
|
- (instancetype) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2019-10-02 04:57:17 +00:00
|
|
|
- (double)baseUnitValueFromValue:(double)value
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (double)valueFromBaseUnitValue:(double)baseUnitValue
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
@end
|
2019-09-30 19:59:50 +00:00
|
|
|
|
2019-10-02 09:47:03 +00:00
|
|
|
// Linear conversion...
|
2019-10-02 06:05:18 +00:00
|
|
|
@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
|
|
|
|
{
|
2019-10-02 09:08:37 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
_coefficient = [coder decodeDoubleForKey: @"coefficient"];
|
|
|
|
_constant = [coder decodeDoubleForKey: @"constant"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[coder decodeValueOfObjCType: @encode(double) at: &_coefficient];
|
|
|
|
[coder decodeValueOfObjCType: @encode(double) at: &_constant];
|
|
|
|
}
|
|
|
|
return self;
|
2019-10-02 06:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
2019-10-02 09:08:37 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
2019-10-02 09:12:07 +00:00
|
|
|
[coder encodeDouble: _coefficient forKey: @"coefficient"];
|
|
|
|
[coder encodeDouble: _constant forKey: @"constant"];
|
2019-10-02 09:08:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-02 09:12:07 +00:00
|
|
|
[coder encodeValueOfObjCType: @encode(double) at: &_coefficient];
|
|
|
|
[coder encodeValueOfObjCType: @encode(double) at: &_constant];
|
2019-10-02 09:08:37 +00:00
|
|
|
}
|
2019-10-02 06:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (double) coefficient
|
|
|
|
{
|
|
|
|
return _coefficient;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (double) constant
|
|
|
|
{
|
|
|
|
return _constant;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2019-10-02 09:47:03 +00:00
|
|
|
// Abstract unit...
|
2019-10-02 04:57:17 +00:00
|
|
|
@implementation NSUnit
|
2019-10-02 04:24:46 +00:00
|
|
|
+ (instancetype)new
|
|
|
|
{
|
|
|
|
return [[self alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if(self != nil)
|
|
|
|
{
|
|
|
|
ASSIGNCOPY(_symbol, @"");
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithSymbol:(NSString *)symbol
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if(self != nil)
|
|
|
|
{
|
|
|
|
ASSIGNCOPY(_symbol, symbol);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
2019-10-02 04:57:17 +00:00
|
|
|
_symbol = [coder decodeObjectForKey: @"symbol"];
|
2019-10-02 04:24:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_symbol = [coder decodeObject];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
[coder encodeObject: _symbol forKey: @"coder"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[coder encodeObject: _symbol];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype) copyWithZone: (NSZone *)zone
|
|
|
|
{
|
|
|
|
NSUnit *u = [[NSUnit allocWithZone: zone] initWithSymbol: [self symbol]];
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)symbol
|
|
|
|
{
|
|
|
|
return _symbol;
|
|
|
|
}
|
2019-09-30 19:59:50 +00:00
|
|
|
@end
|
|
|
|
|
2019-10-02 09:08:37 +00:00
|
|
|
|
|
|
|
// Dimension using units....
|
|
|
|
@implementation NSDimension
|
|
|
|
- (NSUnitConverter *) converter
|
|
|
|
{
|
|
|
|
return _converter;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *) converter
|
|
|
|
{
|
2019-10-04 08:05:34 +00:00
|
|
|
self = [super initWithSymbol: symbol];
|
|
|
|
if(self != nil)
|
|
|
|
{
|
|
|
|
ASSIGN(_converter, converter);
|
|
|
|
}
|
|
|
|
return self;
|
2019-10-02 09:08:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-07 02:33:23 +00:00
|
|
|
- (instancetype) initWithSymbol: (NSString *)symbol
|
|
|
|
coefficient: (double)coefficient
|
|
|
|
constant: (double)constant
|
|
|
|
{
|
|
|
|
NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: coefficient
|
|
|
|
constant: constant];
|
|
|
|
NSDimension *result = [[[self class] alloc] initWithSymbol: symbol
|
|
|
|
converter: converter];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-02 09:08:37 +00:00
|
|
|
+ (instancetype) baseUnit
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
// Predefined....
|
2019-10-06 04:37:30 +00:00
|
|
|
@implementation NSUnitAcceleration
|
2019-10-06 03:09:12 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (instancetype) baseUnit
|
|
|
|
{
|
|
|
|
return [self metersPerSecondSquared];
|
|
|
|
}
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - metersPerSecondSquared
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitAcceleration *) metersPerSecondSquared
|
|
|
|
{
|
|
|
|
NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"m/s^2"
|
2019-10-07 02:33:23 +00:00
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
2019-10-06 15:48:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitAcceleration *) gravity
|
|
|
|
{
|
2019-10-06 23:46:06 +00:00
|
|
|
NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"g"
|
2019-10-07 02:33:23 +00:00
|
|
|
coefficient: 9.81
|
|
|
|
constant: 0];
|
2019-10-06 15:48:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitAngle
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - degrees
|
2019-10-07 02:33:23 +00:00
|
|
|
+ (NSUnitAngle *) degrees
|
|
|
|
{
|
|
|
|
NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"deg"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitAngle *) arcMinutes
|
|
|
|
{
|
|
|
|
NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"'"
|
|
|
|
coefficient: 0.016667
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitAngle *) arcSeconds
|
|
|
|
{
|
|
|
|
NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"\""
|
|
|
|
coefficient: 0.00027778
|
|
|
|
constant: 9.81];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitAngle *) radians
|
|
|
|
{
|
|
|
|
NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"rad"
|
|
|
|
coefficient: 57.2958
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitAngle *) gradians
|
|
|
|
{
|
|
|
|
NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"grad"
|
|
|
|
coefficient: 0.9
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitAngle *) revolutions
|
|
|
|
{
|
|
|
|
NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"rev"
|
|
|
|
coefficient: 360.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitArea
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - squareMeters
|
2019-10-07 02:58:47 +00:00
|
|
|
+ (NSUnitArea *) squareMegameters
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"Mm^2"
|
|
|
|
coefficient: 1e12
|
|
|
|
constant: 0.0];
|
2019-10-07 02:58:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareKilometers
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"km^2"
|
|
|
|
coefficient: 1000000.0
|
|
|
|
constant: 0.0];
|
2019-10-07 02:58:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareMeters
|
|
|
|
{
|
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"m^2"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareCentimeters
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"cm^2"
|
|
|
|
coefficient: 0.0001
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareMillimeters
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"mm^2"
|
|
|
|
coefficient: 0.000001
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareMicrometers
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"um^2"
|
|
|
|
coefficient: 1e-12
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareNanometers
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"nm^2"
|
|
|
|
coefficient: 1e-18
|
|
|
|
constant: 0.0];
|
2019-10-07 02:58:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareInches
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"in^2"
|
|
|
|
coefficient: 0.00064516
|
|
|
|
constant: 0.0];
|
2019-10-07 02:58:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareFeet
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"ft^2"
|
|
|
|
coefficient: 0.092903
|
|
|
|
constant: 0.0];
|
2019-10-07 02:58:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareYards
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"yd^2"
|
|
|
|
coefficient: 0.836127
|
|
|
|
constant: 0.0];
|
2019-10-07 02:58:47 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) squareMiles
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"mi^2"
|
|
|
|
coefficient: 2.59e+6
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) acres
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"acres"
|
|
|
|
coefficient: 4046.86
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) ares
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"ares"
|
|
|
|
coefficient: 100.0
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitArea *) hectares
|
|
|
|
{
|
2019-10-07 03:17:13 +00:00
|
|
|
NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"hectares"
|
|
|
|
coefficient: 10000.0
|
2019-10-07 02:58:47 +00:00
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitConcentrationMass
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - gramsPerLiter
|
2019-10-07 03:22:17 +00:00
|
|
|
+ (NSUnitConcentrationMass *) gramsPerLiter
|
|
|
|
{
|
|
|
|
NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"g/L"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitConcentrationMass *) milligramsPerDeciliter
|
|
|
|
{
|
|
|
|
NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"mg/dL"
|
|
|
|
coefficient: 0.01
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-07 03:22:17 +00:00
|
|
|
+ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole
|
|
|
|
{
|
|
|
|
NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"mmol/L"
|
|
|
|
coefficient: 18.0 * gramsPerMole
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitDispersion
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - partsPerMillion
|
2019-10-07 03:59:27 +00:00
|
|
|
+ (NSUnitDispersion *) partsPerMillion
|
|
|
|
{
|
|
|
|
NSUnitDispersion *result = [[NSUnitDispersion alloc] initWithSymbol: @"ppm"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:29:00 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitDuration
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - seconds
|
2019-10-07 04:03:12 +00:00
|
|
|
+ (NSUnitDuration *) seconds
|
|
|
|
{
|
|
|
|
NSUnitDuration *result = [[NSUnitDuration alloc] initWithSymbol: @"sec"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitDuration *) minutes
|
|
|
|
{
|
|
|
|
NSUnitDuration *result = [[NSUnitDuration alloc] initWithSymbol: @"min"
|
|
|
|
coefficient: 60.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitDuration *) hours
|
|
|
|
{
|
|
|
|
NSUnitDuration *result = [[NSUnitDuration alloc] initWithSymbol: @"hr"
|
|
|
|
coefficient: 3600.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitElectricCharge
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - coulombs
|
2019-10-07 04:15:41 +00:00
|
|
|
+ (NSUnitElectricCharge *) coulombs
|
|
|
|
{
|
|
|
|
NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"C"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCharge *) megaampereHours
|
|
|
|
{
|
|
|
|
NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"MAh"
|
|
|
|
coefficient: 3.6e9
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCharge *) kiloampereHours
|
|
|
|
{
|
|
|
|
NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"kAh"
|
|
|
|
coefficient: 3600000.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCharge *) ampereHours
|
|
|
|
{
|
|
|
|
NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"mAh"
|
|
|
|
coefficient: 3600.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCharge *) milliampereHours
|
|
|
|
{
|
|
|
|
NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"hr"
|
|
|
|
coefficient: 3.6
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCharge *) microampereHours
|
|
|
|
{
|
|
|
|
NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"uAh"
|
|
|
|
coefficient: 0.0036
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:29:00 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitElectricCurrent
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - amperes
|
2019-10-07 04:52:13 +00:00
|
|
|
+ (NSUnitElectricCurrent *) megaamperes
|
|
|
|
{
|
|
|
|
NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"MA"
|
|
|
|
coefficient: 1000000.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCurrent *) kiloamperes
|
|
|
|
{
|
|
|
|
NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"kA"
|
|
|
|
coefficient: 1000.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCurrent *) amperes
|
|
|
|
{
|
|
|
|
NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"A"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCurrent *) milliamperes
|
|
|
|
{
|
|
|
|
NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"mA"
|
|
|
|
coefficient: 0.001
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricCurrent *) microamperes
|
|
|
|
{
|
|
|
|
NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"uA"
|
2019-10-07 05:04:55 +00:00
|
|
|
coefficient: 0.000001
|
|
|
|
constant: 0.0];
|
2019-10-07 04:52:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitElectricPotentialDifference
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - volts
|
2019-10-07 05:04:55 +00:00
|
|
|
+ (NSUnitElectricPotentialDifference *) megavolts
|
|
|
|
{
|
|
|
|
NSUnitElectricPotentialDifference *result =
|
|
|
|
[[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"MV"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 1000000.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricPotentialDifference *) kilovolts
|
|
|
|
{
|
|
|
|
NSUnitElectricPotentialDifference *result =
|
|
|
|
[[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"kV"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 1000.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricPotentialDifference *) volts
|
|
|
|
{
|
|
|
|
NSUnitElectricPotentialDifference *result =
|
|
|
|
[[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"V"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 1.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricPotentialDifference *) millivolts
|
|
|
|
{
|
|
|
|
NSUnitElectricPotentialDifference *result =
|
|
|
|
[[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"mV"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 0.001];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitElectricPotentialDifference *) microvolts
|
|
|
|
{
|
|
|
|
NSUnitElectricPotentialDifference *result =
|
|
|
|
[[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"uV"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 0.000001];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitElectricResistance
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - ohms
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitElectricResistance *) megaohms { return nil; }
|
2019-10-07 05:54:16 +00:00
|
|
|
{
|
|
|
|
NSUnitElectricResistance *result =
|
|
|
|
[[NSUnitElectricResistance alloc] initWithSymbol: @"MOhm"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 100000.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitElectricResistance *) kiloohms { return nil; }
|
2019-10-07 05:54:16 +00:00
|
|
|
{
|
|
|
|
NSUnitElectricResistance *result =
|
|
|
|
[[NSUnitElectricResistance alloc] initWithSymbol: @"kOhm"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 1000.000001];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitElectricResistance *) ohms { return nil; }
|
2019-10-07 05:54:16 +00:00
|
|
|
{
|
|
|
|
NSUnitElectricResistance *result =
|
|
|
|
[[NSUnitElectricResistance alloc] initWithSymbol: @"Ohm"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 0.000001];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitElectricResistance *) milliohms { return nil; }
|
2019-10-07 05:54:16 +00:00
|
|
|
{
|
|
|
|
NSUnitElectricResistance *result =
|
|
|
|
[[NSUnitElectricResistance alloc] initWithSymbol: @"mOhm"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 0.000001];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitElectricResistance *) microohms { return nil; }
|
2019-10-07 05:54:16 +00:00
|
|
|
{
|
|
|
|
NSUnitElectricResistance *result =
|
|
|
|
[[NSUnitElectricResistance alloc] initWithSymbol: @"uOhm"
|
|
|
|
coefficient: 0.0
|
|
|
|
constant: 0.000001];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitEnergy
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - joules
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitEnergy *) kilojoules { return nil; }
|
|
|
|
+ (NSUnitEnergy *) joules { return nil; }
|
|
|
|
+ (NSUnitEnergy *) kilocalories { return nil; }
|
|
|
|
+ (NSUnitEnergy *) calories { return nil; }
|
|
|
|
+ (NSUnitEnergy *) kilowattHours { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitFrequency
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - hertz
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitFrequency *) terahertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) gigahertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) megahertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) kilohertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) hertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) millihertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) microhertz { return nil; }
|
|
|
|
+ (NSUnitFrequency *) nanohertz { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitFuelEfficiency
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - litersPer100Kilometers
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitFuelEfficiency *) litersPer100Kilometers { return nil; }
|
|
|
|
+ (NSUnitFuelEfficiency *) milesPerImperialGallon { return nil; }
|
|
|
|
+ (NSUnitFuelEfficiency *) milesPerGallon { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitLength
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - meters
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitLength *) megameters { return nil; }
|
|
|
|
+ (NSUnitLength *) kilometers { return nil; }
|
|
|
|
+ (NSUnitLength *) hectometers { return nil; }
|
|
|
|
+ (NSUnitLength *) decameters { return nil; }
|
|
|
|
+ (NSUnitLength *) meters { return nil; }
|
|
|
|
+ (NSUnitLength *) decimeters { return nil; }
|
|
|
|
+ (NSUnitLength *) centimeters { return nil; }
|
|
|
|
+ (NSUnitLength *) millimeters { return nil; }
|
|
|
|
+ (NSUnitLength *) micrometers { return nil; }
|
|
|
|
+ (NSUnitLength *) nanometers { return nil; }
|
|
|
|
+ (NSUnitLength *) picometers { return nil; }
|
|
|
|
+ (NSUnitLength *) inches { return nil; }
|
|
|
|
+ (NSUnitLength *) feet { return nil; }
|
|
|
|
+ (NSUnitLength *) yards { return nil; }
|
|
|
|
+ (NSUnitLength *) miles { return nil; }
|
|
|
|
+ (NSUnitLength *) scandinavianMiles { return nil; }
|
|
|
|
+ (NSUnitLength *) lightyears { return nil; }
|
|
|
|
+ (NSUnitLength *) nauticalMiles { return nil; }
|
|
|
|
+ (NSUnitLength *) fathoms { return nil; }
|
|
|
|
+ (NSUnitLength *) furlongs { return nil; }
|
|
|
|
+ (NSUnitLength *) astronomicalUnits { return nil; }
|
|
|
|
+ (NSUnitLength *) parsecs { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitIlluminance
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - lux
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-07 04:23:55 +00:00
|
|
|
+ (NSUnitIlluminance *) lux
|
|
|
|
{
|
|
|
|
NSUnitIlluminance *result = [[NSUnitIlluminance alloc] initWithSymbol: @"lux"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:29:00 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitMass
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - kilograms
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitMass *) kilograms { return nil; }
|
|
|
|
+ (NSUnitMass *) grams { return nil; }
|
|
|
|
+ (NSUnitMass *) decigrams { return nil; }
|
|
|
|
+ (NSUnitMass *) centigrams { return nil; }
|
|
|
|
+ (NSUnitMass *) milligrams { return nil; }
|
|
|
|
+ (NSUnitMass *) micrograms { return nil; }
|
|
|
|
+ (NSUnitMass *) nanograms { return nil; }
|
|
|
|
+ (NSUnitMass *) picograms { return nil; }
|
|
|
|
+ (NSUnitMass *) ounces { return nil; }
|
|
|
|
+ (NSUnitMass *) poundsMass { return nil; }
|
|
|
|
+ (NSUnitMass *) stones { return nil; }
|
|
|
|
+ (NSUnitMass *) metricTons { return nil; }
|
|
|
|
+ (NSUnitMass *) shortTons { return nil; }
|
|
|
|
+ (NSUnitMass *) carats { return nil; }
|
|
|
|
+ (NSUnitMass *) ouncesTroy { return nil; }
|
|
|
|
+ (NSUnitMass *) slugs { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitPower
|
2019-10-06 04:37:30 +00:00
|
|
|
|
|
|
|
// Base unit - watts
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitPower *) terawatts { return nil; }
|
|
|
|
+ (NSUnitPower *) gigawatts { return nil; }
|
|
|
|
+ (NSUnitPower *) megawatts { return nil; }
|
|
|
|
+ (NSUnitPower *) kilowatts { return nil; }
|
|
|
|
+ (NSUnitPower *) watts { return nil; }
|
|
|
|
+ (NSUnitPower *) milliwatts { return nil; }
|
|
|
|
+ (NSUnitPower *) microwatts { return nil; }
|
|
|
|
+ (NSUnitPower *) nanowatts { return nil; }
|
|
|
|
+ (NSUnitPower *) picowatts { return nil; }
|
|
|
|
+ (NSUnitPower *) femtowatts { return nil; }
|
|
|
|
+ (NSUnitPower *) horsepower { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
@implementation NSUnitPressure
|
|
|
|
|
|
|
|
// Base unit - newtonsPerMetersSquared (equivalent to 1 pascal)
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitPressure *) newtonsPerMetersSquared { return nil; }
|
|
|
|
+ (NSUnitPressure *) gigapascals { return nil; }
|
|
|
|
+ (NSUnitPressure *) megapascals { return nil; }
|
|
|
|
+ (NSUnitPressure *) kilopascals { return nil; }
|
|
|
|
+ (NSUnitPressure *) hectopascals { return nil; }
|
|
|
|
+ (NSUnitPressure *) inchesOfMercury { return nil; }
|
|
|
|
+ (NSUnitPressure *) bars { return nil; }
|
|
|
|
+ (NSUnitPressure *) millibars { return nil; }
|
|
|
|
+ (NSUnitPressure *) millimetersOfMercury { return nil; }
|
|
|
|
+ (NSUnitPressure *) poundsForcePerSquareInch { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitSpeed
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - metersPerSecond
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitSpeed *) metersPerSecond { return nil; }
|
|
|
|
+ (NSUnitSpeed *) kilometersPerHour { return nil; }
|
|
|
|
+ (NSUnitSpeed *) milesPerHour { return nil; }
|
|
|
|
+ (NSUnitSpeed *) knots { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
@implementation NSUnitTemperature
|
|
|
|
|
|
|
|
// Base unit - kelvin
|
2019-10-07 05:11:29 +00:00
|
|
|
+ (NSUnitTemperature *) kelvin
|
|
|
|
{
|
|
|
|
NSUnitTemperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"K"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 0.0];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
|
2019-10-07 05:11:29 +00:00
|
|
|
+ (NSUnitTemperature *) celsius
|
|
|
|
{
|
|
|
|
NSUnitTerperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"C"
|
|
|
|
coefficient: 1.0
|
|
|
|
constant: 273.15];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSUnitTemperature *) fahrenheit
|
|
|
|
{
|
|
|
|
NSUnitTemperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"F"
|
|
|
|
coefficient: 0.55555555555556
|
|
|
|
constant: 255.37222222222427];
|
|
|
|
return result;
|
|
|
|
}
|
2019-10-04 02:29:00 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSUnitVolume
|
|
|
|
|
2019-10-06 04:37:30 +00:00
|
|
|
// Base unit - liters
|
2019-10-06 15:48:21 +00:00
|
|
|
+ (NSUnitVolume *) megaliters { return nil; }
|
|
|
|
+ (NSUnitVolume *) kiloliters { return nil; }
|
|
|
|
+ (NSUnitVolume *) liters { return nil; }
|
|
|
|
+ (NSUnitVolume *) deciliters { return nil; }
|
|
|
|
+ (NSUnitVolume *) centiliters { return nil; }
|
|
|
|
+ (NSUnitVolume *) milliliters { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicKilometers { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicMeters { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicDecimeters { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicCentimeters { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicMillimeters { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicInches { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicFeet { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicYards { return nil; }
|
|
|
|
+ (NSUnitVolume *) cubicMiles { return nil; }
|
|
|
|
+ (NSUnitVolume *) acreFeet { return nil; }
|
|
|
|
+ (NSUnitVolume *) bushels { return nil; }
|
|
|
|
+ (NSUnitVolume *) teaspoons { return nil; }
|
|
|
|
+ (NSUnitVolume *) tablespoons { return nil; }
|
|
|
|
+ (NSUnitVolume *) fluidOunces { return nil; }
|
|
|
|
+ (NSUnitVolume *) cups { return nil; }
|
|
|
|
+ (NSUnitVolume *) pints { return nil; }
|
|
|
|
+ (NSUnitVolume *) quarts { return nil; }
|
|
|
|
+ (NSUnitVolume *) gallons { return nil; }
|
|
|
|
+ (NSUnitVolume *) imperialTeaspoons { return nil; }
|
|
|
|
+ (NSUnitVolume *) imperialTablespoons { return nil; }
|
|
|
|
+ (NSUnitVolume *) imperialFluidOunces { return nil; }
|
|
|
|
+ (NSUnitVolume *) imperialPints { return nil; }
|
|
|
|
+ (NSUnitVolume *) imperialQuarts { return nil; }
|
|
|
|
+ (NSUnitVolume *) imperialGallons { return nil; }
|
|
|
|
+ (NSUnitVolume *) metricCups { return nil; }
|
2019-10-04 02:29:00 +00:00
|
|
|
|
|
|
|
@end
|