fix(modeling): handle float bendpoints in label behavior

* silently round all values when doing circle-line intersection

closes #602
This commit is contained in:
Philipp Fromme 2016-08-10 12:01:24 +02:00 committed by Nico Rehwaldt
parent 226a0d76ed
commit 91cfcd9bac
2 changed files with 60 additions and 0 deletions

View File

@ -136,8 +136,11 @@ module.exports.getAttachment = getAttachment;
*/
function getCircleSegmentIntersections(s1, s2, cc, cr) {
// silently round values
s1 = roundPoint(s1);
s2 = roundPoint(s2);
cc = roundPoint(cc);
cr = min(getDistance(s1, cc), getDistance(s2, cc));
var baX = s2.x - s1.x;
var baY = s2.y - s1.y;

View File

@ -2,6 +2,7 @@
var getAttachment = require('lib/features/modeling/behavior/util/LineAttachmentUtil').getAttachment;
var EPSILON = 0.1;
describe('modeling/behavior/util - LineAttachmentUtil#getAttachment', function() {
@ -186,4 +187,60 @@ describe('modeling/behavior/util - LineAttachmentUtil#getAttachment', function()
});
describe('should handle float values', function() {
// test line
//
// *--*
// |
// *
// \
// *
//
var otherLine = [
{ x: 10.141592, y: 10.653589 },
// -
{ x: 30.793238, y: 10.462643 },
// |
{ x: 30.383279, y: 30.502884 },
// \
{ x: 130.197169, y: 130.399375 }
];
it('float value segment', function() {
// when
var attachment = getAttachment({ x: 20.197169, y: 5.399375 }, otherLine);
// then
expect(attachment.type).to.equal('segment');
expect(attachment.segmentIndex).to.equal(0);
// expect values to be roughly equal
expect(attachment.relativeLocation).to.be.within(0.5 - EPSILON, 0.5 + EPSILON);
expect(attachment.position.x).to.be.within(20.25 - EPSILON, 20.25 + EPSILON);
expect(attachment.position.y).to.be.within(10.5 - EPSILON, 10.5 + EPSILON);
});
it('float value bendboint', function() {
// when
var attachment = getAttachment({ x: 35.197169, y: 5.399375 }, otherLine);
// then
// expext values to be rounded to 3 decimal places
expect(attachment).to.eql({
type: 'bendpoint',
position: { x: 30.793, y: 10.463 },
bendpointIndex: 1,
segmentIndex: 0
});
});
});
});