1

美好的一天大家,检测对象完全在另一个对象内

我想知道是否有一种方法来检测织物对象是否完全在另一个对象内?

我在看文档object.intersectsWithObject(object2),但不幸的是,只要对象完全在object2中,函数就不会返回true,而是返回false。

有其他人有这个问题吗?我根本不知道该怎么做。 我已经在fabric.js中搜索了函数。有人可以帮忙吗?

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'; 
} 

如果你想知道,如果一个下贱完全是另一个对象,你应该使用isContainedWithinObject内谢谢你已经为你的帮助 塞巴斯蒂安

回答

2

isContainedWithinObject(其他)→ {布尔型}

§检查

名称:■如果对象是另一个对象的区域

参数范围内完全 包含在其他
类型:Object

说明:对象来测试

来源:fabric.js, line 12300

返回:如果对象完全包含的 区中的另一个对象

类型内:布尔

这是源:

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); 
    } 

它的工作原理采用边框你要测试的对象。

+0

谢谢!我正在寻找'内部'和'内部'的每一种组合,但没有检查'内部'。谢谢,抱歉!虽然可以帮助别人。 – Sebastian