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

相關問題