Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Rename base to interpolationBase #7486

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
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
32 changes: 16 additions & 16 deletions platform/darwin/src/MGLStyleValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ NS_ASSUME_NONNULL_BEGIN

/**
Creates and returns an `MGLStyleFunction` object representing a zoom level
function with an exponential base and any number of stops.
function with an exponential interpolation base and any number of stops.
@param base The exponential base of the interpolation curve.
@param interpolationBase The exponential base of the interpolation curve.
@param stops A dictionary associating zoom levels with style values.
@return An `MGLStyleFunction` object with the given base and stops.
@return An `MGLStyleFunction` object with the given interpolation base and stops.
*/
+ (instancetype)valueWithBase:(CGFloat)base stops:(NSDictionary<NSNumber *, MGLStyleValue<T> *> *)stops;
+ (instancetype)valueWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary<NSNumber *, MGLStyleValue<T> *> *)stops;

@end

Expand Down Expand Up @@ -126,38 +126,38 @@ NS_ASSUME_NONNULL_BEGIN

/**
Creates and returns an `MGLStyleFunction` object representing a zoom level
function with an exponential base and any number of stops.
function with an exponential interpolation base and any number of stops.
@param base The exponential base of the interpolation curve.
@param interpolationBase The exponential base of the interpolation curve.
@param stops A dictionary associating zoom levels with style values.
@return An `MGLStyleFunction` object with the given base and stops.
@return An `MGLStyleFunction` object with the given interpolation base and stops.
*/
+ (instancetype)functionWithBase:(CGFloat)base stops:(NSDictionary<NSNumber *, MGLStyleValue<T> *> *)stops;
+ (instancetype)functionWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary<NSNumber *, MGLStyleValue<T> *> *)stops;

#pragma mark Initializing a Style Function

/**
Returns an `MGLStyleFunction` object representing a zoom level function with an
exponential base and any number of stops.
exponential interpolation base and any number of stops.
@param base The exponential base of the interpolation curve.
@param interpolationBase The exponential base of the interpolation curve.
@param stops A dictionary associating zoom levels with style values.
@return An `MGLStyleFunction` object with the given base and stops.
@return An `MGLStyleFunction` object with the given interpolation base and stops.
*/
- (instancetype)initWithBase:(CGFloat)base stops:(NSDictionary<NSNumber *, MGLStyleValue<T> *> *)stops NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary<NSNumber *, MGLStyleValue<T> *> *)stops NS_DESIGNATED_INITIALIZER;

#pragma mark Accessing the Parameters of a Function

/**
The exponential base of the function’s interpolation curve.
The exponential interpolation base of the function’s interpolation curve.
The exponential base controls the rate at which the function’s output values
The exponential interpolation base controls the rate at which the function’s output values
increase. A value of 1 causes the function to increase linearly by zoom level.
A higher exponential base causes the function’s output values to vary
A higher exponential interpolation base causes the function’s output values to vary
exponentially, increasing more rapidly towards the high end of the function’s
range. The default value of this property is 1, for a linear curve.
*/
@property (nonatomic) CGFloat base;
@property (nonatomic) CGFloat interpolationBase;

/**
A dictionary associating zoom levels with style values.
Expand Down
24 changes: 12 additions & 12 deletions platform/darwin/src/MGLStyleValue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ + (instancetype)valueWithRawValue:(id)rawValue {
return [MGLStyleConstantValue valueWithRawValue:rawValue];
}

+ (instancetype)valueWithBase:(CGFloat)base stops:(NSDictionary *)stops {
return [MGLStyleFunction functionWithBase:base stops:stops];
+ (instancetype)valueWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops {
return [MGLStyleFunction functionWithInterpolationBase:interpolationBase stops:stops];
}

+ (instancetype)valueWithStops:(NSDictionary *)stops {
Expand Down Expand Up @@ -49,44 +49,44 @@ - (NSUInteger)hash {

@implementation MGLStyleFunction

+ (instancetype)functionWithBase:(CGFloat)base stops:(NSDictionary *)stops {
return [[self alloc] initWithBase:base stops:stops];
+ (instancetype)functionWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops {
return [[self alloc] initWithInterpolationBase:interpolationBase stops:stops];
}

+ (instancetype)functionWithStops:(NSDictionary *)stops {
return [[self alloc] initWithBase:1 stops:stops];
return [[self alloc] initWithInterpolationBase:1 stops:stops];
}

- (instancetype)init {
return [self initWithBase:1 stops:@{}];
return [self initWithInterpolationBase:1 stops:@{}];
}

- (instancetype)initWithBase:(CGFloat)base stops:(NSDictionary *)stops {
- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops {
if (self = [super init]) {
if (!stops.count)
{
[NSException raise:NSInvalidArgumentException format:@"%@ requires at least one stop.", self];
}
_base = base;
_interpolationBase = interpolationBase;
_stops = stops;
}
return self;
}

- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, base = %f; stops = %@>",
return [NSString stringWithFormat:@"<%@: %p, interpolationBase = %f; stops = %@>",
NSStringFromClass([self class]), (void *)self,
self.base,
self.interpolationBase,
self.stops];
}

- (BOOL)isEqual:(MGLStyleFunction *)other {
return ([other isKindOfClass:[self class]] && other.base == self.base
return ([other isKindOfClass:[self class]] && other.interpolationBase == self.interpolationBase
&& [other.stops isEqualToDictionary:self.stops]);
}

- (NSUInteger)hash {
return self.base + self.stops.hash;
return self.interpolationBase + self.stops.hash;
}

@end
8 changes: 4 additions & 4 deletions platform/darwin/src/MGLStyleValue_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MGLStyleValueTransformer {
for (const auto &mbglStop : mbglStops) {
stops[@(mbglStop.first)] = toEnumStyleConstantValue<>(mbglStop.second);
}
return [MGLStyleFunction<NSValue *> functionWithBase:mbglValue.asFunction().getBase() stops:stops];
return [MGLStyleFunction<NSValue *> functionWithInterpolationBase:mbglValue.asFunction().getBase() stops:stops];
} else {
return nil;
}
Expand All @@ -62,7 +62,7 @@ class MGLStyleValueTransformer {
NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant");
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
return mbgl::style::Function<MBGLType>({{mbglStops}}, function.base);
return mbgl::style::Function<MBGLType>({{mbglStops}}, function.interpolationBase);
} else if (value) {
[NSException raise:@"MGLAbstractClassException" format:
@"The style value %@ cannot be applied to the style. "
Expand Down Expand Up @@ -92,7 +92,7 @@ class MGLStyleValueTransformer {
NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant");
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
return mbgl::style::Function<MBGLEnum>({{mbglStops}}, function.base);
return mbgl::style::Function<MBGLEnum>({{mbglStops}}, function.interpolationBase);
} else if (value) {
[NSException raise:@"MGLAbstractClassException" format:
@"The style value %@ cannot be applied to the style. "
Expand All @@ -118,7 +118,7 @@ class MGLStyleValueTransformer {
auto rawValue = toMGLRawStyleValue(mbglStop.second);
stops[@(mbglStop.first)] = [MGLStyleValue valueWithRawValue:rawValue];
}
return [MGLStyleFunction<ObjCType> functionWithBase:mbglFunction.getBase() stops:stops];
return [MGLStyleFunction<ObjCType> functionWithInterpolationBase:mbglFunction.getBase() stops:stops];
}

template <typename MBGLEnum = MBGLType,
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/test/MGLStyleValueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension MGLStyleValueTests {
3: MGLStyleValue(rawValue: true),
4: MGLStyleValue(rawValue: false),
]
symbolStyleLayer.iconAllowsOverlap = MGLStyleFunction<NSNumber>(base: 1, stops: stops)
XCTAssertEqual((symbolStyleLayer.iconAllowsOverlap as! MGLStyleFunction<NSNumber>), MGLStyleFunction(base: 1, stops: stops))
symbolStyleLayer.iconAllowsOverlap = MGLStyleFunction<NSNumber>(interpolationBase: 1, stops: stops)
XCTAssertEqual((symbolStyleLayer.iconAllowsOverlap as! MGLStyleFunction<NSNumber>), MGLStyleFunction(interpolationBase: 1, stops: stops))
}
}