Skip to content

Commit

Permalink
round points created during bucket creation
Browse files Browse the repository at this point in the history
fix #2067
  • Loading branch information
ansis committed Feb 12, 2016
1 parent 6122e19 commit 4a713d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions js/data/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ LineBucket.prototype.addLine = function(vertices, join, cap, miterLimit, roundLi
if (isSharpCorner && i > 0) {
var prevSegmentLength = currentVertex.dist(prevVertex);
if (prevSegmentLength > 2 * sharpCornerOffset) {
var newPrevVertex = currentVertex.sub(currentVertex.sub(prevVertex)._mult(sharpCornerOffset / prevSegmentLength));
var newPrevVertex = currentVertex.sub(currentVertex.sub(prevVertex)._mult(sharpCornerOffset / prevSegmentLength)._round());
distance += newPrevVertex.dist(prevVertex);
this.addCurrentVertex(newPrevVertex, flip, distance, prevNormal.mult(1), 0, 0, false);
prevVertex = newPrevVertex;
Expand Down Expand Up @@ -329,7 +329,7 @@ LineBucket.prototype.addLine = function(vertices, join, cap, miterLimit, roundLi
if (isSharpCorner && i < len - 1) {
var nextSegmentLength = currentVertex.dist(nextVertex);
if (nextSegmentLength > 2 * sharpCornerOffset) {
var newCurrentVertex = currentVertex.add(nextVertex.sub(currentVertex)._mult(sharpCornerOffset / nextSegmentLength));
var newCurrentVertex = currentVertex.add(nextVertex.sub(currentVertex)._mult(sharpCornerOffset / nextSegmentLength)._round());
distance += newCurrentVertex.dist(currentVertex);
this.addCurrentVertex(newCurrentVertex, flip, distance, nextNormal.mult(1), 0, 0, false);
currentVertex = newCurrentVertex;
Expand Down
16 changes: 8 additions & 8 deletions js/symbol/clip_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ function clipLine(lines, x1, y1, x2, y2) {
if (p0.x < x1 && p1.x < x1) {
continue;
} else if (p0.x < x1) {
p0 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)));
p0 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
} else if (p1.x < x1) {
p1 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)));
p1 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
}

if (p0.y < y1 && p1.y < y1) {
continue;
} else if (p0.y < y1) {
p0 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1);
p0 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
} else if (p1.y < y1) {
p1 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1);
p1 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
}

if (p0.x >= x2 && p1.x >= x2) {
continue;
} else if (p0.x >= x2) {
p0 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)));
p0 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
} else if (p1.x >= x2) {
p1 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)));
p1 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
}

if (p0.y >= y2 && p1.y >= y2) {
continue;
} else if (p0.y >= y2) {
p0 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2);
p0 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
} else if (p1.y >= y2) {
p1 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2);
p1 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
}

if (!clippedLine || !p0.equals(clippedLine[clippedLine.length - 1])) {
Expand Down
4 changes: 1 addition & 3 deletions js/symbol/get_anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ function resample(line, offset, spacing, angleWindowSize, maxAngle, labelLength,
if (x >= 0 && x < tileExtent && y >= 0 && y < tileExtent &&
markedDistance - halfLabelLength >= 0 &&
markedDistance + halfLabelLength <= lineLength) {
x = Math.round(x);
y = Math.round(y);
var anchor = new Anchor(x, y, angle, i);
var anchor = new Anchor(x, y, angle, i)._round();

if (!angleWindowSize || checkMaxAngle(line, anchor, labelLength, angleWindowSize, maxAngle)) {
anchors.push(anchor);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"eslint": "^1.5.0",
"eslint-config-mourner": "^1.0.0",
"istanbul": "^0.4.1",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#c896d35640872d61cbae2dc681a27d405e610b4e",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#8859b504ef241bca49d4c2f9a79ff4d0bfdf81a1",
"prova": "^2.1.2",
"sinon": "^1.15.4",
"st": "^1.0.0",
Expand Down

0 comments on commit 4a713d4

Please sign in to comment.