Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/minimum-rectangle'
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Feb 7, 2018
2 parents 9d03dfd + b5c2013 commit a8e8c97
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ var rectangleAnnotation = function (args) {
map.displayToGcs({x: evt.upperRight.x, y: evt.upperRight.y}, null),
map.displayToGcs({x: evt.upperRight.x, y: evt.lowerLeft.y}, null)
];
/* Don't keep rectangles that have nearly zero area in display pixels */
if (layer.displayDistance(corners[0], null, corners[1], null) *
layer.displayDistance(corners[0], null, corners[3], null) < 0.01) {
return 'remove';
}
m_this.options('corners', corners);
m_this.state(annotationState.done);
return 'done';
Expand Down Expand Up @@ -854,6 +859,11 @@ var rectangleAnnotation = function (args) {
evt.handled = true;
if (corners.length) {
m_this._setCornersFromMouse(corners, evt);
/* Don't keep rectangles that have nearly zero area in display pixels */
if (layer.displayDistance(corners[0], null, corners[1], null) *
layer.displayDistance(corners[0], null, corners[3], null) < 0.01) {
return 'remove';
}
m_this.state(annotationState.done);
return 'done';
}
Expand Down
26 changes: 26 additions & 0 deletions tests/cases/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ describe('geo.annotation', function () {
expect(coor[0].y).toBeCloseTo(10.055);
expect(coor[2].x).toBeCloseTo(-20.215);
expect(coor[2].y).toBeCloseTo(15.199);
// a zero-area rectangle should be asked to be removed.
ann = geo.annotation.rectangleAnnotation({layer: layer, corners: corners});
ann.state(geo.annotation.state.create);
evt = {
event: geo.event.actionselection,
state: {action: geo.geo_action.annotation_rectangle},
lowerLeft: {x: 10, y: 65},
upperRight: {x: 90, y: 65}
};
expect(ann.processAction(evt)).toBe('remove');
});
it('_coordinates', function () {
var ann = geo.annotation.rectangleAnnotation({corners: corners});
Expand Down Expand Up @@ -428,6 +438,22 @@ describe('geo.annotation', function () {
});
expect(ann.options('corners').length).toBe(4);
expect(ann.state()).toBe(geo.annotation.state.done);
// a zero-area rectangle should be asked to be removed.
ann = geo.annotation.rectangleAnnotation({layer: layer});
ann.state(geo.annotation.state.create);
expect(ann.mouseClick({
buttonsDown: {left: true},
time: time,
map: corners[0],
mapgcs: map.displayToGcs(corners[0], null)
})).toBe(true);
expect(ann.options('corners').length).toBe(4);
expect(ann.mouseClick({
buttonsDown: {left: true},
time: time,
map: corners[1],
mapgcs: map.displayToGcs(corners[1], null)
})).toBe('remove');
});
});

Expand Down

0 comments on commit a8e8c97

Please sign in to comment.