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

[core] Transform{,State} cleanups - #6790

Merged
brunoabinader merged 5 commits into
masterfrom
transformstate-helpers
Oct 31, 2016
Merged

brunoabinader merged 5 commits into
masterfrom
transformstate-helpers

Conversation

@brunoabinader

Copy link
Copy Markdown
Contributor

Reuse TransformState::{zoomScale,scaleZoom,getZoomFraction} and util::log2 whenever possible.

@brunoabinader brunoabinader added the Core The cross-platform C++ core, aka mbgl label Oct 21, 2016
@mention-bot

Copy link
Copy Markdown

@brunoabinader, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jfirebaugh, @kkaefer and @ansis to be potential reviewers.

Comment thread src/mbgl/renderer/painter_symbol.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct in the case of overzoomed tiles?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - I'm not sure. I'll revert this particular change.

Comment thread src/mbgl/tile/geometry_tile.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same question here BTW.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess I didn't account for overscaled zoom on my tests. We can revisit it again with proper unit tests to verify later.

@brunoabinader
brunoabinader force-pushed the transformstate-helpers branch 3 times, most recently from 6f3a220 to acbb073 Compare October 24, 2016 06:33
@brunoabinader brunoabinader changed the title [core] Reuse TransformState helpers [core] Transform{,State} cleanups Oct 29, 2016
@brunoabinader
brunoabinader force-pushed the transformstate-helpers branch 2 times, most recently from cbee3dc to 689c8b1 Compare October 30, 2016 09:01
@brunoabinader

Copy link
Copy Markdown
Contributor Author

Took liberty to include a few other refactors and bug fixes related. Rebased after #6468 (/cc @jfirebaugh).

@brunoabinader
brunoabinader force-pushed the transformstate-helpers branch from 689c8b1 to ff9f2fc Compare October 30, 2016 09:18
Comment thread src/mbgl/layout/symbol_layout.cpp Outdated

const float placementZoom = ::fmax(std::log(scale) / std::log(2) + zoom, 0);
static const uint16_t vertexLength = 4;
const float placementZoom = util::max(std::log2(scale) + zoom, 0.0f);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using util::log2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - forgot to update these, thanks!

Comment thread src/mbgl/layout/symbol_layout.cpp Outdated
const float a = std::fmod(symbol.anchorAngle + placementAngle + M_PI, M_PI * 2);
if (keepUpright && placement == style::SymbolPlacementType::Line &&
(a <= M_PI / 2 || a > M_PI * 3 / 2)) {
(a <= M_PI_2 || a > M_PI_2 * 3)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this makes sense for readability. The compiler almost certainly optimizes this anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough 👍 From reading http://stackoverflow.com/posts/1610346/revisions it seems that using M_PI_2 actually decreases a bit of precision in favor of pre computation.

Comment thread src/mbgl/math/log2.cpp Outdated
#endif
}
template <> float log2(float x);
template <> double log2(double x);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these needed? The implementation is all in the header anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accounts for explicit instantiation, which from my understanding instantiates these template specializations to be reused by each compilation unit without duplications.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but they are only needed when you want to force certain instances to exist even if they're not used, or when the template definition is in an implementation file.

Comment thread src/mbgl/layout/symbol_layout.cpp Outdated
// coordinate in this polygon.
auto& segment = buffer.segments.back();
size_t index = segment.vertexLength;
uint16_t index = uint16_t(segment.vertexLength);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert here that it's <= 65535?

Comment thread src/mbgl/layout/symbol_layout.cpp Outdated

template <typename Buffer>
void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle) {
static const uint16_t vertexLength = 4;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be constexpr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - btw this accounts for the longest type declaration in our codebase: static constexpr const uint16_t 😄

@brunoabinader
brunoabinader force-pushed the transformstate-helpers branch from af691bf to f1f2840 Compare October 31, 2016 13:11
- Added util::{MIN,MAX}_ZOOM_F to avoid consecutive conversions from
double to float
- Move util::log2 to its own header (part of mbgl/math)
@brunoabinader
brunoabinader force-pushed the transformstate-helpers branch from f1f2840 to 6a756e0 Compare October 31, 2016 14:14
@brunoabinader
brunoabinader merged commit 7b3e24d into master Oct 31, 2016
@brunoabinader
brunoabinader deleted the transformstate-helpers branch October 31, 2016 14:53
@jfirebaugh

Copy link
Copy Markdown
Contributor

Can you please revert the GL_LINEAR change? Enabling GL_LINEAR during pan-only operations was the intended behavior -- it prevents icons from "wiggling" during the pan.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants