Skip to content
Snippets Groups Projects
Commit e0a5a1e9 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

computing distance between element and coordinates sometimes returned invalid (low) value

parent 656bd882
No related branches found
No related tags found
4 merge requests!678Merge 12.2.0 beta.2 into master,!67712.2.0~beta.2 into master,!676Devel 12.2.0~beta.2 into master,!672Resolve "Compartment annotation"
minerva (12.2.0~beta.2) unstable; urgency=medium
* Bug fix: clicking outside of the element sometimes resulted with the
invalid element highlighted (#324)
* Bug fix: parent compartment/pathway use proper type name in left panel
(#324)
* Bug fix: editing/removing project requires Map Management privilege (#681)
......
......@@ -1235,7 +1235,7 @@ CustomMap.prototype.getDistance = function (params) {
var elementWidth = element.getWidth();
var elementHeight = element.getHeight();
return Math.min(
Functions.distance(p1, new Point(elementX, y)),
Functions.distance(p1, new Point(elementX, elementY)),
Functions.distance(p1, new Point(elementX + elementWidth, elementY)),
Functions.distance(p1, new Point(elementX, elementY + elementHeight)),
Functions.distance(p1, new Point(elementX + elementWidth, elementY + elementHeight))
......
......@@ -1017,4 +1017,84 @@ describe('CustomMap', function () {
return map.getControl(ControlType.LOGO_IMG).onclick()
});
});
describe("getDistance", function () {
it("inside element", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setX(50);
alias.setY(60);
alias.setWidth(100);
alias.setHeight(200);
var ie = new IdentifiedElement(alias);
return map.getDistance({modelId:map.getId(), coordinates: new Point(100,200), element: ie}).then(function(distance){
assert.equal(0, distance);
return map.destroy();
});
});
it("to the left", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setX(50);
alias.setY(60);
alias.setWidth(100);
alias.setHeight(200);
var ie = new IdentifiedElement(alias);
return map.getDistance({modelId:map.getId(), coordinates: new Point(1,200), element: ie}).then(function(distance){
assert.equal(49, distance);
return map.destroy();
});
});
it("to the right", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setX(50);
alias.setY(60);
alias.setWidth(100);
alias.setHeight(200);
var ie = new IdentifiedElement(alias);
return map.getDistance({modelId:map.getId(), coordinates: new Point(161,200), element: ie}).then(function(distance){
assert.equal(11, distance);
return map.destroy();
});
});
it("to the top", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setX(50);
alias.setY(60);
alias.setWidth(100);
alias.setHeight(200);
var ie = new IdentifiedElement(alias);
return map.getDistance({modelId:map.getId(), coordinates: new Point(100,11), element: ie}).then(function(distance){
assert.equal(49, distance);
return map.destroy();
});
});
it("to the bottom", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setX(50);
alias.setY(60);
alias.setWidth(100);
alias.setHeight(200);
var ie = new IdentifiedElement(alias);
return map.getDistance({modelId:map.getId(), coordinates: new Point(100,300), element: ie}).then(function(distance){
assert.equal(40, distance);
return map.destroy();
});
});
it("corner", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setX(50);
alias.setY(60);
alias.setWidth(100);
alias.setHeight(200);
var ie = new IdentifiedElement(alias);
return map.getDistance({modelId:map.getId(), coordinates: new Point(46,57), element: ie}).then(function(distance){
assert.equal(5, distance);
return map.destroy();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment