Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions spec/EntitySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ describe("Entity.hasConnectorAnchor", function() {
});
});

describe("Entity.hasAnyConnectorAnchor", function() {
it("returns true if 1+ anchor is assigned to Entity", function() {
const entity = new Entity(
"obj-123",
100,
200,
10,
20,
sheet,
window.document.createElement('div'),
[window.document.createElement('div')],
[window.document.createElement('div')]
);

const anchorElemA = window.document.createElement('div');
const anchorElemB = window.document.createElement('div');
const newAnchorA = entity.addInteractableConnectorAnchor(anchorElemA);

expect(entity.hasAnyConnectorAnchor([newAnchorA, anchorElemB])).toBe(true);
});
});

describe("Entity.translate", function() {
it("translates entity", function() {
const entityDomElem = window.document.createElement('div');
Expand Down
19 changes: 15 additions & 4 deletions src/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,21 @@ function Entity(_id, _x, _y, _width, _height, _sheet, _domElement, _translateHan
* @returns {Boolean}
*/
this.hasConnectorAnchor = function(_anchor) {
const anchors = self.getConnectorAnchors();
for(let i=0; i<anchors.length; i++) {
if(anchors[i] === _anchor) {
return true;
return self.hasAnyConnectorAnchor([_anchor]);
};

/**
*
* @param {ConnectorAnchor[]} _anchors
* @returns {Boolean}
*/
this.hasAnyConnectorAnchor = function(_anchors) {
const haystack = self.getConnectorAnchors();
for(let i=0; i<haystack.length; i++) {
for(let j=0; j<_anchors.length; j++) {
if(haystack[i] === _anchors[j]) {
return true;
}
}
}

Expand Down