Merge pull request #3587 from tschaub/intersects
Handle left/right segment intersections for top/bottom spans.
This commit is contained in:
+6
-3
@@ -814,17 +814,20 @@ ol.extent.intersectsSegment = function(extent, start, end) {
|
|||||||
// potentially intersects top
|
// potentially intersects top
|
||||||
x = endX - ((endY - maxY) / slope);
|
x = endX - ((endY - maxY) / slope);
|
||||||
intersects = x >= minX && x <= maxX;
|
intersects = x >= minX && x <= maxX;
|
||||||
} else if (!!(endRel & ol.extent.Relationship.RIGHT) &&
|
}
|
||||||
|
if (!intersects && !!(endRel & ol.extent.Relationship.RIGHT) &&
|
||||||
!(startRel & ol.extent.Relationship.RIGHT)) {
|
!(startRel & ol.extent.Relationship.RIGHT)) {
|
||||||
// potentially intersects right
|
// potentially intersects right
|
||||||
y = endY - ((endX - maxX) * slope);
|
y = endY - ((endX - maxX) * slope);
|
||||||
intersects = y >= minY && y <= maxY;
|
intersects = y >= minY && y <= maxY;
|
||||||
} else if (!!(endRel & ol.extent.Relationship.BELOW) &&
|
}
|
||||||
|
if (!intersects && !!(endRel & ol.extent.Relationship.BELOW) &&
|
||||||
!(startRel & ol.extent.Relationship.BELOW)) {
|
!(startRel & ol.extent.Relationship.BELOW)) {
|
||||||
// potentially intersects bottom
|
// potentially intersects bottom
|
||||||
x = endX - ((endY - minY) / slope);
|
x = endX - ((endY - minY) / slope);
|
||||||
intersects = x >= minX && x <= maxX;
|
intersects = x >= minX && x <= maxX;
|
||||||
} else if (!!(endRel & ol.extent.Relationship.LEFT) &&
|
}
|
||||||
|
if (!intersects && !!(endRel & ol.extent.Relationship.LEFT) &&
|
||||||
!(startRel & ol.extent.Relationship.LEFT)) {
|
!(startRel & ol.extent.Relationship.LEFT)) {
|
||||||
// potentially intersects left
|
// potentially intersects left
|
||||||
y = endY - ((endX - minX) * slope);
|
y = endY - ((endX - minX) * slope);
|
||||||
|
|||||||
@@ -472,6 +472,22 @@ describe('ol.extent', function() {
|
|||||||
expect(intersects).to.be(false);
|
expect(intersects).to.be(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('works for left/right intersection spanning top to bottom', function() {
|
||||||
|
var extent = [2, 1, 3, 4];
|
||||||
|
var start = [0, 0];
|
||||||
|
var end = [5, 5];
|
||||||
|
expect(ol.extent.intersectsSegment(extent, start, end)).to.be(true);
|
||||||
|
expect(ol.extent.intersectsSegment(extent, end, start)).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works for top/bottom intersection spanning left to right', function() {
|
||||||
|
var extent = [1, 2, 4, 3];
|
||||||
|
var start = [0, 0];
|
||||||
|
var end = [5, 5];
|
||||||
|
expect(ol.extent.intersectsSegment(extent, start, end)).to.be(true);
|
||||||
|
expect(ol.extent.intersectsSegment(extent, end, start)).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#applyTransform()', function() {
|
describe('#applyTransform()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user