inPolygon turf 이용으로 수정
This commit is contained in:
parent
6fe18deb3f
commit
3c3bdca6b6
@ -2,7 +2,7 @@ import { fabric } from 'fabric'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { QLine } from '@/components/fabric/QLine'
|
||||
import { distanceBetweenPoints, findTopTwoIndexesByDistance, getDirectionByPoint, sortedPointLessEightPoint, sortedPoints } from '@/util/canvas-util'
|
||||
import { calculateAngle, drawHippedRoof, splitPolygonWithLines, toGeoJSON } from '@/util/qpolygon-utils'
|
||||
import { calculateAngle, drawHippedRoof, inPolygon, lineIntersect, splitPolygonWithLines, toGeoJSON } from '@/util/qpolygon-utils'
|
||||
import * as turf from '@turf/turf'
|
||||
|
||||
export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
||||
@ -244,9 +244,7 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
||||
{ x: rectLeft + rectWidth, y: rectTop },
|
||||
]
|
||||
|
||||
const allPointsInside = this.inPolygon2(rectPoints)
|
||||
|
||||
if (allPointsInside) {
|
||||
if (inPolygon(this.points, rectPoints)) {
|
||||
const rect = new fabric.Rect({
|
||||
left: rectLeft,
|
||||
top: rectTop,
|
||||
|
||||
@ -2670,3 +2670,25 @@ export const toGeoJSON = (pointsArray) => {
|
||||
|
||||
return coordinates
|
||||
}
|
||||
|
||||
export const inPolygon = (polygonPoints, rectPoints) => {
|
||||
const polygonCoordinates = toGeoJSON(polygonPoints)
|
||||
const rectCoordinates = toGeoJSON(rectPoints)
|
||||
|
||||
const polygonFeature = turf.polygon([polygonCoordinates])
|
||||
const rectFeature = turf.polygon([rectCoordinates])
|
||||
|
||||
// 사각형의 모든 꼭짓점이 다각형 내부에 있는지 확인
|
||||
const allPointsInsidePolygon = rectCoordinates.every((coord) => {
|
||||
const point = turf.point(coord)
|
||||
return turf.booleanPointInPolygon(point, polygonFeature)
|
||||
})
|
||||
|
||||
// 다각형의 모든 점이 사각형 내부에 있지 않은지 확인
|
||||
const noPolygonPointsInsideRect = polygonCoordinates.every((coord) => {
|
||||
const point = turf.point(coord)
|
||||
return !turf.booleanPointInPolygon(point, rectFeature)
|
||||
})
|
||||
|
||||
return allPointsInsidePolygon && noPolygonPointsInsideRect
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user