Consider also distance from centroid when calculating label position
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java, javascript
- Domain
- computer-graphics
Research direction
Read the current cell-quality comparison, initial-best-cell logic, and the while-loop calculation described in the issue. Evaluate the proposed centroid-aware cost on rectangles and polygons with parallel edges; done means the algorithm consistently prefers the more central equally good solution without reducing polygon-distance quality.
Written by the indexing model from the issue text.
Description
In cases where there are several equally good solutions, algorithm's output is not always the most elegant one. The simplest case is a rectangle: the set of solutions lies on a line and algorithm returns a point that coincides with one of the line's endpoints. Current implementation covers such case when calculating initial best cell, however these lines can occur also in more complex polygons containing parallel edges.
I propose using a cost function when estimating cell quality, which would consider both distance from polygon and distance from centroid in such a way it would prefer points closer to centroid, e.g.:
0.5 * (distFromPoly + distFromPoly / (distFromCtr/distFromPoly+1); distFromPoly >= 0
distFromPoly; distFromPoly < 0
So for example, if pia point is very far away from centroid and its distance from polygon is not much greater than centroid's distance, we would get centroid as optimal point. Weights on both values can be manipulated by cost function. What are optimal set of weights is of course subjective.
Cost function would be then used when comparing two cells in while loop and max attribute of a cell can be then calculated in a following way (java code):
// for distance from polygon take max possible distance
// for distance from mass centre take minimal possible distance
double maxDist = dist + h*SQRT2;
if (maxDist < 0) {
return maxDist;
}
double distFromCtr = Math.max(distance(this, massCentreCell) - h*SQRT2, 0);
return costFunction.compute(distFromCtr, maxDist);
I've implemented this in Java and I'm very satisfied with the results.
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 163
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mapbox/polylabel
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
question
Difficulty 3/5 1-2 days Newbie friendliness 20/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
-
enhancement question
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in mapbox/polylabel
Similar issues
-
bug CI breakage triage needed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
oppia/oppia#27517 · 1 comment ·
Maintainers usually reply within 1 day
-
draftomen enhancement size: S
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
andreagrandi/draftomen#761 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
HarperFast/harper#2866 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
HarperFast/harper-pro#927 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
anthropics/skills#1897 · 1 comment ·
Maintainers usually reply within 1 day