javascript - Detect object completely inside another object -
good day everyone,
i wondering if there way detect if fabric object inside object?
i looking @ object.intersectswithobject(object2)
in documentation unfortunately, object inside object2, function doesn't give true anymore false.
has else had problem? not know @ how this. have searched function in fabric.js. can help?
intersectswithobject: function(other) { // extracts coords function getcoords(ocoords) { return { tl: new fabric.point(ocoords.tl.x, ocoords.tl.y), tr: new fabric.point(ocoords.tr.x, ocoords.tr.y), bl: new fabric.point(ocoords.bl.x, ocoords.bl.y), br: new fabric.point(ocoords.br.x, ocoords.br.y) }; } var thiscoords = getcoords(this.ocoords), othercoords = getcoords(other.ocoords), intersection = fabric.intersection.intersectpolygonpolygon( [thiscoords.tl, thiscoords.tr, thiscoords.br, thiscoords.bl], [othercoords.tl, othercoords.tr, othercoords.br, othercoords.bl] ); return intersection.status === 'intersection'; }
thank sebastian
if want know if abject inside object should use iscontainedwithinobject:
iscontainedwithinobject(other) → {boolean}
§ checks if object contained within area of object
parameters:
name : other
type: objectdescription: object test
source: fabric.js, line 12300
returns: true if object contained within area of object
type: boolean
this source:
iscontainedwithinobject: function(other) { var boundingrect = other.getboundingrect(), point1 = new fabric.point(boundingrect.left, boundingrect.top), point2 = new fabric.point(boundingrect.left + boundingrect.width, boundingrect.top + boundingrect.height); return this.iscontainedwithinrect(point1, point2); }
it works using bounding box of object test.
Comments
Post a Comment