|
@@ -1,5 +1,14 @@
|
|
|
+import Point from '../core/fixedpoint'
|
|
|
|
|
|
-export default function calcRoom(data) {
|
|
|
+//颜色对象
|
|
|
+function Color(){
|
|
|
+ let r = Math.floor(Math.random()*255);
|
|
|
+ let g = Math.floor(Math.random()*255);
|
|
|
+ let b = Math.floor(Math.random()*255);
|
|
|
+ return 'rgba('+ r +','+ g +','+ b +',0.8)';
|
|
|
+}
|
|
|
+
|
|
|
+export default function calcRoom(data, cad) {
|
|
|
let _roomsEdges = [];
|
|
|
let _roomsEdgesPoints = [];
|
|
|
let _roomsWalls = [];
|
|
@@ -196,6 +205,8 @@ export default function calcRoom(data) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
function isPointInPoly(point, points) {
|
|
|
var x = point.x, y = point.y;
|
|
|
var inside = false;
|
|
@@ -231,11 +242,54 @@ export default function calcRoom(data) {
|
|
|
removeBigPolygon()
|
|
|
getIncludeFromRoom()
|
|
|
|
|
|
+ //计算多边形中心
|
|
|
+ //后续要修改,应该是重心才合理
|
|
|
+ function getPolygonAreaCenter(points){
|
|
|
+ var sum_x = 0;
|
|
|
+ var sum_y = 0;
|
|
|
+ var sum_area = 0;
|
|
|
+ var p1 = points[1];
|
|
|
+ for (var i = 2; i < points.length; i++) {
|
|
|
+ var p2 = points[i];
|
|
|
+ var area = Area(points[0], p1, p2);
|
|
|
+ sum_area += area;
|
|
|
+ sum_x += (points[0].x + p1.x + p2.x) * area;
|
|
|
+ sum_y += (points[0].y + p1.y + p2.y) * area;
|
|
|
+ p1 = p2;
|
|
|
+ }
|
|
|
+ var xx = sum_x / sum_area / 3;
|
|
|
+ var yy = sum_y / sum_area / 3;
|
|
|
+ return {x:xx, y:yy};
|
|
|
+ }
|
|
|
+
|
|
|
+ function Area(p0,p1,p2) {
|
|
|
+ var area = 0.0 ;
|
|
|
+ area = p0.x * p1.y + p1.x * p2.y + p2.x * p0.y - p1.x * p0.y - p2.x * p1.y - p0.x * p2.y;
|
|
|
+ return area / 2 ;
|
|
|
+ }
|
|
|
+
|
|
|
data.room = _roomsWalls.map((wall, i) => {
|
|
|
return {
|
|
|
wall: wall.map(({id}) => id),
|
|
|
ground: _roomsPoints[i].map(({id}) => id),
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ if (test_debugger) {
|
|
|
+ data.room.forEach(({ground}) => {
|
|
|
+ console.log(ground.map(point => cad.processing.points.find(({id}) => id === point).ele.real))
|
|
|
+ })
|
|
|
+
|
|
|
+ window.testCenterPoints && cad.processing.render.remove(...window.testCenterPoints)
|
|
|
+ window.testCenterPoints = _roomsPoints.map(points => {
|
|
|
+ let point = getPolygonAreaCenter(points)
|
|
|
+ let color = Color();
|
|
|
+ let epoint = new Point({ fillColor: color, storkeColor: color, x: point.x, y: -point.y, renderer: cad.processing.render })
|
|
|
+ cad.processing.render.push(epoint)
|
|
|
+ return epoint
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return data
|
|
|
}
|