From 6cde1a48807829c41f9cce53d000cc3ec800eebb Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 1 Jun 2017 18:49:48 -0400 Subject: [PATCH 1/6] [ios, macos] Add the MGLLight generation templates --- .../darwin/scripts/generate-style-code.js | 15 +++ platform/darwin/src/MGLLight.h.ejs | 125 ++++++++++++++++++ platform/darwin/src/MGLLight.mm.ejs | 113 ++++++++++++++++ 3 files changed, 253 insertions(+) create mode 100644 platform/darwin/src/MGLLight.h.ejs create mode 100644 platform/darwin/src/MGLLight.mm.ejs diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 7efc8d441cf..e06a00fd701 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -519,6 +519,14 @@ global.setSourceLayer = function() { return `_layer->setSourceLayer(sourceLayer.UTF8String);` }; +const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => { + var property = spec[`light`][name]; + property.name = name; + property['light-property'] = true; + memo.push(property); + return memo; +}, []); + const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true}); @@ -526,6 +534,13 @@ const forStyleAuthorsMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guid const ddsGuideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Using Style Functions at Runtime.md.ejs', 'utf8'), { strict: true }); const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Tile URL Templates.md.ejs', 'utf8'), { strict: true }); +const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true});; +const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true});; +fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH(lightProperties)); +fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM(lightProperties)); + + + const layers = _(spec.layer.type.values).map((value, layerType) => { const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => { if (name !== 'visibility') { diff --git a/platform/darwin/src/MGLLight.h.ejs b/platform/darwin/src/MGLLight.h.ejs new file mode 100644 index 00000000000..ef9811bd33c --- /dev/null +++ b/platform/darwin/src/MGLLight.h.ejs @@ -0,0 +1,125 @@ +#import + +#import "MGLFoundation.h" +#import "MGLStyleValue.h" + +NS_ASSUME_NONNULL_BEGIN + + +/** Options to specify extruded geometries are lit relative to the map or viewport. */ +typedef NS_ENUM(NSUInteger, MGLLightAnchor) { + /** The position of the light source is aligned to the rotation of the map. */ + MGLLightAnchorMap, + /** The position of the light source is aligned to the rotation of the viewport. */ + MGLLightAnchorViewport +}; + +/** + A structure containing information about the position of the light source + relative to lit geometries. + */ +typedef struct MGLSphericalPosition { + /** Distance from the center of the base of an object to its light. */ + CLLocationDistance radial; + /** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds + to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north, + and degrees proceed clockwise). */ + CLLocationDirection azimuthal; + /** Indicates the height of the light (from 0°, directly above, to 180°, directly below). */ + CLLocationDirection polar; +} MGLSphericalPosition; + +/** + Creates a new `MGLSphericalPosition` from the given radial, azimuthal, polar. + + @param radial The radial coordinate. + @param azimuthal The azimuthal angle. + @param polar The polar angle. + + @return Returns a `MGLSphericalPosition` struct containing the position attributes. + */ +NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CLLocationDistance radial, CLLocationDirection azimuthal, CLLocationDirection polar) { + MGLSphericalPosition position; + position.radial = radial; + position.azimuthal = azimuthal; + position.polar = polar; + + return position; +} + +/** + An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`. + */ +MGL_EXPORT +@interface MGLLight : NSObject + +/** + `anchor` Whether extruded geometries are lit relative to the map or viewport. + + This property corresponds to the anchor + light property in the Mapbox Style Specification. + */ +@property (nonatomic) MGLStyleValue *anchor; + +/** + Values describing animated transitions to `anchor` property. + */ +@property (nonatomic) MGLTransition anchorTransition; + + +/** + Position of the light source relative to lit (extruded) geometries. + + This property corresponds to the position + light property in the Mapbox Style Specification. + */ +@property (nonatomic) MGLStyleValue *position; + +/** + Values describing animated transitions to `position` property. + */ +@property (nonatomic) MGLTransition positionTransiton; + + +#if TARGET_OS_IPHONE +/** + Color tint for lighting extruded geometries. + + This property corresponds to the color + light property in the Mapbox Style Specification. + */ +@property (nonatomic) MGLStyleValue *color; +#else + +/** + Color tint for lighting extruded geometries. + */ +@property (nonatomic) MGLStyleValue *color; +#endif + +/** + Values describing animated transitions to `color` property. + */ +@property (nonatomic) MGLTransition colorTransiton; + + +/** + Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. + + This property corresponds to the intensity + light property in the Mapbox Style Specification. + */ +@property(nonatomic) MGLStyleValue *intensity; + +/** + Values describing animated transitions to `intensity` property. + */ +@property (nonatomic) MGLTransition intensityTransition; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLLight.mm.ejs b/platform/darwin/src/MGLLight.mm.ejs new file mode 100644 index 00000000000..262fad3b070 --- /dev/null +++ b/platform/darwin/src/MGLLight.mm.ejs @@ -0,0 +1,113 @@ +#import "MGLLight.h" + +#import "MGLTypes.h" +#import "NSDate+MGLAdditions.h" +#import "MGLStyleValue_Private.h" +#import "NSValue+MGLAdditions.h" + +#import +#import + +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLLightAnchor, { + { MGLLightAnchorMap, "map" }, + { MGLLightAnchorViewport, "viewport" }, + }); + +} + +NS_INLINE MGLTransition MGLTransitionFromOptions(const mbgl::style::TransitionOptions& options) { + MGLTransition transition; + transition.duration = MGLTimeIntervalFromDuration(options.duration.value_or(mbgl::Duration::zero())); + transition.delay = MGLTimeIntervalFromDuration(options.delay.value_or(mbgl::Duration::zero())); + + return transition; +} + +NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition transition) { + mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } }; + return options; +} + +@interface MGLLight() + +@end + +@implementation MGLLight + +- (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight +{ + if (self = [super init]) { + auto anchor = mbglLight->getAnchor(); + MGLStyleValue *anchorStyleValue; + if (anchor.isUndefined()) { + mbgl::style::PropertyValue defaultAnchor = mbglLight->getDefaultAnchor(); + anchorStyleValue = MGLStyleValueTransformer().toEnumStyleValue(defaultAnchor); + } else { + anchorStyleValue = MGLStyleValueTransformer().toEnumStyleValue(anchor); + } + + _anchor = anchorStyleValue; + + _anchorTransition = MGLTransitionFromOptions(mbglLight->getAnchorTransition()); + + auto positionValue = mbglLight->getPosition(); + if (positionValue.isUndefined()) { + _position = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultPosition()); + } else { + _position = MGLStyleValueTransformer().toStyleValue(positionValue); + } + + _positionTransiton = MGLTransitionFromOptions(mbglLight->getPositionTransition()); + + auto colorValue = mbglLight->getColor(); + if (colorValue.isUndefined()) { + _color = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultColor()); + } else { + _color = MGLStyleValueTransformer().toStyleValue(colorValue); + } + + _colorTransiton = MGLTransitionFromOptions(mbglLight->getColorTransition()); + + auto intensityValue = mbglLight->getIntensity(); + if (intensityValue.isUndefined()) { + _intensity = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultIntensity()); + } else { + _intensity = MGLStyleValueTransformer().toStyleValue(intensityValue); + } + + _intensityTransition = MGLTransitionFromOptions(mbglLight->getIntensityTransition()); + } + + return self; +} + +- (mbgl::style::Light)mbglLight +{ + mbgl::style::Light mbglLight; + + auto anchor = MGLStyleValueTransformer().toEnumPropertyValue(self.anchor); + mbglLight.setAnchor(anchor); + + mbglLight.setAnchorTransition(MGLOptionsFromTransition(self.anchorTransition)); + + auto position = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.position); + mbglLight.setPosition(position); + + mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransiton)); + + auto color = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.color); + mbglLight.setColor(color); + + mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransiton)); + + auto intensity = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.intensity); + mbglLight.setIntensity(intensity); + + mbglLight.setIntensityTransition(MGLOptionsFromTransition(self.intensityTransition)); + + return mbglLight; +} + +@end From d2153a6b86ce78041a4a22f5d615e082a99f7152 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 12 Jun 2017 10:53:24 -0400 Subject: [PATCH 2/6] [ios, macos] Add MGLLight generation script --- platform/darwin/scripts/generate-style-code.js | 9 ++++++--- platform/darwin/src/MGLLight.h | 5 ++++- platform/darwin/src/MGLLight.h.ejs | 10 +++++++++- platform/darwin/src/MGLLight.mm | 6 +++++- platform/darwin/src/MGLLight.mm.ejs | 18 +++++++++++++++--- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index e06a00fd701..dde41cc239c 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -220,6 +220,7 @@ global.testHelperMessage = function (property, layerType, isFunction) { }; global.propertyDoc = function (propertyName, property, layerType, kind) { + console.log(propertyName + " : " + property + " : " + layerType + " : " + kind) // Match references to other property names & values. // Requires the format 'When `foo` is set to `bar`,'. let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) { @@ -527,6 +528,8 @@ const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => { return memo; }, []); +console.log(lightProperties); + const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true}); @@ -536,8 +539,8 @@ const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Til const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true});; const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true});; -fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH(lightProperties)); -fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM(lightProperties)); +fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH({ properties: lightProperties, })); +fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, })); @@ -555,7 +558,7 @@ const layers = _(spec.layer.type.values).map((value, layerType) => { memo.push(spec[`paint_${layerType}`][name]); return memo; }, []); - +console.log(spec.layer.type.values[layerType].doc) return { doc: spec.layer.type.values[layerType].doc, type: layerType, diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index ef9811bd33c..5991f365cf9 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -1,3 +1,6 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. + #import #import "MGLFoundation.h" @@ -20,7 +23,7 @@ typedef NS_ENUM(NSUInteger, MGLLightAnchor) { */ typedef struct MGLSphericalPosition { /** Distance from the center of the base of an object to its light. */ - CLLocationDistance radial; + CGFloat radial; /** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north, and degrees proceed clockwise). */ diff --git a/platform/darwin/src/MGLLight.h.ejs b/platform/darwin/src/MGLLight.h.ejs index ef9811bd33c..e1bfc29fe1d 100644 --- a/platform/darwin/src/MGLLight.h.ejs +++ b/platform/darwin/src/MGLLight.h.ejs @@ -1,3 +1,11 @@ +<% + const properties = locals.properties; + const type = locals.type; + const doc = locals.doc; +-%> +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. + #import #import "MGLFoundation.h" @@ -20,7 +28,7 @@ typedef NS_ENUM(NSUInteger, MGLLightAnchor) { */ typedef struct MGLSphericalPosition { /** Distance from the center of the base of an object to its light. */ - CLLocationDistance radial; + CGFloat radial; /** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north, and degrees proceed clockwise). */ diff --git a/platform/darwin/src/MGLLight.mm b/platform/darwin/src/MGLLight.mm index 262fad3b070..92eb78b9745 100644 --- a/platform/darwin/src/MGLLight.mm +++ b/platform/darwin/src/MGLLight.mm @@ -1,3 +1,7 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +// test + #import "MGLLight.h" #import "MGLTypes.h" @@ -9,7 +13,7 @@ #import namespace mbgl { - + MBGL_DEFINE_ENUM(MGLLightAnchor, { { MGLLightAnchorMap, "map" }, { MGLLightAnchorViewport, "viewport" }, diff --git a/platform/darwin/src/MGLLight.mm.ejs b/platform/darwin/src/MGLLight.mm.ejs index 262fad3b070..d9469564840 100644 --- a/platform/darwin/src/MGLLight.mm.ejs +++ b/platform/darwin/src/MGLLight.mm.ejs @@ -1,3 +1,10 @@ +<% + const properties = locals.properties; +-%> +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +// test + #import "MGLLight.h" #import "MGLTypes.h" @@ -9,10 +16,15 @@ #import namespace mbgl { - + MBGL_DEFINE_ENUM(MGLLightAnchor, { - { MGLLightAnchorMap, "map" }, - { MGLLightAnchorViewport, "viewport" }, +<% for (const property of properties) { -%> +<% if (property.type == "enum") { -%> +<% for (const value in property.values) { -%> + { MGLLightAnchor<%- camelize(value) %>, "<%- value %>" }, +<% } -%> +<% } -%> +<% } -%> }); } From ed30f1566da388234d28f514f4f0923f23d9fd9c Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 13 Jun 2017 19:49:20 -0400 Subject: [PATCH 3/6] [ios, macos] Add the auto-generation script for MGLLight.mm --- .../darwin/scripts/generate-style-code.js | 19 +-- .../scripts/style-spec-overrides-v8.json | 1 + platform/darwin/src/MGLLight.h | 113 ++++++++++++++---- platform/darwin/src/MGLLight.h.ejs | 97 +++++---------- platform/darwin/src/MGLLight.mm | 35 +++--- platform/darwin/src/MGLLight.mm.ejs | 99 +++++++-------- 6 files changed, 192 insertions(+), 172 deletions(-) diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index dde41cc239c..38e1a4bfebc 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -220,7 +220,6 @@ global.testHelperMessage = function (property, layerType, isFunction) { }; global.propertyDoc = function (propertyName, property, layerType, kind) { - console.log(propertyName + " : " + property + " : " + layerType + " : " + kind) // Match references to other property names & values. // Requires the format 'When `foo` is set to `bar`,'. let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) { @@ -257,7 +256,7 @@ global.propertyDoc = function (propertyName, property, layerType, kind) { if (kind !== 'enum') { if ('default' in property) { doc += `\n\nThe default value of this property is ${propertyDefault(property, layerType)}.`; - if (!property.required) { + if (!property.required && kind != 'light') { doc += ' Set this property to `nil` to reset it to the default value.'; } } @@ -419,6 +418,7 @@ global.propertyType = function (property) { return 'NSArray *'; case 'padding': return 'NSValue *'; + case 'position': case 'offset': case 'translate': return 'NSValue *'; @@ -458,6 +458,8 @@ global.valueTransformerArguments = function (property) { return ['std::vector', objCType, 'std::string']; case 'padding': return ['std::array', objCType]; + case 'position': + return ['mbgl::style::Position', objCType]; case 'offset': case 'translate': return ['std::array', objCType]; @@ -520,15 +522,15 @@ global.setSourceLayer = function() { return `_layer->setSourceLayer(sourceLayer.UTF8String);` }; -const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => { - var property = spec[`light`][name]; +const lightProperties = Object.keys(spec['light']).reduce((memo, name) => { + var property = spec['light'][name]; property.name = name; property['light-property'] = true; memo.push(property); return memo; }, []); -console.log(lightProperties); +const lightDoc = spec[`light-cocoa-doc`]; const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); @@ -539,9 +541,8 @@ const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Til const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true});; const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true});; -fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH({ properties: lightProperties, })); -fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, })); - +fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc}))); +fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc})); const layers = _(spec.layer.type.values).map((value, layerType) => { @@ -558,7 +559,7 @@ const layers = _(spec.layer.type.values).map((value, layerType) => { memo.push(spec[`paint_${layerType}`][name]); return memo; }, []); -console.log(spec.layer.type.values[layerType].doc) + return { doc: spec.layer.type.values[layerType].doc, type: layerType, diff --git a/platform/darwin/scripts/style-spec-overrides-v8.json b/platform/darwin/scripts/style-spec-overrides-v8.json index a594ef2957e..58d3870c267 100644 --- a/platform/darwin/scripts/style-spec-overrides-v8.json +++ b/platform/darwin/scripts/style-spec-overrides-v8.json @@ -1,4 +1,5 @@ { + "light-cocoa-doc": "An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.", "layer": { "type": { "values": { diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index 5991f365cf9..7dc9a7e2ca2 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -8,13 +8,19 @@ NS_ASSUME_NONNULL_BEGIN - -/** Options to specify extruded geometries are lit relative to the map or viewport. */ +/** + Whether extruded geometries are lit relative to the map or viewport. + */ typedef NS_ENUM(NSUInteger, MGLLightAnchor) { - /** The position of the light source is aligned to the rotation of the map. */ + /** + The position of the light source is aligned to the rotation of the map. + */ MGLLightAnchorMap, - /** The position of the light source is aligned to the rotation of the viewport. */ - MGLLightAnchorViewport + /** + The position of the light source is aligned to the rotation of the + viewport. + */ + MGLLightAnchorViewport, }; /** @@ -57,8 +63,17 @@ MGL_EXPORT @interface MGLLight : NSObject /** - `anchor` Whether extruded geometries are lit relative to the map or viewport. + Whether extruded geometries are lit relative to the map or viewport. + + The default value of this property is an `MGLStyleValue` object containing an + `NSValue` object containing `MGLAnchorViewport`. + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of + `MGLInterpolationModeInterval` + This property corresponds to the anchor light property in the Mapbox Style Specification. @@ -66,14 +81,25 @@ MGL_EXPORT @property (nonatomic) MGLStyleValue *anchor; /** - Values describing animated transitions to `anchor` property. - */ -@property (nonatomic) MGLTransition anchorTransition; - - -/** - Position of the light source relative to lit (extruded) geometries. + Position of the light source relative to lit (extruded) geometries, in [r + radial coordinate, a azimuthal angle, p polar angle] where r indicates the + distance from the center of the base of an object to its light, a indicates the + position of the light relative to 0° (0° when `light.anchor` is set to + `MGLLight.anchorViewport` corresponds to the top of the viewport, or 0° when + `light.anchor` is set to `MGLLight.anchorMap` corresponds to due north, and + degrees proceed clockwise), and p indicates the height of the light (from 0°, + directly above, to 180°, directly below). + + The default value of this property is an `MGLStyleValue` object containing the + array `1.15`, `210`, `30`. + + You can set this property to an instance of: + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + This property corresponds to the position light property in the Mapbox Style Specification. @@ -81,48 +107,87 @@ MGL_EXPORT @property (nonatomic) MGLStyleValue *position; /** - Values describing animated transitions to `position` property. - */ -@property (nonatomic) MGLTransition positionTransiton; + The transition affecting any changes to this layer’s `position` property. + This property corresponds to the `position-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition positionTransition; #if TARGET_OS_IPHONE /** Color tint for lighting extruded geometries. + The default value of this property is an `MGLStyleValue` object containing + `UIColor.whiteColor`. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + This property corresponds to the color light property in the Mapbox Style Specification. */ @property (nonatomic) MGLStyleValue *color; #else - /** Color tint for lighting extruded geometries. + + The default value of this property is an `MGLStyleValue` object containing + `NSColor.whiteColor`. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + + This property corresponds to the color + light property in the Mapbox Style Specification. */ @property (nonatomic) MGLStyleValue *color; #endif /** - Values describing animated transitions to `color` property. - */ -@property (nonatomic) MGLTransition colorTransiton; + The transition affecting any changes to this layer’s `color` property. + This property corresponds to the `color-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition colorTransition; /** - Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. + Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as + more extreme contrast. + + The default value of this property is an `MGLStyleValue` object containing an + `NSNumber` object containing the float `0.5`. + + You can set this property to an instance of: + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + This property corresponds to the intensity light property in the Mapbox Style Specification. */ -@property(nonatomic) MGLStyleValue *intensity; +@property (nonatomic) MGLStyleValue *intensity; /** - Values describing animated transitions to `intensity` property. - */ + The transition affecting any changes to this layer’s `intensity` property. + + This property corresponds to the `intensity-transition` property in the style JSON file format. +*/ @property (nonatomic) MGLTransition intensityTransition; + @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLLight.h.ejs b/platform/darwin/src/MGLLight.h.ejs index e1bfc29fe1d..26ecefc3af6 100644 --- a/platform/darwin/src/MGLLight.h.ejs +++ b/platform/darwin/src/MGLLight.h.ejs @@ -13,14 +13,21 @@ NS_ASSUME_NONNULL_BEGIN - -/** Options to specify extruded geometries are lit relative to the map or viewport. */ -typedef NS_ENUM(NSUInteger, MGLLightAnchor) { - /** The position of the light source is aligned to the rotation of the map. */ - MGLLightAnchorMap, - /** The position of the light source is aligned to the rotation of the viewport. */ - MGLLightAnchorViewport +<% for (const property of properties) { -%> +<% if (property.type == "enum") { -%> +/** +<%- propertyDoc(property.name, property, type, 'enum').wrap(80, 1) %> + */ +typedef NS_ENUM(NSUInteger, MGLLight<%- camelize(property.name) %>) { +<% for (const value in property.values) { -%> + /** +<%- propertyDoc(property.name, property.values[value], type, 'enum').wrap(80, 4+1) %> + */ + MGLLightAnchor<%- camelize(value) %>, +<% } -%> }; +<% } -%> +<% } -%> /** A structure containing information about the position of the light source @@ -46,7 +53,7 @@ typedef struct MGLSphericalPosition { @return Returns a `MGLSphericalPosition` struct containing the position attributes. */ -NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CLLocationDistance radial, CLLocationDirection azimuthal, CLLocationDirection polar) { +NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CGFloat radial, CLLocationDirection azimuthal, CLLocationDirection polar) { MGLSphericalPosition position; position.radial = radial; position.azimuthal = azimuthal; @@ -56,77 +63,37 @@ NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CLLocationDistance radia } /** - An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`. + <%- doc %> */ MGL_EXPORT @interface MGLLight : NSObject +<% if (properties.length) { -%> +<% for (const property of properties) { -%> /** - `anchor` Whether extruded geometries are lit relative to the map or viewport. - - This property corresponds to the anchor - light property in the Mapbox Style Specification. - */ -@property (nonatomic) MGLStyleValue *anchor; - -/** - Values describing animated transitions to `anchor` property. - */ -@property (nonatomic) MGLTransition anchorTransition; - - -/** - Position of the light source relative to lit (extruded) geometries. - - This property corresponds to the position - light property in the Mapbox Style Specification. - */ -@property (nonatomic) MGLStyleValue *position; - -/** - Values describing animated transitions to `position` property. - */ -@property (nonatomic) MGLTransition positionTransiton; +<%- propertyDoc(property.name, property, type, 'light').wrap(80, 1) %> - -#if TARGET_OS_IPHONE -/** - Color tint for lighting extruded geometries. - This property corresponds to the color + href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-<%- originalPropertyName(property) %>"><%- originalPropertyName(property) %> light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLStyleValue *color; -#else +@property (nonatomic<% if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(property.name) %>; +<% if (property.transition) { -%> /** - Color tint for lighting extruded geometries. - */ -@property (nonatomic) MGLStyleValue *color; -#endif + The transition affecting any changes to this layer’s `<%- camelizeWithLeadingLowercase(property.name) %>` property. -/** - Values describing animated transitions to `color` property. - */ -@property (nonatomic) MGLTransition colorTransiton; + This property corresponds to the `<%- originalPropertyName(property) %>-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition <%- camelizeWithLeadingLowercase(property.name) %>Transition; +<% } -%> +<% if (property.original) { -%> +@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); -/** - Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. - - This property corresponds to the intensity - light property in the Mapbox Style Specification. - */ -@property(nonatomic) MGLStyleValue *intensity; - -/** - Values describing animated transitions to `intensity` property. - */ -@property (nonatomic) MGLTransition intensityTransition; +<% } -%> +<% } -%> +<% } -%> @end diff --git a/platform/darwin/src/MGLLight.mm b/platform/darwin/src/MGLLight.mm index 92eb78b9745..c83ef127a6c 100644 --- a/platform/darwin/src/MGLLight.mm +++ b/platform/darwin/src/MGLLight.mm @@ -51,11 +51,9 @@ - (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight } else { anchorStyleValue = MGLStyleValueTransformer().toEnumStyleValue(anchor); } - + _anchor = anchorStyleValue; - - _anchorTransition = MGLTransitionFromOptions(mbglLight->getAnchorTransition()); - + auto positionValue = mbglLight->getPosition(); if (positionValue.isUndefined()) { _position = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultPosition()); @@ -63,8 +61,8 @@ - (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight _position = MGLStyleValueTransformer().toStyleValue(positionValue); } - _positionTransiton = MGLTransitionFromOptions(mbglLight->getPositionTransition()); - + _positionTransition = MGLTransitionFromOptions(mbglLight->getPositionTransition()); + auto colorValue = mbglLight->getColor(); if (colorValue.isUndefined()) { _color = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultColor()); @@ -72,8 +70,8 @@ - (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight _color = MGLStyleValueTransformer().toStyleValue(colorValue); } - _colorTransiton = MGLTransitionFromOptions(mbglLight->getColorTransition()); - + _colorTransition = MGLTransitionFromOptions(mbglLight->getColorTransition()); + auto intensityValue = mbglLight->getIntensity(); if (intensityValue.isUndefined()) { _intensity = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultIntensity()); @@ -82,6 +80,7 @@ - (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight } _intensityTransition = MGLTransitionFromOptions(mbglLight->getIntensityTransition()); + } return self; @@ -90,26 +89,24 @@ - (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight - (mbgl::style::Light)mbglLight { mbgl::style::Light mbglLight; - auto anchor = MGLStyleValueTransformer().toEnumPropertyValue(self.anchor); mbglLight.setAnchor(anchor); - - mbglLight.setAnchorTransition(MGLOptionsFromTransition(self.anchorTransition)); - + auto position = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.position); mbglLight.setPosition(position); - - mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransiton)); - + + mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransition)); + auto color = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.color); mbglLight.setColor(color); - - mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransiton)); - + + mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransition)); + auto intensity = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.intensity); mbglLight.setIntensity(intensity); - + mbglLight.setIntensityTransition(MGLOptionsFromTransition(self.intensityTransition)); + return mbglLight; } diff --git a/platform/darwin/src/MGLLight.mm.ejs b/platform/darwin/src/MGLLight.mm.ejs index d9469564840..0d0da124c8e 100644 --- a/platform/darwin/src/MGLLight.mm.ejs +++ b/platform/darwin/src/MGLLight.mm.ejs @@ -51,45 +51,37 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition - (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight { if (self = [super init]) { - auto anchor = mbglLight->getAnchor(); - MGLStyleValue *anchorStyleValue; - if (anchor.isUndefined()) { - mbgl::style::PropertyValue defaultAnchor = mbglLight->getDefaultAnchor(); - anchorStyleValue = MGLStyleValueTransformer().toEnumStyleValue(defaultAnchor); - } else { - anchorStyleValue = MGLStyleValueTransformer().toEnumStyleValue(anchor); - } - - _anchor = anchorStyleValue; - - _anchorTransition = MGLTransitionFromOptions(mbglLight->getAnchorTransition()); - - auto positionValue = mbglLight->getPosition(); - if (positionValue.isUndefined()) { - _position = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultPosition()); - } else { - _position = MGLStyleValueTransformer().toStyleValue(positionValue); - } - - _positionTransiton = MGLTransitionFromOptions(mbglLight->getPositionTransition()); - - auto colorValue = mbglLight->getColor(); - if (colorValue.isUndefined()) { - _color = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultColor()); +<% if (properties.length) { -%> +<% for (const property of properties) { -%> +<% if (property.type == "enum") { -%> + auto <%- camelizeWithLeadingLowercase(property.name) -%> = mbglLight->get<%- camelize(property.name) -%>(); + MGLStyleValue *<%- camelizeWithLeadingLowercase(property.name) -%>StyleValue; + if (<%- camelizeWithLeadingLowercase(property.name) -%>.isUndefined()) { + mbgl::style::PropertyValueType> default<%- camelize(property.name) -%> = mbglLight->getDefault<%- camelize(property.name) -%>(); + <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue = MGLStyleValueTransformerType, MGLLight<%- camelize(property.name) -%>>().toEnumStyleValue(default<%- camelize(property.name) -%>); } else { - _color = MGLStyleValueTransformer().toStyleValue(colorValue); + <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue = MGLStyleValueTransformerType, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumStyleValue(<%- camelizeWithLeadingLowercase(property.name) -%>); } - - _colorTransiton = MGLTransitionFromOptions(mbglLight->getColorTransition()); - - auto intensityValue = mbglLight->getIntensity(); - if (intensityValue.isUndefined()) { - _intensity = MGLStyleValueTransformer().toStyleValue(mbglLight->getDefaultIntensity()); + + _<%- camelizeWithLeadingLowercase(property.name) -%> = <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue; + +<% if (property.transition) { -%> + _<%- camelizeWithLeadingLowercase(property.name) -%>Transition = MGLTransitionFromOptions(mbglLight->get<%- camelize(property.name) -%>Transition()); + +<% } -%> +<% } else {-%> + auto <%- camelizeWithLeadingLowercase(property.name) -%>Value = mbglLight->get<%- camelize(property.name) -%>(); + if (<%- camelizeWithLeadingLowercase(property.name) -%>Value.isUndefined()) { + _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(mbglLight->getDefault<%- camelize(property.name) -%>()); } else { - _intensity = MGLStyleValueTransformer().toStyleValue(intensityValue); + _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(<%- camelizeWithLeadingLowercase(property.name) -%>Value); } - - _intensityTransition = MGLTransitionFromOptions(mbglLight->getIntensityTransition()); +<% if (property.transition) { -%> + _<%- camelizeWithLeadingLowercase(property.name) -%>Transition = MGLTransitionFromOptions(mbglLight->get<%- camelize(property.name) -%>Transition()); +<% } -%> +<% } -%> +<% } -%> +<% } -%> } return self; @@ -98,26 +90,23 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition - (mbgl::style::Light)mbglLight { mbgl::style::Light mbglLight; - - auto anchor = MGLStyleValueTransformer().toEnumPropertyValue(self.anchor); - mbglLight.setAnchor(anchor); - - mbglLight.setAnchorTransition(MGLOptionsFromTransition(self.anchorTransition)); - - auto position = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.position); - mbglLight.setPosition(position); - - mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransiton)); - - auto color = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.color); - mbglLight.setColor(color); - - mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransiton)); - - auto intensity = MGLStyleValueTransformer().toInterpolatablePropertyValue(self.intensity); - mbglLight.setIntensity(intensity); - - mbglLight.setIntensityTransition(MGLOptionsFromTransition(self.intensityTransition)); +<% if (properties.length) { -%> +<% for (const property of properties) { -%> +<% if (property.type == "enum") { -%> + auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformerType, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumPropertyValue(self.<%- camelizeWithLeadingLowercase(property.name) -%>); + mbglLight.set<%- camelize(property.name) -%>(<%- camelizeWithLeadingLowercase(property.name) -%>); + +<% } else {-%> + auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toInterpolatablePropertyValue(self.<%- camelizeWithLeadingLowercase(property.name) -%>); + mbglLight.set<%- camelize(property.name) -%>(<%- camelizeWithLeadingLowercase(property.name) -%>); + +<% } -%> +<% if (property.transition) { -%> + mbglLight.set<%- camelize(property.name) -%>Transition(MGLOptionsFromTransition(self.<%- camelizeWithLeadingLowercase(property.name) -%>Transition)); + +<% } -%> +<% } -%> +<% } -%> return mbglLight; } From 009063e174e75c42fb8977feaa247373296251d0 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Wed, 14 Jun 2017 21:35:50 -0400 Subject: [PATCH 4/6] [ios, macos] Add the auto-generation script for MGLLightTest.mm --- .../darwin/scripts/generate-style-code.js | 6 +- platform/darwin/src/MGLLight.h | 2 +- platform/darwin/test/MGLLightTest.mm | 140 ++++++-- platform/darwin/test/MGLLightTest.mm.ejs | 308 ++++++++++++++++++ 4 files changed, 434 insertions(+), 22 deletions(-) create mode 100644 platform/darwin/test/MGLLightTest.mm.ejs diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 38e1a4bfebc..bc5b0ab983f 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -539,10 +539,12 @@ const forStyleAuthorsMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guid const ddsGuideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Using Style Functions at Runtime.md.ejs', 'utf8'), { strict: true }); const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Tile URL Templates.md.ejs', 'utf8'), { strict: true }); -const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true});; -const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true});; +const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true}); +const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true}); +const testLight = ejs.compile(fs.readFileSync('platform/darwin/test/MGLLightTest.mm.ejs', 'utf8'), { strict: true}); fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc}))); fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc})); +fs.writeFileSync(`platform/darwin/test/MGLLightTest.mm`, testLight({ properties: lightProperties, doc: lightDoc})); const layers = _(spec.layer.type.values).map((value, layerType) => { diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index 7dc9a7e2ca2..f08f02b5d23 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -47,7 +47,7 @@ typedef struct MGLSphericalPosition { @return Returns a `MGLSphericalPosition` struct containing the position attributes. */ -NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CLLocationDistance radial, CLLocationDirection azimuthal, CLLocationDirection polar) { +NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CGFloat radial, CLLocationDirection azimuthal, CLLocationDirection polar) { MGLSphericalPosition position; position.radial = radial; position.azimuthal = azimuthal; diff --git a/platform/darwin/test/MGLLightTest.mm b/platform/darwin/test/MGLLightTest.mm index 2c3d1c7bd1e..ae3d79c4e30 100644 --- a/platform/darwin/test/MGLLightTest.mm +++ b/platform/darwin/test/MGLLightTest.mm @@ -1,3 +1,5 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import #import @@ -20,13 +22,115 @@ - (void)testProperties { MGLTransition defaultTransition = MGLTransitionMake(0, 0); MGLTransition transition = MGLTransitionMake(6, 3); mbgl::style::TransitionOptions transitionOptions { { MGLDurationFromTimeInterval(6) }, { MGLDurationFromTimeInterval(3) } }; - + // anchor { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; + XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); + + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor().asConstant()); + + + } + + // position + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); + NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; + auto positionArray = light.getDefaultPosition().getSpherical(); + MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); + + XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); + XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); + XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); + + // Default transition test + XCTAssertEqual(mglLight.positionTransition.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.positionTransition.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); + + // transition test + auto positionTransition = lightFromMGLlight.getPositionTransition(); + XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); + XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); + + } + + // color + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); + NSValue *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; + MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; + auto color = light.getDefaultColor(); + const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor); - NSAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + XCTAssert(color.r == colorComponents[0] && color.g == colorComponents[1] && color.b == colorComponents[2] && + color.a == colorComponents[3]); + + // Default transition test + XCTAssertEqual(mglLight.colorTransition.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.colorTransition.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(color, lightFromMGLlight.getColor().asConstant()); + + // transition test + auto colorTransition = lightFromMGLlight.getColorTransition(); + XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); + XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); + + } + + // intensity + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); + NSValue *intensityValue = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; + NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; + auto intensity = light.getDefaultIntensity(); + + XCTAssert(intensityNumber.floatValue == intensity); + + // Default transition test + XCTAssertEqual(mglLight.intensityTransition.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.intensityTransition.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(intensity, lightFromMGLlight.getIntensity().asConstant()); + + // transition test + auto intensityTransition = lightFromMGLlight.getIntensityTransition(); + XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); + XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); + + } + + // anchor + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); XCTAssertEqual(mglLight.anchorTransition.delay, defaultTransition.delay); @@ -41,11 +145,11 @@ - (void)testProperties { MGLStyleValue *anchorStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; mglLight.anchor = anchorStyleValue; - mglLight.anchorTransition = transition; - NSAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); + + mglLight.anchorTransition = transition; XCTAssertEqual(mglLight.anchorTransition.delay, transition.delay); XCTAssertEqual(mglLight.anchorTransition.duration, transition.duration); @@ -66,7 +170,7 @@ - (void)testProperties { { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - NSAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; auto positionArray = light.getDefaultPosition().getSpherical(); MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); @@ -87,14 +191,13 @@ - (void)testProperties { defaultPosition = MGLSphericalPositionMake(6, 180, 90); MGLStyleValue *positionStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]]; mglLight.position = positionStyleValue; - mglLight.positionTransiton = transition; - - NSAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); + + mglLight.positionTransiton = transition; XCTAssertEqual(mglLight.positionTransiton.delay, transition.delay); XCTAssertEqual(mglLight.positionTransiton.duration, transition.duration); @@ -117,7 +220,7 @@ - (void)testProperties { { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - NSAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; auto color = light.getDefaultColor(); const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor); @@ -136,12 +239,11 @@ - (void)testProperties { MGLStyleValue *colorStyleValue = [MGLStyleValue valueWithRawValue:[MGLColor blackColor]]; mglLight.color = colorStyleValue; - mglLight.colorTransiton = transition; - - NSAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - XCTAssertEqual([MGLColor blackColor], colorValue); + + mglLight.colorTransiton = transition; XCTAssertEqual(mglLight.colorTransiton.delay, transition.delay); XCTAssertEqual(mglLight.colorTransiton.duration, transition.duration); @@ -163,7 +265,7 @@ - (void)testProperties { { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - NSAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; auto intensity = light.getDefaultIntensity(); @@ -181,11 +283,11 @@ - (void)testProperties { NSNumber *intensityValue = @0.4; MGLStyleValue *intensityStyleValue = [MGLStyleValue valueWithRawValue:intensityValue]; mglLight.intensity = intensityStyleValue; - mglLight.intensityTransition = transition; - - NSAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); + XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; XCTAssert(intensityNumber.floatValue == intensityValue.floatValue); + + mglLight.intensityTransition = transition; XCTAssertEqual(mglLight.intensityTransition.delay, transition.delay); XCTAssertEqual(mglLight.intensityTransition.duration, transition.duration); diff --git a/platform/darwin/test/MGLLightTest.mm.ejs b/platform/darwin/test/MGLLightTest.mm.ejs new file mode 100644 index 00000000000..a4219583557 --- /dev/null +++ b/platform/darwin/test/MGLLightTest.mm.ejs @@ -0,0 +1,308 @@ +<% + const properties = locals.properties; +-%> +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#import +#import + +#import "MGLLight_Private.h" + +#import "../../darwin/src/NSDate+MGLAdditions.h" + +#import +#import +#include + +@interface MGLLightTest : XCTestCase + +@end + +@implementation MGLLightTest + +- (void)testProperties { + + MGLTransition defaultTransition = MGLTransitionMake(0, 0); + MGLTransition transition = MGLTransitionMake(6, 3); + mbgl::style::TransitionOptions transitionOptions { { MGLDurationFromTimeInterval(6) }, { MGLDurationFromTimeInterval(3) } }; + +<% for (const property of properties) { -%> + // <%- property.name %> + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isn’t a MGLConstantStyleValue."); + NSValue *<%- camelizeWithLeadingLowercase(property.name) -%>Value = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; +<% if (property.type == "enum") { -%> + XCTAssertEqual(<%- camelizeWithLeadingLowercase(property.name) -%>Value.MGLLight<%- camelize(property.name) -%>Value, MGLLight<%- camelize(property.name) -%><%- camelize(property.default) -%>); +<% } else if (property.type == "array") { -%> + auto positionArray = light.getDefaultPosition().getSpherical(); + MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); + + XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); + XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); + XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); +<% } else if (property.type == "color") {-%> + MGLColor *<%- camelizeWithLeadingLowercase(property.name) -%>Value = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; + auto <%- camelizeWithLeadingLowercase(property.name) -%> = light.getDefault<%- camelize(property.name) -%>(); + const CGFloat *<%- camelizeWithLeadingLowercase(property.name) -%>Components = CGColorGetComponents(<%- camelizeWithLeadingLowercase(property.name) -%>Value.CGColor); + + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>.r == <%- camelizeWithLeadingLowercase(property.name) -%>Components[0] && <%- camelizeWithLeadingLowercase(property.name) -%>.g == <%- camelizeWithLeadingLowercase(property.name) -%>Components[1] && <%- camelizeWithLeadingLowercase(property.name) -%>.b == <%- camelizeWithLeadingLowercase(property.name) -%>Components[2] && + <%- camelizeWithLeadingLowercase(property.name) -%>.a == <%- camelizeWithLeadingLowercase(property.name) -%>Components[3]); +<% } else if (property.type == "number") { -%> + NSNumber *<%- camelizeWithLeadingLowercase(property.name) -%>Number = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; + auto <%- camelizeWithLeadingLowercase(property.name) -%> = light.getDefault<%- camelize(property.name) -%>(); + + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Number.floatValue == <%- camelizeWithLeadingLowercase(property.name) -%>); +<% } else { -%> + XCTAssertTrue(NO, @"<%- camelizeWithLeadingLowercase(property.name) -%> has not implementation in the test generation script."); +<% } -%> +<% if (property.transition) { -%> + // Default transition test + XCTAssertEqual(mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration, defaultTransition.duration); +<% } -%> + auto lightFromMGLlight = [mglLight mbglLight]; + +<% if (property.type == "enum") { -%> + XCTAssertEqual(light.getDefault<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>().asConstant()); +<% } else if (property.type == "array") { -%> + XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); +<% } else { -%> + XCTAssertEqual(<%- camelizeWithLeadingLowercase(property.name) -%>, lightFromMGLlight.get<%- camelize(property.name) -%>().asConstant()); +<% } -%> +<% if (property.transition) { -%> + // transition test + auto <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition(); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); +<% } -%> +<% if (property.type == "enum") { -%> + MGLStyleValue<<%- propertyType(property) %>> *anchorStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; + mglLight.anchor = anchorStyleValue; + XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; + XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); +<% } else if (property.type == "array") { -%> + defaultPosition = MGLSphericalPositionMake(6, 180, 90); + MGLStyleValue<<%- propertyType(property) %>> *positionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]]; + mglLight.position = positionStyleValue; + XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); + positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; + XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); + XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); + XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); +<% } else if (property.type == "color") {-%> + MGLStyleValue<<%- propertyType(property) %>> *colorStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:[MGLColor blackColor]]; + mglLight.color = colorStyleValue; + XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); + colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; + XCTAssertEqual([MGLColor blackColor], colorValue); +<% } else if (property.type == "number") { -%> + NSNumber *intensityValue = @0.4; + MGLStyleValue<<%- propertyType(property) %>> *intensityStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:intensityValue]; + mglLight.intensity = intensityStyleValue; + XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); + intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; + XCTAssert(intensityNumber.floatValue == intensityValue.floatValue); +<% } else { -%> + XCTAssertTrue(NO, @"<%- camelizeWithLeadingLowercase(property.name) -%> has not implementation in the test generation script."); +<% } -%> + } + +<% } -%> + // anchor + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + + XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; + XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); + XCTAssertEqual(mglLight.anchorTransition.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.anchorTransition.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor().asConstant()); + auto anchorTransition = lightFromMGLlight.getAnchorTransition(); + XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); + XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); + + MGLStyleValue *anchorStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; + mglLight.anchor = anchorStyleValue; + mglLight.anchorTransition = transition; + XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); + anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; + + XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); + XCTAssertEqual(mglLight.anchorTransition.delay, transition.delay); + XCTAssertEqual(mglLight.anchorTransition.duration, transition.duration); + + mbgl::style::PropertyValue anchorProperty = { mbgl::style::LightAnchorType::Map }; + light.setAnchor(anchorProperty); + light.setAnchorTransition(transitionOptions); + + lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getAnchor().asConstant(), lightFromMGLlight.getAnchor().asConstant()); + anchorTransition = lightFromMGLlight.getAnchorTransition(); + XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == transition.delay); + XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == transition.duration); + + } + + // position + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); + NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; + auto positionArray = light.getDefaultPosition().getSpherical(); + MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); + + XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); + XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); + XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); + XCTAssertEqual(mglLight.positionTransiton.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.positionTransiton.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); + auto positionTransition = lightFromMGLlight.getPositionTransition(); + XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == defaultTransition.delay); + XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == defaultTransition.duration); + + defaultPosition = MGLSphericalPositionMake(6, 180, 90); + MGLStyleValue *positionStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]]; + mglLight.position = positionStyleValue; + mglLight.positionTransiton = transition; + + XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); + positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; + + XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); + XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); + XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); + XCTAssertEqual(mglLight.positionTransiton.delay, transition.delay); + XCTAssertEqual(mglLight.positionTransiton.duration, transition.duration); + + lightFromMGLlight = [mglLight mbglLight]; + + positionArray = { { 6, 180, 90 } }; + mbgl::style::Position position = { positionArray }; + mbgl::style::PropertyValue positionProperty = { position }; + light.setPosition(positionProperty); + light.setPositionTransition(transitionOptions); + + XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); + positionTransition = lightFromMGLlight.getPositionTransition(); + XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == transition.delay); + XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == transition.duration); + + } + + // color + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); + MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; + auto color = light.getDefaultColor(); + const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor); + + XCTAssert(color.r == colorComponents[0] && color.g == colorComponents[1] && color.b == colorComponents[2] && + color.a == colorComponents[3]); + XCTAssertEqual(mglLight.colorTransiton.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.colorTransiton.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(color, lightFromMGLlight.getColor().asConstant()); + auto colorTransition = lightFromMGLlight.getColorTransition(); + XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == defaultTransition.delay); + XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == defaultTransition.duration); + + MGLStyleValue *colorStyleValue = [MGLStyleValue valueWithRawValue:[MGLColor blackColor]]; + mglLight.color = colorStyleValue; + mglLight.colorTransiton = transition; + + XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); + colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; + + XCTAssertEqual([MGLColor blackColor], colorValue); + XCTAssertEqual(mglLight.colorTransiton.delay, transition.delay); + XCTAssertEqual(mglLight.colorTransiton.duration, transition.duration); + + mbgl::style::PropertyValue colorProperty = { { 0, 0, 0, 1 } }; + light.setColor(colorProperty); + light.setColorTransition(transitionOptions); + + lightFromMGLlight = [mglLight mbglLight]; + + colorComponents = CGColorGetComponents(colorValue.CGColor); + color = lightFromMGLlight.getColor().asConstant(); + XCTAssertEqual(light.getColor().asConstant(),lightFromMGLlight.getColor().asConstant()); + colorTransition = lightFromMGLlight.getColorTransition(); + XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == transition.delay); + XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == transition.duration); + } + + // intensity + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); + NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; + auto intensity = light.getDefaultIntensity(); + + XCTAssert(intensityNumber.floatValue == intensity); + XCTAssertEqual(mglLight.intensityTransition.delay, defaultTransition.delay); + XCTAssertEqual(mglLight.intensityTransition.duration, defaultTransition.duration); + + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(intensity, lightFromMGLlight.getIntensity().asConstant()); + auto intensityTransition = lightFromMGLlight.getIntensityTransition(); + XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == defaultTransition.delay); + XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == defaultTransition.duration); + + NSNumber *intensityValue = @0.4; + MGLStyleValue *intensityStyleValue = [MGLStyleValue valueWithRawValue:intensityValue]; + mglLight.intensity = intensityStyleValue; + mglLight.intensityTransition = transition; + + XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); + intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; + XCTAssert(intensityNumber.floatValue == intensityValue.floatValue); + XCTAssertEqual(mglLight.intensityTransition.delay, transition.delay); + XCTAssertEqual(mglLight.intensityTransition.duration, transition.duration); + + mbgl::style::PropertyValue intensityProperty = { 0.4 }; + light.setIntensity(intensityProperty); + light.setIntensityTransition(transitionOptions); + + lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getIntensity().asConstant(), lightFromMGLlight.getIntensity().asConstant()); + intensityTransition = lightFromMGLlight.getIntensityTransition(); + XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == transition.delay); + XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == transition.duration); + + } + +} + +- (void)testValueAdditions { + MGLSphericalPosition position = MGLSphericalPositionMake(1.15, 210, 30); + + XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.radial, position.radial); + XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.azimuthal, position.azimuthal); + XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.polar, position.polar); + XCTAssertEqual([NSValue valueWithMGLLightAnchor:MGLLightAnchorMap].MGLLightAnchorValue, MGLLightAnchorMap); + XCTAssertEqual([NSValue valueWithMGLLightAnchor:MGLLightAnchorViewport].MGLLightAnchorValue, MGLLightAnchorViewport); +} + +@end From ca29d6d3c5796f3d37451dc333d5e7d5cb4a527e Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 15 Jun 2017 15:29:44 -0400 Subject: [PATCH 5/6] [core] Add const to Position constructor. --- include/mbgl/style/position.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbgl/style/position.hpp b/include/mbgl/style/position.hpp index 3be8d1c55e0..078e62bda89 100644 --- a/include/mbgl/style/position.hpp +++ b/include/mbgl/style/position.hpp @@ -9,7 +9,7 @@ namespace style { class Position { public: Position() = default; - Position(std::array& position_) + Position(const std::array& position_) : radial(position_[0]), azimuthal(position_[1]), polar(position_[2]) { calculateCartesian(); }; From 91a69839ded0cc4a27513e7e7099cf7e2d4b5a2f Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 15 Jun 2017 15:32:24 -0400 Subject: [PATCH 6/6] [ios, macos] Simplify MGLLightTest.mm autogenerate script. --- .../darwin/scripts/generate-style-code.js | 24 +- .../scripts/style-spec-overrides-v8.json | 5 + platform/darwin/src/MGLLight.h | 24 +- platform/darwin/test/MGLLightTest.mm | 263 +++------------- platform/darwin/test/MGLLightTest.mm.ejs | 284 +++--------------- 5 files changed, 114 insertions(+), 486 deletions(-) diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index bc5b0ab983f..5a4936c0ee9 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -149,6 +149,9 @@ global.mbglTestValue = function (property, layerType) { type = 'Alignment'; } let value = camelize(_.last(_.keys(property.values))); + if (property['light-property']) { + return `mbgl::style::Light${type}Type::${value}`; + } return `mbgl::style::${type}Type::${value}`; } case 'color': @@ -225,6 +228,9 @@ global.propertyDoc = function (propertyName, property, layerType, kind) { let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) { let otherProperty = camelizeWithLeadingLowercase(peerPropertyName); let otherValue = objCType(layerType, peerPropertyName) + camelize(propertyValue); + if (property.type == 'array' && kind == 'light') { + otherValue = propertyValue; + } return '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`'; }); // Match references to our own property values. @@ -348,6 +354,8 @@ global.describeValue = function (value, property, layerType) { let objCType = global.objCType(layerType, property.name); return `${conjunction}\`${objCType}${camelize(possibleValue)}\``; }).join(separator); + } else if (property['light-property']) { + displayValue = `\`${prefix}Light${camelize(property.name)}${camelize(value)}\``; } else { let objCType = global.objCType(layerType, property.name); displayValue = `\`${objCType}${camelize(value)}\``; @@ -382,6 +390,8 @@ global.describeValue = function (value, property, layerType) { case 'offset': case 'translate': return 'an `NSValue` object containing a `CGVector` struct set to' + ` ${value[0]}${units} rightward and ${value[1]}${units} downward`; + case 'position': + return 'an `MGLSphericalPosition` struct set to' + ` ${value[0]} radial, ${value[1]} azimuthal and ${value[2]} polar`; default: return 'the array `' + value.join('`, `') + '`'; } @@ -481,6 +491,9 @@ global.mbglType = function(property) { return 'std::string'; case 'enum': { let type = camelize(originalPropertyName(property)); + if (property['light-property']) { + return `mbgl::style::Light${type}Type`; + } if (/-translate-anchor$/.test(originalPropertyName(property))) { type = 'TranslateAnchor'; } @@ -502,6 +515,8 @@ global.mbglType = function(property) { case 'offset': case 'translate': return 'std::array'; + case 'position': + return 'mbgl::style::Position'; default: throw new Error(`unknown array type for ${property.name}`); } @@ -530,7 +545,8 @@ const lightProperties = Object.keys(spec['light']).reduce((memo, name) => { return memo; }, []); -const lightDoc = spec[`light-cocoa-doc`]; +const lightDoc = spec['light-cocoa-doc']; +const lightType = 'light'; const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); @@ -542,9 +558,9 @@ const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Til const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true}); const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true}); const testLight = ejs.compile(fs.readFileSync('platform/darwin/test/MGLLightTest.mm.ejs', 'utf8'), { strict: true}); -fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc}))); -fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc})); -fs.writeFileSync(`platform/darwin/test/MGLLightTest.mm`, testLight({ properties: lightProperties, doc: lightDoc})); +fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc, type: lightType }))); +fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc, type: lightType })); +fs.writeFileSync(`platform/darwin/test/MGLLightTest.mm`, testLight({ properties: lightProperties, doc: lightDoc, type: lightType })); const layers = _(spec.layer.type.values).map((value, layerType) => { diff --git a/platform/darwin/scripts/style-spec-overrides-v8.json b/platform/darwin/scripts/style-spec-overrides-v8.json index 58d3870c267..67a6641fe7b 100644 --- a/platform/darwin/scripts/style-spec-overrides-v8.json +++ b/platform/darwin/scripts/style-spec-overrides-v8.json @@ -1,5 +1,10 @@ { "light-cocoa-doc": "An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.", + "light": { + "position": { + "doc": "Position of the `MGLLight` source relative to lit (extruded) geometries, in a `MGLSphericalPosition` struct [radial coordinate, azimuthal angle, polar angle] where radial indicates the distance from the center of the base of an object to its light, azimuthal indicates the position of the light relative to 0° (0° when `MGLLight.anchor` is set to `MGLLightAnchorViewport` corresponds to the top of the viewport, or 0° when `MGLLight.anchor` is set to `MGLLightAnchorMap` corresponds to due north, and degrees proceed clockwise), and polar indicates the height of the light (from 0°, directly above, to 180°, directly below)." + } + }, "layer": { "type": { "values": { diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index f08f02b5d23..55b789f0432 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -66,7 +66,7 @@ MGL_EXPORT Whether extruded geometries are lit relative to the map or viewport. The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLAnchorViewport`. + `NSValue` object containing `MGLLightAnchorViewport`. You can set this property to an instance of: @@ -81,17 +81,17 @@ MGL_EXPORT @property (nonatomic) MGLStyleValue *anchor; /** - Position of the light source relative to lit (extruded) geometries, in [r - radial coordinate, a azimuthal angle, p polar angle] where r indicates the - distance from the center of the base of an object to its light, a indicates the - position of the light relative to 0° (0° when `light.anchor` is set to - `MGLLight.anchorViewport` corresponds to the top of the viewport, or 0° when - `light.anchor` is set to `MGLLight.anchorMap` corresponds to due north, and - degrees proceed clockwise), and p indicates the height of the light (from 0°, - directly above, to 180°, directly below). - - The default value of this property is an `MGLStyleValue` object containing the - array `1.15`, `210`, `30`. + Position of the `MGLLight` source relative to lit (extruded) geometries, in a + `MGLSphericalPosition` struct [radial coordinate, azimuthal angle, polar angle] + where radial indicates the distance from the center of the base of an object to + its light, azimuthal indicates the position of the light relative to 0° (0° + when `MGLLight.anchor` is set to `MGLLightAnchorViewport` corresponds to the + top of the viewport, or 0° when `MGLLight.anchor` is set to `MGLLightAnchorMap` + corresponds to due north, and degrees proceed clockwise), and polar indicates + the height of the light (from 0°, directly above, to 180°, directly below). + + The default value of this property is an `MGLStyleValue` object containing an + `MGLSphericalPosition` struct set to 1.15 radial, 210 azimuthal and 30 polar. You can set this property to an instance of: diff --git a/platform/darwin/test/MGLLightTest.mm b/platform/darwin/test/MGLLightTest.mm index ae3d79c4e30..b021bd1b73a 100644 --- a/platform/darwin/test/MGLLightTest.mm +++ b/platform/darwin/test/MGLLightTest.mm @@ -27,281 +27,104 @@ - (void)testProperties { { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + auto lightFromMGLlight = [mglLight mbglLight]; + XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor()); XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); - - - auto lightFromMGLlight = [mglLight mbglLight]; - XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor().asConstant()); + mbgl::style::PropertyValue propertyValue = { mbgl::style::LightAnchorType::Viewport }; + light.setAnchor(propertyValue); + mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getAnchor(), lightFromMGLlight.getAnchor()); } // position { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - - XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); - NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - auto positionArray = light.getDefaultPosition().getSpherical(); - MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); - - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); - - // Default transition test - XCTAssertEqual(mglLight.positionTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.positionTransition.duration, defaultTransition.duration); - auto lightFromMGLlight = [mglLight mbglLight]; - XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); - - // transition test + XCTAssertEqual(light.getDefaultPosition(), lightFromMGLlight.getPosition()); auto positionTransition = lightFromMGLlight.getPositionTransition(); - XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); - XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); - - } - - // color - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - - XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); - NSValue *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - auto color = light.getDefaultColor(); - const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor); - - XCTAssert(color.r == colorComponents[0] && color.g == colorComponents[1] && color.b == colorComponents[2] && - color.a == colorComponents[3]); - - // Default transition test - XCTAssertEqual(mglLight.colorTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.colorTransition.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(color, lightFromMGLlight.getColor().asConstant()); - - // transition test - auto colorTransition = lightFromMGLlight.getColorTransition(); - XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); - XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); - - } - - // intensity - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == defaultTransition.delay); + XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == defaultTransition.duration); - XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); - NSValue *intensityValue = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - auto intensity = light.getDefaultIntensity(); - - XCTAssert(intensityNumber.floatValue == intensity); - - // Default transition test - XCTAssertEqual(mglLight.intensityTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.intensityTransition.duration, defaultTransition.duration); + const std::array positionArray = { { 6, 180, 90 } }; + mbgl::style::Position position = { positionArray }; + mbgl::style::PropertyValue propertyValue = { position }; - auto lightFromMGLlight = [mglLight mbglLight]; + light.setPosition(propertyValue); + light.setPositionTransition(transitionOptions); - XCTAssertEqual(intensity, lightFromMGLlight.getIntensity().asConstant()); - // transition test - auto intensityTransition = lightFromMGLlight.getIntensityTransition(); - XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); - XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); - - } - - // anchor - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - - XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); - NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); - XCTAssertEqual(mglLight.anchorTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.anchorTransition.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor().asConstant()); - auto anchorTransition = lightFromMGLlight.getAnchorTransition(); - XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); - XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); - - MGLStyleValue *anchorStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; - mglLight.anchor = anchorStyleValue; - XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); - anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); - - mglLight.anchorTransition = transition; - XCTAssertEqual(mglLight.anchorTransition.delay, transition.delay); - XCTAssertEqual(mglLight.anchorTransition.duration, transition.duration); - - mbgl::style::PropertyValue anchorProperty = { mbgl::style::LightAnchorType::Map }; - light.setAnchor(anchorProperty); - light.setAnchorTransition(transitionOptions); - - lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(light.getAnchor().asConstant(), lightFromMGLlight.getAnchor().asConstant()); - anchorTransition = lightFromMGLlight.getAnchorTransition(); - XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == transition.delay); - XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == transition.duration); - - } - - // position - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); - NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - auto positionArray = light.getDefaultPosition().getSpherical(); - MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); - - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); - XCTAssertEqual(mglLight.positionTransiton.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.positionTransiton.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); - auto positionTransition = lightFromMGLlight.getPositionTransition(); - XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == defaultTransition.delay); - XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == defaultTransition.duration); - - defaultPosition = MGLSphericalPositionMake(6, 180, 90); - MGLStyleValue *positionStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]]; - mglLight.position = positionStyleValue; - XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); - positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); - - mglLight.positionTransiton = transition; - XCTAssertEqual(mglLight.positionTransiton.delay, transition.delay); - XCTAssertEqual(mglLight.positionTransiton.duration, transition.duration); - + mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; lightFromMGLlight = [mglLight mbglLight]; - - positionArray = { { 6, 180, 90 } }; - mbgl::style::Position position = { positionArray }; - mbgl::style::PropertyValue positionProperty = { position }; - light.setPosition(positionProperty); - light.setPositionTransition(transitionOptions); - XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); + XCTAssertEqual(light.getPosition(), lightFromMGLlight.getPosition()); positionTransition = lightFromMGLlight.getPositionTransition(); XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == transition.delay); XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == transition.duration); } - + // color { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); - MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - auto color = light.getDefaultColor(); - const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor); - - XCTAssert(color.r == colorComponents[0] && color.g == colorComponents[1] && color.b == colorComponents[2] && - color.a == colorComponents[3]); - XCTAssertEqual(mglLight.colorTransiton.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.colorTransiton.duration, defaultTransition.duration); - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(color, lightFromMGLlight.getColor().asConstant()); + + XCTAssertEqual(light.getDefaultColor(), lightFromMGLlight.getColor()); auto colorTransition = lightFromMGLlight.getColorTransition(); XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == defaultTransition.delay); XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == defaultTransition.duration); - - MGLStyleValue *colorStyleValue = [MGLStyleValue valueWithRawValue:[MGLColor blackColor]]; - mglLight.color = colorStyleValue; - XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); - colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - XCTAssertEqual([MGLColor blackColor], colorValue); - - mglLight.colorTransiton = transition; - XCTAssertEqual(mglLight.colorTransiton.delay, transition.delay); - XCTAssertEqual(mglLight.colorTransiton.duration, transition.duration); - - mbgl::style::PropertyValue colorProperty = { { 0, 0, 0, 1 } }; - light.setColor(colorProperty); + + mbgl::style::PropertyValue propertyValue = { { 1, 0, 0, 1 } }; + + light.setColor(propertyValue); light.setColorTransition(transitionOptions); - + + + mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; lightFromMGLlight = [mglLight mbglLight]; - - colorComponents = CGColorGetComponents(colorValue.CGColor); - color = lightFromMGLlight.getColor().asConstant(); - XCTAssertEqual(light.getColor().asConstant(),lightFromMGLlight.getColor().asConstant()); + + XCTAssertEqual(light.getColor(), lightFromMGLlight.getColor()); colorTransition = lightFromMGLlight.getColorTransition(); XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == transition.delay); XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == transition.duration); + } - + // intensity { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); - NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - auto intensity = light.getDefaultIntensity(); - - XCTAssert(intensityNumber.floatValue == intensity); - XCTAssertEqual(mglLight.intensityTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.intensityTransition.duration, defaultTransition.duration); - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(intensity, lightFromMGLlight.getIntensity().asConstant()); + + XCTAssertEqual(light.getDefaultIntensity(), lightFromMGLlight.getIntensity()); auto intensityTransition = lightFromMGLlight.getIntensityTransition(); XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == defaultTransition.delay); XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == defaultTransition.duration); - - NSNumber *intensityValue = @0.4; - MGLStyleValue *intensityStyleValue = [MGLStyleValue valueWithRawValue:intensityValue]; - mglLight.intensity = intensityStyleValue; - XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); - intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - XCTAssert(intensityNumber.floatValue == intensityValue.floatValue); - - mglLight.intensityTransition = transition; - XCTAssertEqual(mglLight.intensityTransition.delay, transition.delay); - XCTAssertEqual(mglLight.intensityTransition.duration, transition.duration); - - mbgl::style::PropertyValue intensityProperty = { 0.4 }; - light.setIntensity(intensityProperty); + + mbgl::style::PropertyValue propertyValue = { 0xff }; + + light.setIntensity(propertyValue); light.setIntensityTransition(transitionOptions); + + mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(light.getIntensity().asConstant(), lightFromMGLlight.getIntensity().asConstant()); + + XCTAssertEqual(light.getIntensity(), lightFromMGLlight.getIntensity()); intensityTransition = lightFromMGLlight.getIntensityTransition(); XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == transition.delay); XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == transition.duration); - + } } diff --git a/platform/darwin/test/MGLLightTest.mm.ejs b/platform/darwin/test/MGLLightTest.mm.ejs index a4219583557..c1904d5ab85 100644 --- a/platform/darwin/test/MGLLightTest.mm.ejs +++ b/platform/darwin/test/MGLLightTest.mm.ejs @@ -1,4 +1,5 @@ <% + const type = locals.type; const properties = locals.properties; -%> // This file is generated. @@ -31,268 +32,46 @@ { mbgl::style::Light light; MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getDefault<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>()); +<% if (property.transition) { -%> + auto <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition(); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay) == defaultTransition.delay); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration) == defaultTransition.duration); +<% } -%> +<% if (property.type == "enum" && property.default) { -%> XCTAssert([mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isn’t a MGLConstantStyleValue."); NSValue *<%- camelizeWithLeadingLowercase(property.name) -%>Value = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; -<% if (property.type == "enum") { -%> XCTAssertEqual(<%- camelizeWithLeadingLowercase(property.name) -%>Value.MGLLight<%- camelize(property.name) -%>Value, MGLLight<%- camelize(property.name) -%><%- camelize(property.default) -%>); -<% } else if (property.type == "array") { -%> - auto positionArray = light.getDefaultPosition().getSpherical(); - MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); - - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); -<% } else if (property.type == "color") {-%> - MGLColor *<%- camelizeWithLeadingLowercase(property.name) -%>Value = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; - auto <%- camelizeWithLeadingLowercase(property.name) -%> = light.getDefault<%- camelize(property.name) -%>(); - const CGFloat *<%- camelizeWithLeadingLowercase(property.name) -%>Components = CGColorGetComponents(<%- camelizeWithLeadingLowercase(property.name) -%>Value.CGColor); - - XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>.r == <%- camelizeWithLeadingLowercase(property.name) -%>Components[0] && <%- camelizeWithLeadingLowercase(property.name) -%>.g == <%- camelizeWithLeadingLowercase(property.name) -%>Components[1] && <%- camelizeWithLeadingLowercase(property.name) -%>.b == <%- camelizeWithLeadingLowercase(property.name) -%>Components[2] && - <%- camelizeWithLeadingLowercase(property.name) -%>.a == <%- camelizeWithLeadingLowercase(property.name) -%>Components[3]); -<% } else if (property.type == "number") { -%> - NSNumber *<%- camelizeWithLeadingLowercase(property.name) -%>Number = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; - auto <%- camelizeWithLeadingLowercase(property.name) -%> = light.getDefault<%- camelize(property.name) -%>(); - - XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Number.floatValue == <%- camelizeWithLeadingLowercase(property.name) -%>); -<% } else { -%> - XCTAssertTrue(NO, @"<%- camelizeWithLeadingLowercase(property.name) -%> has not implementation in the test generation script."); -<% } -%> -<% if (property.transition) { -%> - // Default transition test - XCTAssertEqual(mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration, defaultTransition.duration); -<% } -%> - auto lightFromMGLlight = [mglLight mbglLight]; -<% if (property.type == "enum") { -%> - XCTAssertEqual(light.getDefault<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>().asConstant()); -<% } else if (property.type == "array") { -%> - XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); +<% } -%> +<% if (property.type == "array") { -%> + const std::array positionArray = { { 6, 180, 90 } }; + mbgl::style::Position position = { positionArray }; + mbgl::style::PropertyValue propertyValue = { position }; <% } else { -%> - XCTAssertEqual(<%- camelizeWithLeadingLowercase(property.name) -%>, lightFromMGLlight.get<%- camelize(property.name) -%>().asConstant()); + mbgl::style::PropertyValue<<%- mbglType(property) %>> propertyValue = { <%- mbglTestValue(property, type) %> }; <% } -%> + light.set<%- camelize(property.name) -%>(propertyValue); <% if (property.transition) { -%> - // transition test - auto <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition(); - XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); - XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); -<% } -%> -<% if (property.type == "enum") { -%> - MGLStyleValue<<%- propertyType(property) %>> *anchorStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; - mglLight.anchor = anchorStyleValue; - XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); - anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); -<% } else if (property.type == "array") { -%> - defaultPosition = MGLSphericalPositionMake(6, 180, 90); - MGLStyleValue<<%- propertyType(property) %>> *positionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]]; - mglLight.position = positionStyleValue; - XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); - positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); -<% } else if (property.type == "color") {-%> - MGLStyleValue<<%- propertyType(property) %>> *colorStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:[MGLColor blackColor]]; - mglLight.color = colorStyleValue; - XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); - colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - XCTAssertEqual([MGLColor blackColor], colorValue); -<% } else if (property.type == "number") { -%> - NSNumber *intensityValue = @0.4; - MGLStyleValue<<%- propertyType(property) %>> *intensityStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:intensityValue]; - mglLight.intensity = intensityStyleValue; - XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); - intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - XCTAssert(intensityNumber.floatValue == intensityValue.floatValue); -<% } else { -%> - XCTAssertTrue(NO, @"<%- camelizeWithLeadingLowercase(property.name) -%> has not implementation in the test generation script."); -<% } -%> - } - -<% } -%> - // anchor - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - - XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); - NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport); - XCTAssertEqual(mglLight.anchorTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.anchorTransition.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor().asConstant()); - auto anchorTransition = lightFromMGLlight.getAnchorTransition(); - XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay); - XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration); - - MGLStyleValue *anchorStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]]; - mglLight.anchor = anchorStyleValue; - mglLight.anchorTransition = transition; - XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue."); - anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue; - - XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap); - XCTAssertEqual(mglLight.anchorTransition.delay, transition.delay); - XCTAssertEqual(mglLight.anchorTransition.duration, transition.duration); - - mbgl::style::PropertyValue anchorProperty = { mbgl::style::LightAnchorType::Map }; - light.setAnchor(anchorProperty); - light.setAnchorTransition(transitionOptions); - - lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(light.getAnchor().asConstant(), lightFromMGLlight.getAnchor().asConstant()); - anchorTransition = lightFromMGLlight.getAnchorTransition(); - XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == transition.delay); - XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == transition.duration); - - } - - // position - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); - NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - auto positionArray = light.getDefaultPosition().getSpherical(); - MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]); - - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); - XCTAssertEqual(mglLight.positionTransiton.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.positionTransiton.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); - auto positionTransition = lightFromMGLlight.getPositionTransition(); - XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == defaultTransition.delay); - XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == defaultTransition.duration); - - defaultPosition = MGLSphericalPositionMake(6, 180, 90); - MGLStyleValue *positionStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]]; - mglLight.position = positionStyleValue; - mglLight.positionTransiton = transition; - - XCTAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue."); - positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue; - - XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial); - XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal); - XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar); - XCTAssertEqual(mglLight.positionTransiton.delay, transition.delay); - XCTAssertEqual(mglLight.positionTransiton.duration, transition.duration); - - lightFromMGLlight = [mglLight mbglLight]; - - positionArray = { { 6, 180, 90 } }; - mbgl::style::Position position = { positionArray }; - mbgl::style::PropertyValue positionProperty = { position }; - light.setPosition(positionProperty); - light.setPositionTransition(transitionOptions); + light.set<%- camelize(property.name) -%>Transition(transitionOptions); - XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical()); - positionTransition = lightFromMGLlight.getPositionTransition(); - XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == transition.delay); - XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == transition.duration); - - } - - // color - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); - MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - auto color = light.getDefaultColor(); - const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor); - - XCTAssert(color.r == colorComponents[0] && color.g == colorComponents[1] && color.b == colorComponents[2] && - color.a == colorComponents[3]); - XCTAssertEqual(mglLight.colorTransiton.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.colorTransiton.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(color, lightFromMGLlight.getColor().asConstant()); - auto colorTransition = lightFromMGLlight.getColorTransition(); - XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == defaultTransition.delay); - XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == defaultTransition.duration); - - MGLStyleValue *colorStyleValue = [MGLStyleValue valueWithRawValue:[MGLColor blackColor]]; - mglLight.color = colorStyleValue; - mglLight.colorTransiton = transition; - - XCTAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue."); - colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue; - - XCTAssertEqual([MGLColor blackColor], colorValue); - XCTAssertEqual(mglLight.colorTransiton.delay, transition.delay); - XCTAssertEqual(mglLight.colorTransiton.duration, transition.duration); - - mbgl::style::PropertyValue colorProperty = { { 0, 0, 0, 1 } }; - light.setColor(colorProperty); - light.setColorTransition(transitionOptions); - +<% } -%> + mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; lightFromMGLlight = [mglLight mbglLight]; - - colorComponents = CGColorGetComponents(colorValue.CGColor); - color = lightFromMGLlight.getColor().asConstant(); - XCTAssertEqual(light.getColor().asConstant(),lightFromMGLlight.getColor().asConstant()); - colorTransition = lightFromMGLlight.getColorTransition(); - XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == transition.delay); - XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == transition.duration); - } - - // intensity - { - mbgl::style::Light light; - MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; - XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); - NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - auto intensity = light.getDefaultIntensity(); - - XCTAssert(intensityNumber.floatValue == intensity); - XCTAssertEqual(mglLight.intensityTransition.delay, defaultTransition.delay); - XCTAssertEqual(mglLight.intensityTransition.duration, defaultTransition.duration); - - auto lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(intensity, lightFromMGLlight.getIntensity().asConstant()); - auto intensityTransition = lightFromMGLlight.getIntensityTransition(); - XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == defaultTransition.delay); - XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == defaultTransition.duration); - - NSNumber *intensityValue = @0.4; - MGLStyleValue *intensityStyleValue = [MGLStyleValue valueWithRawValue:intensityValue]; - mglLight.intensity = intensityStyleValue; - mglLight.intensityTransition = transition; - - XCTAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue."); - intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue; - XCTAssert(intensityNumber.floatValue == intensityValue.floatValue); - XCTAssertEqual(mglLight.intensityTransition.delay, transition.delay); - XCTAssertEqual(mglLight.intensityTransition.duration, transition.duration); - mbgl::style::PropertyValue intensityProperty = { 0.4 }; - light.setIntensity(intensityProperty); - light.setIntensityTransition(transitionOptions); + XCTAssertEqual(light.get<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>()); +<% if (property.transition) { -%> + <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition(); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay) == transition.delay); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration) == transition.duration); - lightFromMGLlight = [mglLight mbglLight]; - - XCTAssertEqual(light.getIntensity().asConstant(), lightFromMGLlight.getIntensity().asConstant()); - intensityTransition = lightFromMGLlight.getIntensityTransition(); - XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == transition.delay); - XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == transition.duration); - +<% } -%> } +<% } -%> } - (void)testValueAdditions { @@ -301,8 +80,13 @@ XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.radial, position.radial); XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.azimuthal, position.azimuthal); XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.polar, position.polar); - XCTAssertEqual([NSValue valueWithMGLLightAnchor:MGLLightAnchorMap].MGLLightAnchorValue, MGLLightAnchorMap); - XCTAssertEqual([NSValue valueWithMGLLightAnchor:MGLLightAnchorViewport].MGLLightAnchorValue, MGLLightAnchorViewport); +<% for (const property of properties) { -%> +<% if (property.type == "enum") { -%> +<% for (const value in property.values) { -%> + XCTAssertEqual([NSValue valueWithMGLLight<%- camelize(property.name) %>:MGLLight<%- camelize(property.name) %><%- camelize(value) %>].MGLLight<%- camelize(property.name) %>Value, MGLLight<%- camelize(property.name) %><%- camelize(value) %>); +<% } -%> +<% } -%> +<% } -%> } @end