Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/mbgl/annotation/annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LineAnnotation {
public:
ShapeAnnotationGeometry geometry;
style::DataDrivenPropertyValue<float> opacity { 1.0f };
style::PropertyValue<float> width { 1.0f };
style::DataDrivenPropertyValue<float> width { 1.0f };
style::DataDrivenPropertyValue<Color> color { Color::black() };
};

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ auto makePaintPropertySetters() {
result["line-translate-transition"] = &setTransition<V, LineLayer, &LineLayer::setLineTranslateTransition>;
result["line-translate-anchor"] = &setProperty<V, LineLayer, PropertyValue<TranslateAnchorType>, &LineLayer::setLineTranslateAnchor>;
result["line-translate-anchor-transition"] = &setTransition<V, LineLayer, &LineLayer::setLineTranslateAnchorTransition>;
result["line-width"] = &setProperty<V, LineLayer, PropertyValue<float>, &LineLayer::setLineWidth>;
result["line-width"] = &setProperty<V, LineLayer, DataDrivenPropertyValue<float>, &LineLayer::setLineWidth>;
result["line-width-transition"] = &setTransition<V, LineLayer, &LineLayer::setLineWidthTransition>;
result["line-gap-width"] = &setProperty<V, LineLayer, DataDrivenPropertyValue<float>, &LineLayer::setLineGapWidth>;
result["line-gap-width-transition"] = &setTransition<V, LineLayer, &LineLayer::setLineGapWidthTransition>;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/data_driven_property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DataDrivenPropertyValue {
bool isZoomConstant() const {
return !value.template is<CameraFunction<T>>() && !value.template is<CompositeFunction<T>>();
}

template <class... Ts>
auto match(Ts&&... ts) const {
return value.match(std::forward<Ts>(ts)...);
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/function/camera_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CameraFunction {
}

Stops stops;
bool useIntegerZoom = false;
};

} // namespace style
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/function/composite_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class CompositeFunction {
std::string property;
Stops stops;
optional<T> defaultValue;
bool useIntegerZoom = false;

private:
T evaluateFinal(const CoveringRanges& ranges, const Value& value, T finalDefaultValue) const {
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/function/source_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SourceFunction {
std::string property;
Stops stops;
optional<T> defaultValue;
bool useIntegerZoom = false;
};

} // namespace style
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/layers/line_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class LineLayer : public Layer {
void setLineTranslateAnchorTransition(const TransitionOptions&);
TransitionOptions getLineTranslateAnchorTransition() const;

static PropertyValue<float> getDefaultLineWidth();
PropertyValue<float> getLineWidth() const;
void setLineWidth(PropertyValue<float>);
static DataDrivenPropertyValue<float> getDefaultLineWidth();
DataDrivenPropertyValue<float> getLineWidth() const;
void setLineWidth(DataDrivenPropertyValue<float>);
void setLineWidthTransition(const TransitionOptions&);
TransitionOptions getLineWidthTransition() const;

Expand Down
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 27 files
+1 −1 docs/_posts/examples/3400-01-31-mapbox-gl-rtl-text.html
+1 −1 package.json
+2 −0 src/data/bucket/line_bucket.js
+8 −3 src/data/program_configuration.js
+1 −1 src/index.js
+0 −1 src/render/draw_line.js
+4 −3 src/shaders/line.vertex.glsl
+4 −3 src/shaders/line_pattern.vertex.glsl
+5 −1 src/shaders/line_sdf.fragment.glsl
+8 −5 src/shaders/line_sdf.vertex.glsl
+1 −0 src/style-spec/reference/v8.json
+0 −17 src/style/style_layer/line_style_layer.js
+ − test/integration/render-tests/line-dasharray/default/expected.png
+ − test/integration/render-tests/line-dasharray/fractional-zoom/expected.png
+ − test/integration/render-tests/line-dasharray/function--line-width-composite-function/expected.png
+152 −0 test/integration/render-tests/line-dasharray/function--line-width-composite-function/style.json
+ − test/integration/render-tests/line-dasharray/function--line-width-property-function/expected.png
+108 −0 test/integration/render-tests/line-dasharray/function--line-width-property-function/style.json
+ − test/integration/render-tests/line-dasharray/literal--line-width-composite-function/expected.png
+138 −0 test/integration/render-tests/line-dasharray/literal--line-width-composite-function/style.json
+ − test/integration/render-tests/line-dasharray/literal--line-width-property-function/expected.png
+94 −0 test/integration/render-tests/line-dasharray/literal--line-width-property-function/style.json
+ − test/integration/render-tests/line-dasharray/literal--line-width-zoom-function/expected.png
+0 −0 test/integration/render-tests/line-dasharray/literal--line-width-zoom-function/style.json
+1 −5 test/integration/render-tests/line-width/property-function/style.json
+2 −2 test/unit/style-spec/fixture/functions.input.json
+1 −1 test/unit/style-spec/fixture/functions.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ public static PropertyValue<Float> lineWidth(Float value) {
/**
* Stroke thickness.
*
* @param <Z> the zoom parameter type
* @param function a wrapper {@link CameraFunction} for Float
* @param <T> the function input type
* @param function a wrapper function for Float
* @return property wrapper around a Float function
*/
public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> lineWidth(CameraFunction<Z, Float> function) {
public static <T> PropertyValue<Function<T, Float>> lineWidth(Function<T, Float> function) {
return new PaintPropertyValue<>("line-width", function);
}

Expand Down Expand Up @@ -1676,7 +1676,7 @@ public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconRo
}

/**
* Scale factor for icon. 1 is original size, 3 triples the size.
* Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by {@link PropertyFactory#iconSize}. 1 is the original size; 3 triples the size of the image.
*
* @param value a Float value
* @return property wrapper around Float
Expand All @@ -1688,7 +1688,7 @@ public static PropertyValue<Float> iconSize(Float value) {


/**
* Scale factor for icon. 1 is original size, 3 triples the size.
* Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by {@link PropertyFactory#iconSize}. 1 is the original size; 3 triples the size of the image.
*
* @param <T> the function input type
* @param function a wrapper function for Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,118 @@ public void testLineWidthAsCameraFunction() {
assertEquals(1, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size());
}

@Test
public void testLineWidthAsIdentitySourceFunction() {
validateTestSetup();
setupLayer();
Timber.i("line-width");
assertNotNull(layer);

// Set
layer.setProperties(
lineWidth(property("FeaturePropertyA", Stops.<Float>identity()))
);

// Verify
assertNotNull(layer.getLineWidth());
assertNotNull(layer.getLineWidth().getFunction());
assertEquals(SourceFunction.class, layer.getLineWidth().getFunction().getClass());
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineWidth().getFunction()).getProperty());
assertEquals(IdentityStops.class, layer.getLineWidth().getFunction().getStops().getClass());
}

@Test
public void testLineWidthAsExponentialSourceFunction() {
validateTestSetup();
setupLayer();
Timber.i("line-width");
assertNotNull(layer);

// Set
layer.setProperties(
lineWidth(
property(
"FeaturePropertyA",
exponential(
stop(0.3f, lineWidth(0.3f))
).withBase(0.5f)
)
)
);

// Verify
assertNotNull(layer.getLineWidth());
assertNotNull(layer.getLineWidth().getFunction());
assertEquals(SourceFunction.class, layer.getLineWidth().getFunction().getClass());
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineWidth().getFunction()).getProperty());
assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass());
}

@Test
public void testLineWidthAsCategoricalSourceFunction() {
validateTestSetup();
setupLayer();
Timber.i("line-width");
assertNotNull(layer);

// Set
layer.setProperties(
lineWidth(
property(
"FeaturePropertyA",
categorical(
stop(1.0f, lineWidth(0.3f))
)
).withDefaultValue(lineWidth(0.3f))
)
);

// Verify
assertNotNull(layer.getLineWidth());
assertNotNull(layer.getLineWidth().getFunction());
assertEquals(SourceFunction.class, layer.getLineWidth().getFunction().getClass());
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineWidth().getFunction()).getProperty());
assertEquals(CategoricalStops.class, layer.getLineWidth().getFunction().getStops().getClass());
assertNotNull(((SourceFunction) layer.getLineWidth().getFunction()).getDefaultValue());
assertNotNull(((SourceFunction) layer.getLineWidth().getFunction()).getDefaultValue().getValue());
assertEquals(0.3f, ((SourceFunction) layer.getLineWidth().getFunction()).getDefaultValue().getValue());
}

@Test
public void testLineWidthAsCompositeFunction() {
validateTestSetup();
setupLayer();
Timber.i("line-width");
assertNotNull(layer);

// Set
layer.setProperties(
lineWidth(
composite(
"FeaturePropertyA",
exponential(
stop(0, 0.3f, lineWidth(0.9f))
).withBase(0.5f)
).withDefaultValue(lineWidth(0.3f))
)
);

// Verify
assertNotNull(layer.getLineWidth());
assertNotNull(layer.getLineWidth().getFunction());
assertEquals(CompositeFunction.class, layer.getLineWidth().getFunction().getClass());
assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineWidth().getFunction()).getProperty());
assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass());
assertEquals(1, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size());

ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops =
(ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getLineWidth().getFunction().getStops();
Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next();
assertEquals(0f, stop.in.zoom, 0.001);
assertEquals(0.3f, stop.in.value, 0.001f);
assertEquals(0.9f, stop.out, 0.001f);
}

@Test
public void testLineGapWidthTransition() {
validateTestSetup();
Expand Down
9 changes: 9 additions & 0 deletions platform/darwin/src/MGLLineStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ MGL_EXPORT
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
* `MGLSourceStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
* `MGLInterpolationModeCategorical`
* `MGLInterpolationModeIdentity`
* `MGLCompositeStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
* `MGLInterpolationModeCategorical`
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineWidth;

Expand Down
6 changes: 3 additions & 3 deletions platform/darwin/src/MGLLineStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ - (void)setLineTranslateAnchor:(MGLStyleValue<NSValue *> *)lineTranslateAnchor {
- (void)setLineWidth:(MGLStyleValue<NSNumber *> *)lineWidth {
MGLAssertStyleLayerIsValid();

auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(lineWidth);
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(lineWidth);
self.rawLayer->setLineWidth(mbglValue);
}

Expand All @@ -489,9 +489,9 @@ - (void)setLineWidth:(MGLStyleValue<NSNumber *> *)lineWidth {

auto propertyValue = self.rawLayer->getLineWidth();
if (propertyValue.isUndefined()) {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultLineWidth());
return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineWidth());
}
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue);
}

- (void)setLineWidthTransition:(MGLTransition )transition {
Expand Down
6 changes: 5 additions & 1 deletion platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,11 @@ MGL_EXPORT
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconRotationAlignment;

/**
Scale factor for icon. 1 is original size, 3 triples the size.
Scales the original size of the icon by the provided factor. The new point size
of the image will be the original point size multiplied by `iconSize`. 1 is the
original size; 3 triples the size of the image.

This property is measured in factor of the original icon sizes.

The default value of this property is an `MGLStyleValue` object containing an
`NSNumber` object containing the float `1`. Set this property to `nil` to reset
Expand Down
30 changes: 24 additions & 6 deletions platform/darwin/test/MGLLineStyleLayerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ - (void)testProperties {

MGLStyleValue<NSNumber *> *constantStyleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff];
layer.lineWidth = constantStyleValue;
mbgl::style::PropertyValue<float> propertyValue = { 0xff };
mbgl::style::DataDrivenPropertyValue<float> propertyValue = { 0xff };
XCTAssertEqual(rawLayer->getLineWidth(), propertyValue,
@"Setting lineWidth to a constant value should update line-width.");
XCTAssertEqualObjects(layer.lineWidth, constantStyleValue,
Expand All @@ -730,18 +730,36 @@ - (void)testProperties {
XCTAssertEqualObjects(layer.lineWidth, functionStyleValue,
@"lineWidth should round-trip camera functions.");

functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil];
layer.lineWidth = functionStyleValue;

mbgl::style::ExponentialStops<float> exponentialStops = { {{18, 0xff}}, 1.0 };
propertyValue = mbgl::style::SourceFunction<float> { "keyName", exponentialStops };

XCTAssertEqual(rawLayer->getLineWidth(), propertyValue,
@"Setting lineWidth to a source function should update line-width.");
XCTAssertEqualObjects(layer.lineWidth, functionStyleValue,
@"lineWidth should round-trip source functions.");

functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.lineWidth = functionStyleValue;

std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };

propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };

XCTAssertEqual(rawLayer->getLineWidth(), propertyValue,
@"Setting lineWidth to a composite function should update line-width.");
XCTAssertEqualObjects(layer.lineWidth, functionStyleValue,
@"lineWidth should round-trip composite functions.");


layer.lineWidth = nil;
XCTAssertTrue(rawLayer->getLineWidth().isUndefined(),
@"Unsetting lineWidth should return line-width to the default value.");
XCTAssertEqualObjects(layer.lineWidth, defaultStyleValue,
@"lineWidth should return the default value after being unset.");

functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil];
XCTAssertThrowsSpecificNamed(layer.lineWidth = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it");
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil];
XCTAssertThrowsSpecificNamed(layer.lineWidth = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it");
// Transition property test
layer.lineWidthTransition = transitionTest;
auto toptions = rawLayer->getLineWidthTransition();
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/programs/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ struct a_width {
using Type = gl::Attribute<float, 1>;
};

struct a_floorwidth {
static auto name() { return "a_floorwidth"; }
using Type = gl::Attribute<float, 1>;
};

struct a_height {
static auto name() { return "a_height"; }
using Type = gl::Attribute<float, 1>;
Expand Down
14 changes: 6 additions & 8 deletions src/mbgl/programs/line_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace style;
static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size");

template <class Values, class...Args>
Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties,
Values makeValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
Expand All @@ -25,15 +25,14 @@ Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties,
properties.get<LineTranslateAnchor>(),
state)
},
uniforms::u_width::Value{ properties.get<LineWidth>() },
uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
uniforms::u_gl_units_to_pixels::Value{{{ 1.0f / pixelsToGLUnits[0], 1.0f / pixelsToGLUnits[1] }}},
std::forward<Args>(args)...
};
}

LineProgram::UniformValues
LineProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties,
LineProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits) {
Expand All @@ -46,17 +45,16 @@ LineProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& propert
}

LineSDFProgram::UniformValues
LineSDFProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties,
LineSDFProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
float pixelRatio,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const LinePatternPos& posA,
const LinePatternPos& posB,
float dashLineWidth,
float atlasWidth) {
const float widthA = posA.width * properties.get<LineDasharray>().fromScale * dashLineWidth;
const float widthB = posB.width * properties.get<LineDasharray>().toScale * dashLineWidth;
const float widthA = posA.width * properties.get<LineDasharray>().fromScale;
const float widthB = posB.width * properties.get<LineDasharray>().toScale;

std::array<float, 2> scaleA {{
1.0f / tile.id.pixelsToTileUnits(widthA, state.getIntegerZoom()),
Expand Down Expand Up @@ -84,7 +82,7 @@ LineSDFProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& prop
}

LinePatternProgram::UniformValues
LinePatternProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties,
LinePatternProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
Expand Down
Loading