function CalculateElement(layer) { this.layer = layer this.calculateLine = this.layer.calculateLine; }; CalculateElement.prototype.getSquarePointsFromStair = function (line1, line2, verticalLine1, verticalLine2) { var tempjoin1 = this.calculateLine.getIntersectionPoint(verticalLine1, line1); var tempjoin3 = this.calculateLine.getIntersectionPoint(verticalLine1, line2); var tempjoin2 = this.calculateLine.getIntersectionPoint(verticalLine2, line1); var tempjoin4 = this.calculateLine.getIntersectionPoint(verticalLine2, line2); var distance = BABYLON.Vector2.Distance(tempjoin1, tempjoin2); var num = parseInt(distance / this.layer.parameter.staircell); var count = 1; var linkedpoints = []; linkedpoints.push({ 1: tempjoin1, 2: tempjoin3 }); while (count < num) { var verticalLine = null; if (verticalLine2.hasOwnProperty('x')) { diff = (verticalLine2.x - verticalLine1.x) / num; verticalLine = { a: 0, b: 0, x: (verticalLine2.x - diff * count) }; } else if (verticalLine2.hasOwnProperty('y')) { diff = (verticalLine2.y - verticalLine1.y) / num; verticalLine = { a: 0, b: 0, x: (verticalLine2.y - diff * count) }; } else { diff = (verticalLine2.b - verticalLine1.b) / num; verticalLine = { a: verticalLine2.a, b: (verticalLine2.b - diff * count) }; } var join1 = this.calculateLine.getIntersectionPoint(verticalLine, line1); var join2 = this.calculateLine.getIntersectionPoint(verticalLine, line2); linkedpoints.push({ 1: join1, 2: join2 }); ++count; } linkedpoints.push({ 1: tempjoin2, 2: tempjoin4 }); return linkedpoints; }; CalculateElement.prototype.GetSpiralpoints = function (point) { var line = {}; var points = []; var verticalLine = {}; var verticalLine1 = {}; var verticalLine2 = {}; points.push({ x: (point.x + this.layer.parameter.spiralR1), y: point.y }); points.push({ x: (point.x - this.layer.parameter.spiralR1), y: point.y }); for (var i = 1; i < 6; ++i) { line.a = Math.tan(i * 30 * Math.PI / 180); line.b = point.y - line.a * point.x; verticalLine.a = -1 / line.a; verticalLine1.a = -1 / line.a; verticalLine2.a = -1 / line.a; verticalLine.b = point.y + 1 / line.a * point.x; verticalLine1.b = verticalLine.b + this.layer.calculateLine.driftY3(verticalLine.a, this.layer.parameter.spiralR1); verticalLine2.b = verticalLine.b - this.layer.calculateLine.driftY3(verticalLine.a, this.layer.parameter.spiralR1); var join1 = this.layer.calculateLine.getIntersectionPoint(verticalLine1, line); points.push(join1); var join2 = this.layer.calculateLine.getIntersectionPoint(verticalLine2, line); points.push(join2); } return points; }; //三个点的时候 CalculateElement.prototype.getAllPointsFromStair = function (points) { var allpoints = {}; var linkedpoints = []; //表示不是闭合的 var state = 1; var interval1 = (this.layer.parameter.stairWidth + this.layer.parameter.stairMeasure); var interval2 = this.layer.parameter.stairWidth; //和墙没关系,只是使用了它的函数 var lines = this.getWalllines(points, state, interval1, interval2); var edgepoints = this.getOutlineMeasureJoin(lines, points, state); var verticalLine_a = null; var verticalLine_b = null; for (var i = 0; i < edgepoints.border1.length - 1; ++i) { var point11 = edgepoints.border1[i]; var point12 = edgepoints.border1[i + 1]; var point21 = edgepoints.border2[i]; var point22 = edgepoints.border2[i + 1]; var line1 = this.calculateLine.createLine(point11, point12); var line2 = this.calculateLine.createLine(point21, point22); var num, extendnum, extenddiff, verticalLine1, verticalLine3; var join1, join2, join3, join4; var extendDistance = null; verticalLine1 = this.calculateLine.getVerticalLine(line2, point21); verticalLine3 = this.calculateLine.getVerticalLine(line2, point11); var tempjoin1 = this.calculateLine.getIntersectionPoint(verticalLine1, line1); var distance1 = BABYLON.Vector2.Distance(tempjoin1, point11); if (distance1 < this.layer.parameter.minInterval) { linkedpoints.push({ 1: point11, 2: point21 }); verticalLine_a = verticalLine1; } else if (this.calculateLine.containPoint(point11, point12, tempjoin1)) { verticalLine_a = verticalLine1; num = parseInt(distance1 / this.layer.parameter.staircell); if (num == 0 && distance1 > this.layer.parameter.minInterval) { num = 1; } var count = 0; while (count < num) { var verticalLine = null; if (verticalLine3.hasOwnProperty('x')) { diff = (verticalLine3.x - verticalLine1.x) / num; verticalLine = { a: 0, b: 0, x: (verticalLine3.x - diff * count) }; } else if (verticalLine3.hasOwnProperty('y')) { diff = (verticalLine3.y - verticalLine1.y) / num; verticalLine = { a: 0, b: 0, x: (verticalLine3.y - diff * count) }; } else { diff = (verticalLine3.b - verticalLine1.b) / num; verticalLine = { a: verticalLine3.a, b: (verticalLine3.b - diff * count) }; } var p = this.calculateLine.getIntersectionPoint(verticalLine, line1); linkedpoints.push({ 1: p, 2: point21 }); ++count; } } else { verticalLine_a = verticalLine3; tempjoin1 = this.calculateLine.getIntersectionPoint(verticalLine3, line2); distance1 = BABYLON.Vector2.Distance(tempjoin1, point21); num = parseInt(distance1 / this.layer.parameter.staircell); if (num == 0 && distance1 > this.layer.parameter.minInterval) { num = 1; } var count = 0; while (count < num) { var verticalLine = null; if (verticalLine1.hasOwnProperty('x')) { diff = (verticalLine1.x - verticalLine3.x) / num; verticalLine = { a: 0, b: 0, x: (verticalLine1.x - diff * count) }; } else if (verticalLine1.hasOwnProperty('y')) { diff = (verticalLine1.y - verticalLine3.y) / num; verticalLine = { a: 0, b: 0, x: (verticalLine1.y - diff * count) }; } else { diff = (verticalLine1.b - verticalLine3.b) / num; verticalLine = { a: verticalLine1.a, b: (verticalLine1.b - diff * count) }; } var p = this.calculateLine.getIntersectionPoint(verticalLine, line2); linkedpoints.push({ 1: point11, 2: p }); ++count; } } var verticalLine2 = this.calculateLine.getVerticalLine(line2, point22); var verticalLine4 = this.calculateLine.getVerticalLine(line2, point12); if (i != edgepoints.border1.length - 2) { var tempjoin2 = this.calculateLine.getIntersectionPoint(verticalLine2, line1); var distance2 = BABYLON.Vector2.Distance(tempjoin2, point12); if (distance2 < this.layer.parameter.minInterval) { linkedpoints.push({ 1: point12, 2: point22 }); verticalLine_b = verticalLine2; var linked = this.getSquarePointsFromStair(line1, line2, verticalLine_a, verticalLine_b); linkedpoints = linkedpoints.concat(linked); } else if (this.calculateLine.containPoint(point11, point12, tempjoin2)) { verticalLine_b = verticalLine2; var linked = this.getSquarePointsFromStair(line1, line2, verticalLine_a, verticalLine_b); linkedpoints = linkedpoints.concat(linked); verticalLine_a = null; verticalLine_b = null; num = parseInt(distance2 / this.layer.parameter.staircell); if (num == 0 && distance1 > this.layer.parameter.minInterval) { num = 1; } var count = 1; while (count < num) { var verticalLine = null; if (verticalLine4.hasOwnProperty('x')) { diff = (verticalLine4.x - verticalLine2.x) / num; verticalLine = { a: 0, b: 0, x: (verticalLine4.x - diff * count) }; } else if (verticalLine4.hasOwnProperty('y')) { diff = (verticalLine4.y - verticalLine2.y) / num; verticalLine = { a: 0, b: 0, x: (verticalLine4.y - diff * count) }; } else { diff = (verticalLine4.b - verticalLine2.b) / num; verticalLine = { a: verticalLine4.a, b: (verticalLine4.b - diff * count) }; } var p = this.calculateLine.getIntersectionPoint(verticalLine, line1); linkedpoints.push({ 1: p, 2: point22 }); ++count; } } else { verticalLine_b = verticalLine4; var linked = this.getSquarePointsFromStair(line1, line2, verticalLine_a, verticalLine_b); linkedpoints = linkedpoints.concat(linked); verticalLine_a = null; verticalLine_b = null; num = parseInt(distance2 / this.layer.parameter.staircell); if (num == 0 && distance1 > this.layer.parameter.minInterval) { num = 1; } var count = 1; while (count < num) { var verticalLine = null; if (verticalLine2.hasOwnProperty('x')) { diff = (verticalLine2.x - verticalLine4.x) / num; verticalLine = { a: 0, b: 0, x: (verticalLine2.x - diff * count) }; } else if (verticalLine2.hasOwnProperty('y')) { diff = (verticalLine2.y - verticalLine4.y) / num; verticalLine = { a: 0, b: 0, x: (verticalLine2.y - diff * count) }; } else { diff = (verticalLine2.b - verticalLine4.b) / num; verticalLine = { a: verticalLine2.a, b: (verticalLine2.b - diff * count) }; } var p = this.calculateLine.getIntersectionPoint(verticalLine, line2); linkedpoints.push({ 1: point12, 2: p }); ++count; } } } else { verticalLine_b = verticalLine2; var linked = this.getSquarePointsFromStair(line1, line2, verticalLine_a, verticalLine_b); linkedpoints = linkedpoints.concat(linked); verticalLine_a = null; verticalLine_b = null; } } allpoints.vertical = linkedpoints; allpoints.border1 = edgepoints.border1; allpoints.border2 = edgepoints.border2; allpoints.arrows1 = edgepoints.arrows1; allpoints.arrows2 = edgepoints.arrows2; return allpoints; }; /* //两个点的时候 CalculateElement.prototype.getAllPointsFromStair=function(point1,point2) { var line = this.calculateLine.createLine(point1,point2); var lines = this.calculateLine.getParallelLineForDistance(line,this.layer.parameter.stairWidth); var start1 = this.calculateLine.getJoinLinePoint(point1,lines.line1); var start2 = this.calculateLine.getJoinLinePoint(point1,lines.line2); var end1 = this.calculateLine.getJoinLinePoint(point2,lines.line1); var end2 = this.calculateLine.getJoinLinePoint(point2,lines.line2); var distance = BABYLON.Vector2.Distance(point1,point2); var num = parseInt(distance/this.layer.parameter.staircell); //针对直线的函数 var divide=null; var verticalLine1 = this.calculateLine.getVerticalLine(line,point1); var verticalLine2 = this.calculateLine.getVerticalLine(line,point2); var diff=null; var count=1; var points=[]; points.push({1:start1,2:start2}); while(count -1) { return points[pre]; } else { return points[points.length - 1]; } }; //points数组里面,在index前面的序号 CalculateElement.prototype.getPreIndex = function (points, index) { var pre = index - 1; if (pre == -1) { pre = points.length - 1; } return pre; }; //points数组里面,在index后面的点 CalculateElement.prototype.getNextPoint = function (points, index) { var next = index + 1; if (next > points.length - 1) { return points[0]; } else { return points[next]; } }; //points数组里面,在index后面的序号 CalculateElement.prototype.getNextIndex = function (points, index, state) { var next = index + 1; if (next > points.length - 1 && (typeof (state) == "undefined" || state == 0)) { next = 0; } else if (next > points.length - 1) { next = index - 1; } return next; }; //在长度是len的数组里,序号index和num是否相邻 CalculateElement.prototype.isNeighbor = function (len, index, num) { if (Math.abs(index - num) == 1) { return true; } else if (index == 0 && (num == len - 1)) { return true; } else if ((index == len - 1) && num == 0) { return true; } else { return false; } }; //计算墙的尺寸 CalculateElement.prototype.computerMeasure = function (geometry) { var points = geometry.points; var state = geometry.state; var type = geometry.wallType; var lines, interval; /* if(type==2) { interval=partitionThickness; } else { interval=wallThickness; } */ //lines=this.getWalllines(points,state,interval,interval/2); lines = this.getWalllines2(geometry); var wallpoint = this.getOutlineMeasureJoin(lines, points, state); //var wallpoint=this.getOutlineMeasureJoin2(lines,geometry); return wallpoint; }; //从一组border里面挑选出合适的 CalculateElement.prototype.getIndexFromLines = function (lines, point1, point2) { var seg = {}; seg.point1 = point1; seg.point2 = point2; var joins = {}; for (var i = 0; i < lines.length; ++i) { var seg1 = {}; seg1.point1 = this.layer.vectors[lines[i].id].geometry.wallInfo[lines[i].index1][lines[i].border]; seg1.point2 = this.layer.vectors[lines[i].id].geometry.wallInfo[lines[i].index2][lines[i].border]; var join = this.calculateLine.isjoin(seg, seg1); if (join == null) { continue; } else { joins[i] = join; } } var index = null; for (var key in joins) { if (index == null) { index = key; } else { var d1 = BABYLON.Vector2.Distance(point2, joins[key]); var d2 = BABYLON.Vector2.Distance(point2, joins[index]); if (d1 < d2) { index = key; } } } if (index == null) { return null; } else { return { index: index, join: joins[key] }; } }; //调整不闭合墙的端点 CalculateElement.prototype.changeEndPointMeasure = function (wallpoint, geometry) { if (typeof (geometry.firstLines) != "undefined" && geometry.firstLines.length > 0) { var result = this.singleWallContain(geometry.points[0], geometry.firstLines[0].id); if (result != null) { var jo = this.getIndexFromLines(geometry.firstLines, wallpoint.border1[0], wallpoint.border1[1]); if (jo != null) { wallpoint.border1[0] = jo["join"]; var arrowjoin1 = this.calculateLine.getJoinLinePoint(jo["join"], this.calculateLine.createLine(wallpoint.arrows1[0], wallpoint.arrows1[1])); if (arrowjoin1 != null) { wallpoint.arrows1[0] = arrowjoin1; } var seg = {}; seg.point1 = this.layer.vectors[geometry.firstLines[jo["index"]].id].geometry.wallInfo[geometry.firstLines[jo["index"]].index1][geometry.firstLines[jo["index"]].border]; seg.point2 = this.layer.vectors[geometry.firstLines[jo["index"]].id].geometry.wallInfo[geometry.firstLines[jo["index"]].index2][geometry.firstLines[jo["index"]].border]; var jn = this.calculateLine.isjoin(seg, { point1: wallpoint.border2[0], point2: wallpoint.border2[1] }); if (jn != null) { wallpoint.border2[0] = jn; var arrowjoin2 = this.calculateLine.getJoinLinePoint(jn, this.calculateLine.createLine(wallpoint.arrows2[0], wallpoint.arrows2[1])); if (arrowjoin2 != null) { wallpoint.arrows2[0] = arrowjoin2; } } } } else { delete geometry.firstLines; } } if (typeof (geometry.endLines) != "undefined" && geometry.endLines.length > 0) { var len = wallpoint.border1.length; var result = this.singleWallContain(geometry.points[len - 1], geometry.endLines[0].id); if (result != null) { var jo = this.getIndexFromLines(geometry.endLines, wallpoint.border1[0], wallpoint.border1[1]); if (jo != null) { wallpoint.border1[len - 1] = jo["join"]; var arrowjoin1 = this.calculateLine.getJoinLinePoint(jo["join"], this.calculateLine.createLine(wallpoint.arrows1[len - 1], wallpoint.arrows1[len - 2])); if (arrowjoin1 != null) { wallpoint.arrows1[len - 1] = arrowjoin1; } var seg = {}; seg.point1 = this.layer.vectors[geometry.endLines[jo["index"]].id].geometry.wallInfo[geometry.endLines[jo["index"]].index1][geometry.endLines[jo["index"]].border]; seg.point2 = this.layer.vectors[geometry.endLines[jo["index"]].id].geometry.wallInfo[geometry.endLines[jo["index"]].index2][geometry.endLines[jo["index"]].border]; var jn = this.calculateLine.isjoin(seg, { point1: wallpoint.border2[len - 2], point2: wallpoint.border2[len - 1] }); if (jn != null) { wallpoint.border2[len - 1] = jn; var arrowjoin2 = this.calculateLine.getJoinLinePoint(jn, this.calculateLine.createLine(wallpoint.arrows2[len - 1], wallpoint.arrows2[len - 2])); if (arrowjoin2 != null) { wallpoint.arrows2[len - 1] = arrowjoin2; } } } } else { delete geometry.endLines; } } return wallpoint; }; //获得墙的内外侧 CalculateElement.prototype.getOneWallOutline = function (line, interval1, interval2) { var border1 = {}; var border2 = {}; var measure1 = {}; var measure2 = {}; if (line.a == 0) { measure1.a = 0; measure1.b = 0 measure2.a = 0; measure2.b = 0 border1.a = 0; border1.b = 0 border2.a = 0; border2.b = 0 if (line.hasOwnProperty('x')) { measure1.x = line.x + interval1; border1.x = line.x + interval2; measure2.x = line.x - interval1; border2.x = line.x - interval2; } else if (line.hasOwnProperty('y')) { measure1.y = line.y + interval1; border1.y = line.y + interval2; measure2.y = line.y - interval1; border2.y = line.y - interval2; } } else { //测量 measure1.a = line.a; //measure1.b= line.b+this.calculateLine.driftY(measure1.a,1,type); measure1.b = line.b + this.calculateLine.driftY3(measure1.a, interval1); measure2.a = line.a; //measure2.b= line.b-this.calculateLine.driftY(measure2.a,1,type); measure2.b = line.b - this.calculateLine.driftY3(measure2.a, interval1); //墙外侧 border1.a = line.a; border1.b = line.b + this.calculateLine.driftY3(border1.a, interval2); border2.a = line.a; border2.b = line.b - this.calculateLine.driftY3(border2.a, interval2); } return { b1: border1, b2: border2, m1: measure1, m2: measure2 }; }; /* //删除墙后,border变了 CalculateElement.prototype.changeWallEndpoint=function(point,line1,line2) { var verticalLine=this.calculateLine.getVerticalLine(line1,point); var join1=this.getIntersectionPoint(line1,verticalLine); return join; } */ //墙的厚度可变 CalculateElement.prototype.getWalllines2 = function (geometry) { var points = geometry.points; var wallInfo = geometry.wallInfo; var ringflag = geometry.state; var type = geometry.wallType; var d; if (type == 2) { d = partitionThickness / 2; } else { d = wallThickness / 2; } var result = { border1: [], border2: [], arrows1: [], arrows2: [] }; var interval1 = wallInfo[0].thick / 2 + d; // var interval2 = wallInfo[0].thick / 2; var interval2 = 0.00001; var outlines = this.getOneWallOutline(this.calculateLine.createLine(points[0], points[1]), interval1, interval2); result.border1.push(outlines.b1); result.border2.push(outlines.b2); result.arrows1.push(outlines.m1); result.arrows2.push(outlines.m2); for (var i = 1; i < points.length; ++i) { var j = i - 1; var k = i + 1; if (i == points.length - 1) { k = 0; } if (ringflag == 1 && i == points.length - 1) //不闭合 { return result; } var line = this.calculateLine.createLine(points[i], points[k]); var radial = { point1: points[i], point2: points[k] }; var outlines1 = { b1: result.border1[result.border1.length - 1], b2: result.border2[result.border2.length - 1], m1: result.arrows1[result.arrows1.length - 1], m2: result.arrows2[result.arrows2.length - 1] }; interval1 = wallInfo[i].thick / 2 + d; // interval2 = wallInfo[i].thick / 2; interval2 = 0.00001; var outlines2 = this.getOneWallOutline(line, interval1, interval2); var join1 = this.calculateLine.getIntersectionPoint(outlines1.b1, outlines2.b1); if (join1 == null) { join1 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b1); } var join2 = this.calculateLine.getIntersectionPoint(outlines1.b2, outlines2.b2); if (join2 == null) { join2 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b2); } var _join1 = this.calculateLine.getIntersectionPoint(outlines1.b1, outlines2.b2); if (_join1 == null) { _join1 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b1); } var _join2 = this.calculateLine.getIntersectionPoint(outlines1.b2, outlines2.b1); if (_join2 == null) { _join2 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b2); } var line2 = this.calculateLine.createLine(points[i], points[j]); var radial2 = { point1: points[i], point2: points[j] }; var nextseg1 = {}; var nextseg3 = {}; var nextseg2 = {}; var nextseg4 = {}; nextseg1.point1 = this.calculateLine.getJoinLinePoint(points[k], outlines2.b1); nextseg1.point2 = join1; nextseg3.point1 = this.calculateLine.getJoinLinePoint(points[k], outlines2.b2); nextseg3.point2 = join2; nextseg2.point1 = this.calculateLine.getJoinLinePoint(points[j], outlines1.b1); nextseg2.point2 = join1; nextseg4.point1 = this.calculateLine.getJoinLinePoint(points[j], outlines1.b2); nextseg4.point2 = join2; if (this.calculateLine.isjoin3(nextseg1, radial2) || this.calculateLine.isjoin3(nextseg3, radial2) || this.calculateLine.isjoin3(nextseg2, radial) || this.calculateLine.isjoin3(nextseg4, radial) || this.calculateLine.isjoin3(nextseg1, radial) || this.calculateLine.isjoin3(nextseg3, radial) || this.calculateLine.isjoin3(nextseg2, radial2) || this.calculateLine.isjoin3(nextseg4, radial2)) { result.border1.push(outlines2.b2); result.border2.push(outlines2.b1); result.arrows1.push(outlines2.m2); result.arrows2.push(outlines2.m1); } else { result.border1.push(outlines2.b1); result.border2.push(outlines2.b2); result.arrows1.push(outlines2.m1); result.arrows2.push(outlines2.m2); } } return result; }; //获取墙的border和arrows CalculateElement.prototype.getWalllines = function (points, ringflag, interval1, interval2) { var result = { border1: [], border2: [], arrows1: [], arrows2: [] }; var outlines = this.getOneWallOutline(this.calculateLine.createLine(points[0], points[1]), interval1, interval2); result.border1.push(outlines.b1); result.border2.push(outlines.b2); result.arrows1.push(outlines.m1); result.arrows2.push(outlines.m2); for (var i = 1; i < points.length; ++i) { var j = i - 1; var k = i + 1; if (i == points.length - 1) { k = 0; } if (ringflag == 1 && i == points.length - 1) //不闭合 { return result; } var line = this.calculateLine.createLine(points[i], points[k]); var radial = { point1: points[i], point2: points[k] }; var outlines1 = { b1: result.border1[result.border1.length - 1], b2: result.border2[result.border2.length - 1], m1: result.arrows1[result.arrows1.length - 1], m2: result.arrows2[result.arrows2.length - 1] }; var outlines2 = this.getOneWallOutline(line, interval1, interval2); var join1 = this.calculateLine.getIntersectionPoint(outlines1.b1, outlines2.b1); if (join1 == null) { join1 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b1); } var join2 = this.calculateLine.getIntersectionPoint(outlines1.b2, outlines2.b2); if (join2 == null) { join2 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b2); } var _join1 = this.calculateLine.getIntersectionPoint(outlines1.b1, outlines2.b2); if (_join1 == null) { _join1 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b1); } var _join2 = this.calculateLine.getIntersectionPoint(outlines1.b2, outlines2.b1); if (_join2 == null) { _join2 = this.calculateLine.getJoinLinePoint(points[i], outlines1.b2); } var line2 = this.calculateLine.createLine(points[i], points[j]); var radial2 = { point1: points[i], point2: points[j] }; var nextseg1 = {}; var nextseg3 = {}; var nextseg2 = {}; var nextseg4 = {}; nextseg1.point1 = this.calculateLine.getJoinLinePoint(points[k], outlines2.b1); nextseg1.point2 = join1; nextseg3.point1 = this.calculateLine.getJoinLinePoint(points[k], outlines2.b2); nextseg3.point2 = join2; nextseg2.point1 = this.calculateLine.getJoinLinePoint(points[j], outlines1.b1); nextseg2.point2 = join1; nextseg4.point1 = this.calculateLine.getJoinLinePoint(points[j], outlines1.b2); nextseg4.point2 = join2; if (this.calculateLine.isjoin3(nextseg1, radial2) || this.calculateLine.isjoin3(nextseg3, radial2) || this.calculateLine.isjoin3(nextseg2, radial) || this.calculateLine.isjoin3(nextseg4, radial) || this.calculateLine.isjoin3(nextseg1, radial) || this.calculateLine.isjoin3(nextseg3, radial) || this.calculateLine.isjoin3(nextseg2, radial2) || this.calculateLine.isjoin3(nextseg4, radial2)) { result.border1.push(outlines2.b2); result.border2.push(outlines2.b1); result.arrows1.push(outlines2.m2); result.arrows2.push(outlines2.m1); } else { result.border1.push(outlines2.b1); result.border2.push(outlines2.b2); result.arrows1.push(outlines2.m1); result.arrows2.push(outlines2.m2); } } return result; } //获取交点 CalculateElement.prototype.getOutlineMeasureJoin2 = function (walllines, geometry) { if (walllines == null) { return; } var state = geometry.state; var points = geometry.points; var border1 = geometry.wallInfo[0].border1; var border2 = geometry.wallInfo[0].border2; var _border1 = geometry.wallInfo[geometry.points.length - 1].border1; var _border2 = geometry.wallInfo[geometry.points.length - 1].border2; var len = walllines.arrows1.length; var wallpoint = { arrows1: [], arrows2: [], border1: [], border2: [] }; if (len == 1) { //var joinpoint1=this.calculateLine.getJoinLinePoint(points[0],walllines.arrows1[0]); var joinpoint1 = this.calculateLine.getJoinLinePoint(border1, walllines.arrows1[0]); wallpoint.arrows1.push(joinpoint1); //var joinpoint2=this.calculateLine.getJoinLinePoint(points[1],walllines.arrows1[0]); var joinpoint2 = this.calculateLine.getJoinLinePoint(_border1, walllines.arrows1[0]); wallpoint.arrows1.push(joinpoint2); //var joinpoint3=this.calculateLine.getJoinLinePoint(points[0],walllines.arrows2[0]); var joinpoint3 = this.calculateLine.getJoinLinePoint(border2, walllines.arrows2[0]); wallpoint.arrows2.push(joinpoint3); //var joinpoint4=this.calculateLine.getJoinLinePoint(points[1],walllines.arrows2[0]); var joinpoint4 = this.calculateLine.getJoinLinePoint(_border2, walllines.arrows2[0]); wallpoint.arrows2.push(joinpoint4); //var joinpoint5=this.calculateLine.getJoinLinePoint(points[0],walllines.border1[0]); var joinpoint5 = this.calculateLine.getJoinLinePoint(border1, walllines.border1[0]); wallpoint.border1.push(joinpoint5); //var joinpoint6=this.calculateLine.getJoinLinePoint(points[1],walllines.border1[0]); var joinpoint6 = this.calculateLine.getJoinLinePoint(_border1, walllines.border1[0]); wallpoint.border1.push(joinpoint6); //var joinpoint7=this.calculateLine.getJoinLinePoint(points[0],walllines.border2[0]); var joinpoint7 = this.calculateLine.getJoinLinePoint(border2, walllines.border2[0]); wallpoint.border2.push(joinpoint7); //var joinpoint8=this.calculateLine.getJoinLinePoint(points[1],walllines.border2[0]); var joinpoint8 = this.calculateLine.getJoinLinePoint(_border2, walllines.border2[0]); wallpoint.border2.push(joinpoint8); return wallpoint; } for (var i = 0; i < len; ++i) { if (state == 1) { if (i == 0 || i == len - 1) { if (i == 0) { //var border1join1=this.calculateLine.getJoinLinePoint(points[0],walllines.border1[0]); var border1join1 = this.calculateLine.getJoinLinePoint(border1, walllines.border1[0]); wallpoint.border1.push(border1join1); //var border2join1=this.calculateLine.getJoinLinePoint(points[0],walllines.border2[0]); var border2join1 = this.calculateLine.getJoinLinePoint(border2, walllines.border2[0]); wallpoint.border2.push(border2join1); var border1join2 = this.calculateLine.getIntersectionPoint(walllines.border1[0], walllines.border1[1]); if (border1join2 == null) { border1join2 = this.calculateLine.getJoinLinePoint(points[1], walllines.border1[0]); } wallpoint.border1.push(border1join2); var border2join2 = this.calculateLine.getIntersectionPoint(walllines.border2[0], walllines.border2[1]); if (border2join2 == null) { border2join2 = this.calculateLine.getJoinLinePoint(points[1], walllines.border2[0]); } wallpoint.border2.push(border2join2); //var join1=this.calculateLine.getJoinLinePoint(points[0],walllines.arrows1[0]); var join1 = this.calculateLine.getJoinLinePoint(border1, walllines.arrows1[0]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join2, walllines.arrows1[0]); wallpoint.arrows1.push(join2); //var join3=this.calculateLine.getJoinLinePoint(points[0],walllines.arrows2[0]); var join3 = this.calculateLine.getJoinLinePoint(border2, walllines.arrows2[0]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join2, walllines.arrows2[0]); wallpoint.arrows2.push(join4); } else { //var border1join1=this.calculateLine.getJoinLinePoint(points[i+1],walllines.border1[i]); var border1join1 = this.calculateLine.getJoinLinePoint(_border1, walllines.border1[i]); wallpoint.border1.push(border1join1); //var border2join1=this.calculateLine.getJoinLinePoint(points[i+1],walllines.border2[i]); var border2join1 = this.calculateLine.getJoinLinePoint(_border2, walllines.border2[i]); wallpoint.border2.push(border2join1); var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[i], walllines.arrows1[i]); wallpoint.arrows1.push(join1); //var join2=this.calculateLine.getJoinLinePoint(points[i+1],walllines.arrows1[i]); var join2 = this.calculateLine.getJoinLinePoint(_border1, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[i], walllines.arrows2[i]); wallpoint.arrows2.push(join3); //var join4=this.calculateLine.getJoinLinePoint(points[i+1],walllines.arrows2[i]); var join4 = this.calculateLine.getJoinLinePoint(_border2, walllines.arrows2[i]); wallpoint.arrows2.push(join4); } continue; } else { var border1join = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getNextIndex(walllines.border1, i)]); if (border1join == null) { border1join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join); var border2join = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getNextIndex(walllines.border2, i)]); if (border2join == null) { border2join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join); var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[wallpoint.border1.length - 2], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[wallpoint.border2.length - 2], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join, walllines.arrows2[i]); wallpoint.arrows2.push(join4); continue; } } else if (state == 0) { if (i == 0) { var border1join1 = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getPreIndex(walllines.border1, i)]); if (border1join1 == null) { border1join1 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join1); var border1join2 = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getNextIndex(walllines.border1, i)]); if (border1join2 == null) { border1join2 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join2); var border2join1 = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getPreIndex(walllines.border2, i)]); if (border2join1 == null) { border2join1 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join1); var border2join2 = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getNextIndex(walllines.border2, i)]); if (border2join2 == null) { border2join2 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join2); var join1 = this.calculateLine.getJoinLinePoint(border1join1, walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join2, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(border2join1, walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join2, walllines.arrows2[i]); wallpoint.arrows2.push(join4); continue; } } if (i < len - 1) { var border1join = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getNextIndex(walllines.border1, i)]); if (border1join == null) { border1join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join); var border2join = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getNextIndex(walllines.border2, i)]); if (border2join == null) { border2join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join); var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[wallpoint.border1.length - 2], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[wallpoint.border2.length - 2], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join, walllines.arrows2[i]); wallpoint.arrows2.push(join4); } else { var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[wallpoint.border1.length - 1], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(wallpoint.border1[0], walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[wallpoint.border2.length - 1], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(wallpoint.border2[0], walllines.arrows2[i]); wallpoint.arrows2.push(join4); } } return wallpoint; }; //获取交点 CalculateElement.prototype.getOutlineMeasureJoin = function (walllines, points, state) { if (walllines == null) { return; } var len = walllines.arrows1.length; var wallpoint = { arrows1: [], arrows2: [], border1: [], border2: [] }; if (len == 1) { var joinpoint1 = this.calculateLine.getJoinLinePoint(points[0], walllines.arrows1[0]); wallpoint.arrows1.push(joinpoint1); var joinpoint2 = this.calculateLine.getJoinLinePoint(points[1], walllines.arrows1[0]); wallpoint.arrows1.push(joinpoint2); var joinpoint3 = this.calculateLine.getJoinLinePoint(points[0], walllines.arrows2[0]); wallpoint.arrows2.push(joinpoint3); var joinpoint4 = this.calculateLine.getJoinLinePoint(points[1], walllines.arrows2[0]); wallpoint.arrows2.push(joinpoint4); var joinpoint5 = this.calculateLine.getJoinLinePoint(points[0], walllines.border1[0]); wallpoint.border1.push(joinpoint5); var joinpoint6 = this.calculateLine.getJoinLinePoint(points[1], walllines.border1[0]); wallpoint.border1.push(joinpoint6); var joinpoint7 = this.calculateLine.getJoinLinePoint(points[0], walllines.border2[0]); wallpoint.border2.push(joinpoint7); var joinpoint8 = this.calculateLine.getJoinLinePoint(points[1], walllines.border2[0]); wallpoint.border2.push(joinpoint8); return wallpoint; } for (var i = 0; i < len; ++i) { if (state == 1) { if (i == 0 || i == len - 1) { if (i == 0) { var border1join1 = this.calculateLine.getJoinLinePoint(points[0], walllines.border1[0]); wallpoint.border1.push(border1join1); var border2join1 = this.calculateLine.getJoinLinePoint(points[0], walllines.border2[0]); wallpoint.border2.push(border2join1); var border1join2 = this.calculateLine.getIntersectionPoint(walllines.border1[0], walllines.border1[1]); if (border1join2 == null) { border1join2 = this.calculateLine.getJoinLinePoint(points[1], walllines.border1[0]); } wallpoint.border1.push(border1join2); var border2join2 = this.calculateLine.getIntersectionPoint(walllines.border2[0], walllines.border2[1]); if (border2join2 == null) { border2join2 = this.calculateLine.getJoinLinePoint(points[1], walllines.border2[0]); } wallpoint.border2.push(border2join2); var join1 = this.calculateLine.getJoinLinePoint(points[0], walllines.arrows1[0]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join2, walllines.arrows1[0]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(points[0], walllines.arrows2[0]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join2, walllines.arrows2[0]); wallpoint.arrows2.push(join4); } else { var border1join1 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); wallpoint.border1.push(border1join1); var border2join1 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); wallpoint.border2.push(border2join1); var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[i], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[i], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.arrows2[i]); wallpoint.arrows2.push(join4); } continue; } else { var border1join = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getNextIndex(walllines.border1, i)]); if (border1join == null) { border1join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join); var border2join = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getNextIndex(walllines.border2, i)]); if (border2join == null) { border2join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join); var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[wallpoint.border1.length - 2], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[wallpoint.border2.length - 2], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join, walllines.arrows2[i]); wallpoint.arrows2.push(join4); continue; } } else if (state == 0) { if (i == 0) { var border1join1 = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getPreIndex(walllines.border1, i)]); if (border1join1 == null) { border1join1 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join1); var border1join2 = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getNextIndex(walllines.border1, i)]); if (border1join2 == null) { border1join2 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join2); var border2join1 = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getPreIndex(walllines.border2, i)]); if (border2join1 == null) { border2join1 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join1); var border2join2 = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getNextIndex(walllines.border2, i)]); if (border2join2 == null) { border2join2 = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join2); var join1 = this.calculateLine.getJoinLinePoint(border1join1, walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join2, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(border2join1, walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join2, walllines.arrows2[i]); wallpoint.arrows2.push(join4); continue; } } if (i < len - 1) { var border1join = this.calculateLine.getIntersectionPoint(walllines.border1[i], walllines.border1[this.getNextIndex(walllines.border1, i)]); if (border1join == null) { border1join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border1[i]); } wallpoint.border1.push(border1join); var border2join = this.calculateLine.getIntersectionPoint(walllines.border2[i], walllines.border2[this.getNextIndex(walllines.border2, i)]); if (border2join == null) { border2join = this.calculateLine.getJoinLinePoint(points[i + 1], walllines.border2[i]); } wallpoint.border2.push(border2join); var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[wallpoint.border1.length - 2], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(border1join, walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[wallpoint.border2.length - 2], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(border2join, walllines.arrows2[i]); wallpoint.arrows2.push(join4); } else { var join1 = this.calculateLine.getJoinLinePoint(wallpoint.border1[wallpoint.border1.length - 1], walllines.arrows1[i]); wallpoint.arrows1.push(join1); var join2 = this.calculateLine.getJoinLinePoint(wallpoint.border1[0], walllines.arrows1[i]); wallpoint.arrows1.push(join2); var join3 = this.calculateLine.getJoinLinePoint(wallpoint.border2[wallpoint.border2.length - 1], walllines.arrows2[i]); wallpoint.arrows2.push(join3); var join4 = this.calculateLine.getJoinLinePoint(wallpoint.border2[0], walllines.arrows2[i]); wallpoint.arrows2.push(join4); } } wallpoint.arrows3 = [] for (var i = 0; i < len; i++) { var start = wallpoint.arrows1[i] var end = wallpoint.arrows1[i + 1] // console.log(i, start.y - end.y) } return wallpoint; }; //border1,border2是墙的边缘 //arrow1,arrow2是墙的测量线 CalculateElement.prototype.getWallMappingPoints = function (wallpoint, points, state) { if (wallpoint == null) { return; } var len = points.length; var resultLines = []; for (var i = 0; i < len; ++i) { if (state == 1) { if (i == len - 1) { break; } } var measureLine = {}; measureLine.arrow1Line1 = wallpoint.arrows1[2 * i]; measureLine.arrow1Line2 = wallpoint.arrows1[this.getNextIndex(wallpoint.arrows1, 2 * i)]; measureLine.text1pt = { x: (measureLine.arrow1Line1.x + measureLine.arrow1Line2.x) / 2, y: (measureLine.arrow1Line1.y + measureLine.arrow1Line2.y) / 2 }; measureLine.arrow2Line1 = wallpoint.arrows2[2 * i]; measureLine.arrow2Line2 = wallpoint.arrows2[this.getNextIndex(wallpoint.arrows2, 2 * i)]; measureLine.text2pt = { x: (measureLine.arrow2Line1.x + measureLine.arrow2Line2.x) / 2, y: (measureLine.arrow2Line1.y + measureLine.arrow2Line2.y) / 2 }; if (wallpoint.border1 != null) { measureLine.border1Line1 = wallpoint.border1[i]; measureLine.border1Line2 = wallpoint.border1[this.getNextIndex(wallpoint.border1, i)]; measureLine.distance1 = BABYLON.Vector2.Distance(measureLine.border1Line1, measureLine.border1Line2) / meter; } else { measureLine.distance1 = BABYLON.Vector2.Distance(measureLine.arrow1Line1, measureLine.arrow1Line2) / meter; } if (wallpoint.border2 != null) { measureLine.border2Line1 = wallpoint.border2[i]; measureLine.border2Line2 = wallpoint.border2[this.getNextIndex(wallpoint.border2, i)]; measureLine.distance2 = BABYLON.Vector2.Distance(measureLine.border2Line1, measureLine.border2Line2) / meter; } else { measureLine.distance2 = BABYLON.Vector2.Distance(measureLine.arrow2Line1, measureLine.arrow2Line2) / meter; } measureLine.border1Line1 = wallpoint.border1[i]; measureLine.border1Line2 = wallpoint.border1[this.getNextIndex(wallpoint.border1, i)]; measureLine.distance1 = BABYLON.Vector2.Distance(measureLine.border1Line1, measureLine.border1Line2) / meter; resultLines.push(measureLine); } return resultLines; }; //9.7 CalculateElement.prototype.updateSelectWallLineIndex = function (wallId, wallindex1, wallindex2, mergeindex) { var len = this.layer.vectors[wallId].geometry.points.length; if (this.isNeighbor(len, wallindex1, mergeindex)) { this.updateSymbolsWallCornerIndexDelete(wallId, mergeindex, wallindex1); if (wallindex1 > mergeindex) { if (mergeindex == 0 && wallindex1 != 1) { wallindex1 = 0; } else { --wallindex1; --wallindex2; } } else if (wallindex1 < mergeindex) { if (wallindex1 == 0 && mergeindex == 1) { --wallindex2; } else if (wallindex1 == 0) { wallindex2 = mergeindex - 1; } } } else if (this.isNeighbor(len, wallindex2, mergeindex)) { this.updateSymbolsWallCornerIndexDelete(wallId, mergeindex, wallindex2); if (wallindex2 > mergeindex) { if (mergeindex == 0 && wallindex2 != 1) { wallindex2 = 0; } else { --wallindex1; --wallindex2; } } else if (wallindex2 < mergeindex) { if (wallindex2 == 0 && mergeindex == 1) { --wallindex1; } else if (wallindex2 == 0) { wallindex1 = mergeindex - 1; } } } if (wallindex1 < 0) { wallindex1 = 0; } if (wallindex2 < 0) { wallindex2 = 0; } return { wallindex1: wallindex1, wallindex2: wallindex2 }; }; CalculateElement.prototype.getIndexsFordeleteWall = function (wallId, index) { var result = {}; var points = this.layer.vectors[wallId].geometry.points; for (var i = 0; i < points.length; ++i) { if (i == index) { continue; } if (i > index) { result[i] = i - 1; } else { result[i] = i; } } return result; }; CalculateElement.prototype.updateIndexAdd = function (len, index, startindex, endindex, symbolpoint1, symbolpoint2, point, wallpoint1, wallpoint2) { var temp = null; if (startindex > endindex) { temp = endindex; endindex = startindex; startindex = temp; } if (Math.abs(startindex - endindex) == 1) { if (startindex > index && endindex > index) { ++startindex; ++endindex; } else if (startindex == index && endindex > index) { ++startindex; ++endindex; } else if (startindex < index && endindex == index) { //两种情况,双击点在哪一侧? if (this.calculateLine.segmentContainPoint(wallpoint1, point, symbolpoint1) && this.calculateLine.segmentContainPoint(wallpoint1, point, symbolpoint2)) { //什么也不变 } else { ++startindex; ++endindex; } } } else if (index > endindex) { //两种情况,双击点在哪一侧? if (this.calculateLine.segmentContainPoint(wallpoint1, point, symbolpoint1) && this.calculateLine.segmentContainPoint(wallpoint1, point, symbolpoint2)) { startindex = endindex; endindex = index; } else { startindex = index; endindex = 0; } } else { ++endindex; } if (temp == null) { return { start: startindex, end: endindex }; } else { return { start: endindex, end: startindex }; } }; //双击墙面 CalculateElement.prototype.updateSymbolsWallCornerIndexAdd = function (wallId, insertindex, point) { var len = this.layer.vectors[wallId].geometry.points.length; var wallindex1 = insertindex - 1; var wallindex2 = insertindex + 1; if (wallindex2 == len) { wallindex2 = 0; } var wallpoint1 = this.layer.vectors[wallId].geometry.points[wallindex1]; var wallpoint2 = this.layer.vectors[wallId].geometry.points[wallindex2]; for (var key in this.layer.vectors[wallId].symbol2Ds) { var symbol2d = this.layer.vectors[wallId].symbol2Ds[key]; var indexs = this.updateIndexAdd(len, insertindex, symbol2d.attributes.wallstartindex, symbol2d.attributes.wallendindex, symbol2d.geometry.points[0], symbol2d.geometry.points[1], point, wallpoint1, wallpoint2); symbol2d.attributes.wallstartindex = indexs.start; symbol2d.attributes.wallendindex = indexs.end; } } //9.7 CalculateElement.prototype.updateSymbolsWallCornerIndexDelete = function (wallId, mergeindex, selectIndex) { var len = this.layer.vectors[wallId].geometry.points.length; if (!this.isNeighbor(len, mergeindex, selectIndex)) { return; } for (var key in this.layer.vectors[wallId].symbol2Ds) { var symbol2d = this.layer.vectors[wallId].symbol2Ds[key]; var index1 = symbol2d.attributes.wallstartindex; var index2 = symbol2d.attributes.wallendindex; if (mergeindex != 0 && selectIndex != 0) { if (Math.min(index1, index2) > Math.max(mergeindex, selectIndex)) { --symbol2d.attributes.wallstartindex; --symbol2d.attributes.wallendindex; } else if (Math.min(index1, index2) == Math.max(mergeindex, selectIndex)) { symbol2d.attributes.wallstartindex = Math.min(mergeindex, selectIndex); --symbol2d.attributes.wallendindex; } else if (index1 == 0 && index2 != 1) { --symbol2d.attributes.wallendindex; } else if (index2 == 0 && index1 != 1) { --symbol2d.attributes.wallstartindex; } } else if (mergeindex == 1 || selectIndex == 1) { --symbol2d.attributes.wallstartindex; --symbol2d.attributes.wallendindex; if (symbol2d.attributes.wallstartindex < 0) { symbol2d.attributes.wallstartindex = 0; } if (symbol2d.attributes.wallendindex < 0) { symbol2d.attributes.wallendindex = 0; } } else if (mergeindex != 1 && selectIndex != 1) { if (selectIndex == 0) { if (Math.min(symbol2d.attributes.wallstartindex, symbol2d.attributes.wallendindex) > 0) { --symbol2d.attributes.wallstartindex; --symbol2d.attributes.wallendindex; } else { symbol2d.attributes.wallstartindex = 0; symbol2d.attributes.wallendindex = mergeindex - 1; } } else { if (symbol2d.attributes.wallstartindex == selectIndex) { symbol2d.attributes.wallstartindex = 0; } else if (symbol2d.attributes.wallendindex == selectIndex) { symbol2d.attributes.wallendindex = 0; } } } } }; //9.7 CalculateElement.prototype.updateSymbolsForDeleteOnePoint = function (wallId, index) { var len = this.layer.vectors[wallId].geometry.points.length; for (var key in this.layer.vectors[wallId].symbol2Ds) { var symbol2d = this.layer.vectors[wallId].symbol2Ds[key]; var index1 = symbol2d.attributes.wallstartindex; var index2 = symbol2d.attributes.wallendindex; if (index1 != 0 && index2 != 0) { if (index < Math.min(index1, index2)) { --symbol2d.attributes.wallstartindex; --symbol2d.attributes.wallendindex; } else if (index == index1) { if (index2 > index) { index1 = index - 1; --index2; } } else if (index == index2) { if (index1 > index) { index2 = index - 1; --index1; } } } else if (index1 == 0) { if (index2 != 1) { if (index != 0) { --index2; } } else if (index == 0) { index2 = len - 2; } } else if (index2 == 0) { if (index1 != 1) { if (index != 0) { --index1; } } else if (index == 0) { index1 = len - 2; } } symbol2d.attributes.wallstartindex = index1; symbol2d.attributes.wallendindex = index2; } }; CalculateElement.prototype.updateSelectWallCornerIndex = function (wallId, mergeindex, selectIndex) { if (!this.isNeighbor(len, mergeindex, selectIndex)) { return null; } if (selectIndex > mergeindex) { return mergeindex; } else if (selectIndex == 0) { if (mergeindex != 1) { --mergeindex; return mergeindex; } } return selectIndex; }; CalculateElement.prototype.updateSymbolsIndexAdd = function (wallId, index, point) { var len = this.layer.vectors[wallId].geometry.points.length; var wallindex1 = index - 1; var wallindex2 = index + 1; if (wallindex2 == len) { wallindex2 = 0; } var wallpoint1 = this.layer.vectors[wallId].geometry.points[wallindex1]; var wallpoint2 = this.layer.vectors[wallId].geometry.points[wallindex2]; for (var key in this.layer.vectors[wallId].symbol2Ds) { var symbol2d = this.layer.vectors[wallId].symbol2Ds[key]; var indexs = this.updateIndexAdd(len, index, symbol2d.attributes.wallstartindex, symbol2d.attributes.wallendindex, symbol2d.geometry.points[0], symbol2d.geometry.points[1], point, wallpoint1, wallpoint2); symbol2d.attributes.wallstartindex = indexs.start; symbol2d.attributes.wallendindex = indexs.end; } }; CalculateElement.prototype.updateSymbolEndPoint = function (symbol2d, point, wallid, startinidex, endindex) { if (wallid == null) { return; } var len = symbol2d.getSymbolLen(); var point1, point2; //不能是墙角 if (endindex != null && typeof (endindex) != undefined) { point1 = this.layer.vectors[wallid].geometry.points[startinidex]; point2 = this.layer.vectors[wallid].geometry.points[endindex]; } else if (symbol2d.geometry.points.length > 0) { point1 = symbol2d.geometry.points[0]; point2 = symbol2d.geometry.points[1]; } else { return; } var line = this.calculateLine.createLine(point1, point2); var endpoint = this.calculateLine.getDisPointsLine(line, point, len / 2, len / 2) if (symbol2d.attributes.wallId != wallid) { --this.layer.vectors[symbol2d.attributes.wallId].symbol2dsCount; delete this.layer.vectors[symbol2d.attributes.wallId].symbol2Ds[symbol2d.id]; symbol2d.attributes.wallId = wallid; ++this.layer.vectors[wallid].symbol2dsCount; this.layer.vectors[wallid].symbol2Ds[symbol2d.id] = symbol2d; } symbol2d.attributes.wallstartindex = startinidex; symbol2d.attributes.wallendindex = endindex; symbol2d.geometry.point1 = endpoint.newpoint1; symbol2d.geometry.point2 = endpoint.newpoint2; var thick = this.layer.getThickness(symbol2d.attributes.wallId, symbol2d.attributes.wallstartindex); symbol2d.geometry.points = this.getSymbolPoints(endpoint.newpoint1, endpoint.newpoint2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick) this.layer.vectors[symbol2d.attributes.selectSymbolIds[0]].geometry.points[0] = endpoint.newpoint1; this.layer.vectors[symbol2d.attributes.selectSymbolIds[0]].geometry.points[1] = endpoint.newpoint2; this.layer.vectors[symbol2d.attributes.selectSymbolIds[1]].geometry.x = endpoint.newpoint1.x; this.layer.vectors[symbol2d.attributes.selectSymbolIds[1]].geometry.y = endpoint.newpoint1.y; this.layer.vectors[symbol2d.attributes.selectSymbolIds[2]].geometry.x = endpoint.newpoint2.x; this.layer.vectors[symbol2d.attributes.selectSymbolIds[2]].geometry.y = endpoint.newpoint2.y; //symbol2d.select=true; //symbol2d.draw(this.layer); }; //point在墙上 CalculateElement.prototype.getSymbolEndPoint = function (point, wallid, startinidex, endindex, len) { var point1 = this.layer.vectors[wallid].geometry.points[startinidex]; if (typeof (endindex) == "undefined") { return null; } var point2 = this.layer.vectors[wallid].geometry.points[endindex]; var line = this.calculateLine.createLine(point1, point2); var endpoint = this.calculateLine.getDisPointsLine(line, point, len / 2, len / 2) return endpoint; }; //point不在墙上 CalculateElement.prototype.getSymbolEndPoint2 = function (point, wallid, startinidex, endindex, len) { if (typeof (endindex) == "undefined") { return null; } var point1 = this.layer.vectors[wallid].geometry.points[startinidex]; var point2 = this.layer.vectors[wallid].geometry.points[endindex]; var line = this.calculateLine.createLine(point1, point2); var p = this.calculateLine.getJoinLinePoint(point, line); if (!this.lineContain(point1, point2, p, 1)) { return null; } else if (BABYLON.Vector2.Distance(point1, p) < len / 2 || BABYLON.Vector2.Distance(point2, p) < len / 2) { return null; } else { var endpoint = this.calculateLine.getDisPointsLine(line, p, len / 2, len / 2) return endpoint; } }; //points中,第1,2点表示与point1和point2构成矩形 //扇形都是以point2为圆心 CalculateElement.prototype.getSingleCasementPoints = function (point1, point2, toward, thick) { //singleCasementDrift var calculateLine = this.calculateLine; var line = calculateLine.createLine(point1, point2); var arcpoints = []; var len = BABYLON.Vector2.Distance(point1, point2); var startAngle2, endAngle2; var tempPoint = { x: point2.x + 1, y: point2.y }; if (line.hasOwnProperty('x')) { if (toward == 1) { arcpoints.push({ x: point2.x - this.layer.parameter.singleCasementDrift, y: point2.y }); arcpoints.push({ x: point1.x - this.layer.parameter.singleCasementDrift, y: point1.y }); endAngle2 = calculateLine.Angle2(point2, point1, tempPoint) / 180 * Math.PI; startAngle2 = endAngle2 - Math.PI / 6; } else { arcpoints.push({ x: point2.x + this.layer.parameter.singleCasementDrift, y: point2.y }); arcpoints.push({ x: point1.x + this.layer.parameter.singleCasementDrift, y: point1.y }); startAngle2 = calculateLine.Angle2(point2, point1, tempPoint) / 180 * Math.PI; endAngle2 = startAngle2 + Math.PI / 6; } } else if (line.hasOwnProperty('y')) { if (toward == 1) { arcpoints.push({ x: point2.x, y: point2.y - this.layer.parameter.singleCasementDrift }); arcpoints.push({ x: point1.x, y: point1.y - this.layer.parameter.singleCasementDrift }); startAngle2 = calculateLine.Angle2(point2, point1, tempPoint) / 180 * Math.PI; endAngle2 = startAngle2 + Math.PI / 6; } else { arcpoints.push({ x: point2.x, y: point2.y + this.layer.parameter.singleCasementDrift }); arcpoints.push({ x: point1.x, y: point1.y + this.layer.parameter.singleCasementDrift }); endAngle2 = calculateLine.Angle2(point2, point1, tempPoint) / 180 * Math.PI; startAngle2 = endAngle2 - Math.PI / 6; } } else { var tl = {}; var a = Math.atan(line.a); tl.a = -1 / line.a; var temp_line2 = calculateLine.getLineForPoint(tl, point1); var temp_line1 = calculateLine.getLineForPoint(tl, point2); var p1, p2; var drift = (this.layer.parameter.singleCasementDrift) / Math.cos(a); var same_line; if (toward == 1) { same_line = { a: line.a, b: line.b - drift }; p1 = calculateLine.getIntersectionPoint(temp_line2, same_line); p2 = calculateLine.getIntersectionPoint(temp_line1, same_line); arcpoints.push(p2); arcpoints.push(p1); startAngle2 = calculateLine.Angle2(point2, point1, tempPoint) / 180 * Math.PI; endAngle2 = startAngle2 + Math.PI / 6; } else { same_line = { a: line.a, b: line.b + drift }; p1 = calculateLine.getIntersectionPoint(temp_line2, same_line); p2 = calculateLine.getIntersectionPoint(temp_line1, same_line); arcpoints.push(p2); arcpoints.push(p1); endAngle2 = calculateLine.Angle2(point2, point1, tempPoint) / 180 * Math.PI; startAngle2 = endAngle2 - Math.PI / 6; } } arcpoints.push(startAngle2); arcpoints.push(endAngle2); return arcpoints; }; CalculateElement.prototype.getDoubleCasementPoints = function (point1, point2, toward, thick) { var calculateLine = this.calculateLine; var line = calculateLine.createLine(point1, point2); var arcpoints = []; var len = BABYLON.Vector2.Distance(point1, point2); var midpoint = { x: (point1.x + point2.x) / 2, y: (point1.y + point2.y) / 2 }; var startAngle21, startAngle22, endAngle21, endAngle22; var tempPoint1 = { x: point1.x + 1, y: point1.y }; var tempPoint2 = { x: point2.x + 1, y: point2.y }; if (line.hasOwnProperty('x')) { if (toward == 1) { arcpoints.push({ x: point2.x - this.layer.parameter.singleCasementDrift, y: point2.y }); arcpoints.push({ x: point1.x - this.layer.parameter.singleCasementDrift, y: point1.y }); if (point1.y > point2.y) { endAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; startAngle21 = endAngle21 - Math.PI / 6; startAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI; endAngle22 = startAngle22 + Math.PI / 6; } else { endAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; startAngle21 = endAngle21 - Math.PI / 6; startAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI + Math.PI; endAngle22 = startAngle22 + Math.PI / 6; } } else { arcpoints.push({ x: point2.x + this.layer.parameter.singleCasementDrift, y: point2.y }); arcpoints.push({ x: point1.x + this.layer.parameter.singleCasementDrift, y: point1.y }); if (point1.y > point2.y) { startAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; endAngle21 = startAngle21 + Math.PI / 6; endAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI; startAngle22 = endAngle22 - Math.PI / 6; } else { startAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; endAngle21 = startAngle21 + Math.PI / 6; endAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI + Math.PI; startAngle22 = endAngle22 - Math.PI / 6; } } } else if (line.hasOwnProperty('y')) { if (toward == 1) { arcpoints.push({ x: point2.x, y: point2.y - this.layer.parameter.singleCasementDrift }); arcpoints.push({ x: point1.x, y: point1.y - this.layer.parameter.singleCasementDrift }); if (point1.x > point2.x) { endAngle21 = 2 * Math.PI; startAngle21 = endAngle21 - Math.PI / 6; startAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI; endAngle22 = startAngle22 + Math.PI / 6; } else { startAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; endAngle21 = startAngle21 + Math.PI / 6; endAngle22 = 2 * Math.PI; startAngle22 = endAngle22 - Math.PI / 6; } } else { arcpoints.push({ x: point2.x, y: point2.y + this.layer.parameter.singleCasementDrift }); arcpoints.push({ x: point1.x, y: point1.y + this.layer.parameter.singleCasementDrift }); if (point1.x > point2.x) { startAngle21 = 0; endAngle21 = startAngle21 + Math.PI / 6; endAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI; startAngle22 = endAngle22 - Math.PI / 6; } else { endAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; startAngle21 = endAngle21 - Math.PI / 6; startAngle22 = 0; endAngle22 = startAngle22 + Math.PI / 6; } } } else { var tl = {}; var a = Math.atan(line.a); tl.a = -1 / line.a; var temp_line2 = calculateLine.getLineForPoint(tl, point1); var temp_line1 = calculateLine.getLineForPoint(tl, point2); var temp_midline = calculateLine.getLineForPoint(tl, midpoint); var p1, p2; var drift = (this.layer.parameter.singleCasementDrift) / Math.cos(a); var same_line; if (toward == 1) { same_line = { a: line.a, b: line.b - drift }; p1 = calculateLine.getIntersectionPoint(temp_line2, same_line); p2 = calculateLine.getIntersectionPoint(temp_line1, same_line); arcpoints.push(p2); arcpoints.push(p1); startAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; endAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI; endAngle21 = startAngle21 + Math.PI / 6; startAngle22 = endAngle22 - Math.PI / 6; } else { same_line = { a: line.a, b: line.b + drift }; p1 = calculateLine.getIntersectionPoint(temp_line2, same_line); p2 = calculateLine.getIntersectionPoint(temp_line1, same_line); arcpoints.push(p2); arcpoints.push(p1); endAngle21 = calculateLine.Angle2(point2, point1, tempPoint2) / 180 * Math.PI; startAngle22 = calculateLine.Angle2(point1, point2, tempPoint1) / 180 * Math.PI; startAngle21 = endAngle21 - Math.PI / 6; endAngle22 = startAngle22 + Math.PI / 6; } } arcpoints.push(startAngle21); arcpoints.push(endAngle21); arcpoints.push(startAngle22); arcpoints.push(endAngle22); return arcpoints; }; CalculateElement.prototype.getSimpleDoorPoints = function (point1, point2, toward, thick) { var calculateLine = this.calculateLine; var line = calculateLine.createLine(point1, point2); var arcpoints = []; var doorlength = BABYLON.Vector2.Distance(point1, point2); if (line.hasOwnProperty('x')) { if (toward == 1) { arcpoints.push({ x: point2.x + thick / 2, y: point2.y }); arcpoints.push({ x: point2.x + thick / 2 + doorlength, y: point2.y }); arcpoints.push({ x: point1.x + thick / 2 + doorlength, y: point1.y }); if (point2.y < point1.y) { arcpoints.push({ x: point1.x + thick / 2 + doorlength, y: point1.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x + thick / 2, y: point1.y - this.layer.parameter.simpleDoorDrift }); } else { arcpoints.push({ x: point1.x + thick / 2 + doorlength, y: point1.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x + thick / 2, y: point1.y + this.layer.parameter.simpleDoorDrift }); } arcpoints.push({ x: point1.x + thick / 2, y: point1.y }); } else { arcpoints.push({ x: point2.x - thick / 2, y: point2.y }); arcpoints.push({ x: point2.x - thick / 2 - doorlength, y: point2.y }); arcpoints.push({ x: point1.x - thick / 2 - doorlength, y: point1.y }); if (point2.y < point1.y) { arcpoints.push({ x: point1.x - thick / 2 - doorlength, y: point1.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x - thick / 2, y: point1.y - this.layer.parameter.simpleDoorDrift }); } else { arcpoints.push({ x: point1.x - thick / 2 - doorlength, y: point1.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x - thick / 2, y: point1.y + this.layer.parameter.simpleDoorDrift }); } arcpoints.push({ x: point1.x - thick / 2, y: point1.y }); } } else if (line.hasOwnProperty('y')) { if (toward == 1) { arcpoints.push({ x: point2.x, y: point2.y + thick / 2 }); arcpoints.push({ x: point2.x, y: point2.y + thick / 2 + doorlength }); arcpoints.push({ x: point1.x, y: point1.y + thick / 2 + doorlength }); if (point2.x < point1.x) { arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 + doorlength }); arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 }); } else { arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 + doorlength }); arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 }); } arcpoints.push({ x: point1.x, y: point1.y + thick / 2 }); } else { arcpoints.push({ x: point2.x, y: point2.y - thick / 2 }); arcpoints.push({ x: point2.x, y: point2.y - thick / 2 - doorlength }); arcpoints.push({ x: point1.x, y: point1.y - thick / 2 - doorlength }); if (point2.x < point1.x) { arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 - doorlength }); arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 }); } else { arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 - doorlength }); arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 }); } arcpoints.push({ x: point1.x, y: point1.y - thick / 2 }); } } else { var tl = {}; var a = Math.atan(line.a); tl.a = -1 / line.a; var temp_line2 = calculateLine.getLineForPoint(tl, point1); var temp_line1 = calculateLine.getLineForPoint(tl, point2); var p1, p2, p3, p4, p5, p6; var temp_line3 = {}; var db = doorlength / Math.cos(a); var drift = (thick / 2) / Math.cos(a); var same_line1, same_line2; if (toward == 1) { same_line1 = { a: line.a, b: line.b + drift }; same_line2 = { a: line.a, b: line.b + drift + db }; p1 = calculateLine.getIntersectionPoint(temp_line1, same_line1); p2 = calculateLine.getIntersectionPoint(temp_line1, same_line2); p3 = calculateLine.getIntersectionPoint(temp_line2, same_line2); if (temp_line2.b < temp_line1.b) { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b + Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); p4 = calculateLine.getIntersectionPoint(temp_line3, same_line2); p5 = calculateLine.getIntersectionPoint(temp_line3, same_line1); } else { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b - Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); p4 = calculateLine.getIntersectionPoint(temp_line3, same_line2); p5 = calculateLine.getIntersectionPoint(temp_line3, same_line1); } p6 = calculateLine.getIntersectionPoint(temp_line2, same_line1); } else { same_line1 = { a: line.a, b: line.b - drift }; same_line2 = { a: line.a, b: line.b - drift - db }; p1 = calculateLine.getIntersectionPoint(temp_line1, same_line1); p2 = calculateLine.getIntersectionPoint(temp_line1, same_line2); p3 = calculateLine.getIntersectionPoint(temp_line2, same_line2); if (temp_line2.b < temp_line1.b) { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b + Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); p4 = calculateLine.getIntersectionPoint(temp_line3, same_line2); p5 = calculateLine.getIntersectionPoint(temp_line3, same_line1); } else { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b - Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); p4 = calculateLine.getIntersectionPoint(temp_line3, same_line2); p5 = calculateLine.getIntersectionPoint(temp_line3, same_line1); } p6 = calculateLine.getIntersectionPoint(temp_line2, same_line1); } arcpoints.push(p1); arcpoints.push(p2); arcpoints.push(p3); arcpoints.push(p4); arcpoints.push(p5); arcpoints.push(p6); } return arcpoints; }; CalculateElement.prototype.getBiFoldDoorPoints = function (point1, point2, toward, thick) { var calculateLine = this.calculateLine; var line = calculateLine.createLine(point1, point2); var arcpoints = []; var doorlength = BABYLON.Vector2.Distance(point1, point2) / 2; var midpoint = { x: (point1.x + point2.x) / 2, y: (point1.y + point2.y) / 2 }; if (line.hasOwnProperty('x')) { if (toward == 1) { arcpoints.push({ x: midpoint.x + thick / 2, y: midpoint.y }); arcpoints.push({ x: midpoint.x + thick / 2 + doorlength, y: midpoint.y }); arcpoints.push({ x: point2.x + thick / 2 + doorlength, y: point2.y }); arcpoints.push({ x: midpoint.x + thick / 2, y: midpoint.y }); arcpoints.push({ x: midpoint.x + thick / 2 + doorlength, y: midpoint.y }); arcpoints.push({ x: point1.x + thick / 2 + doorlength, y: point1.y }); if (point2.y < point1.y) { arcpoints.push({ x: point2.x + thick / 2 + doorlength, y: point2.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x + thick / 2, y: point2.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x + thick / 2, y: point2.y }); arcpoints.push({ x: point1.x + thick / 2 + doorlength, y: point1.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x + thick / 2, y: point1.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x + thick / 2, y: point1.y }); } else { arcpoints.push({ x: point2.x + thick / 2 + doorlength, y: point2.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x + thick / 2, y: point2.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x + thick / 2, y: point2.y }); arcpoints.push({ x: point1.x + thick / 2 + doorlength, y: point1.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x + thick / 2, y: point1.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x + thick / 2, y: point1.y }); } } else { arcpoints.push({ x: midpoint.x - thick / 2, y: midpoint.y }); arcpoints.push({ x: midpoint.x - thick / 2 - doorlength, y: midpoint.y }); arcpoints.push({ x: point2.x - thick / 2 - doorlength, y: point2.y }); arcpoints.push({ x: midpoint.x - thick / 2, y: midpoint.y }); arcpoints.push({ x: midpoint.x - thick / 2 - doorlength, y: midpoint.y }); arcpoints.push({ x: point1.x - thick / 2 - doorlength, y: point1.y }); if (point2.y < point1.y) { arcpoints.push({ x: point2.x - thick / 2 - doorlength, y: point2.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x - thick / 2, y: point2.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x - thick / 2, y: point2.y }); arcpoints.push({ x: point1.x - thick / 2 - doorlength, y: point1.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x - thick / 2, y: point1.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x - thick / 2, y: point1.y }); } else { arcpoints.push({ x: point2.x - thick / 2 - doorlength, y: point2.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x - thick / 2, y: point2.y - this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point2.x - thick / 2, y: point2.y }); arcpoints.push({ x: point1.x - thick / 2 - doorlength, y: point1.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x - thick / 2, y: point1.y + this.layer.parameter.simpleDoorDrift }); arcpoints.push({ x: point1.x - thick / 2, y: point1.y }); } } } else if (line.hasOwnProperty('y')) { if (toward == 1) { arcpoints.push({ x: midpoint.x, y: midpoint.y + thick / 2 }); arcpoints.push({ x: midpoint.x, y: midpoint.y + thick / 2 + doorlength }); arcpoints.push({ x: point2.x, y: point2.y + thick / 2 + doorlength }); arcpoints.push({ x: midpoint.x, y: midpoint.y + thick / 2 }); arcpoints.push({ x: midpoint.x, y: midpoint.y + thick / 2 + doorlength }); arcpoints.push({ x: point1.x, y: point1.y + thick / 2 + doorlength }); if (point2.x < point1.x) { arcpoints.push({ x: point2.x + this.layer.parameter.simpleDoorDrift, y: point2.y + thick / 2 + doorlength }); arcpoints.push({ x: point2.x + this.layer.parameter.simpleDoorDrift, y: point2.y + thick / 2 }); arcpoints.push({ x: point2.x, y: point2.y + thick / 2 }); arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 + doorlength }); arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 }); arcpoints.push({ x: point1.x, y: point1.y + thick / 2 }); } else { arcpoints.push({ x: point2.x - this.layer.parameter.simpleDoorDrift, y: point2.y + thick / 2 + doorlength }); arcpoints.push({ x: point2.x - this.layer.parameter.simpleDoorDrift, y: point2.y + thick / 2 }); arcpoints.push({ x: point2.x, y: point2.y + thick / 2 }); arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 + doorlength }); arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y + thick / 2 }); arcpoints.push({ x: point1.x, y: point1.y + thick / 2 }); } } else { arcpoints.push({ x: midpoint.x, y: midpoint.y - thick / 2 }); arcpoints.push({ x: midpoint.x, y: midpoint.y - thick / 2 - doorlength }); arcpoints.push({ x: point2.x, y: point2.y - thick / 2 - doorlength }); arcpoints.push({ x: midpoint.x, y: midpoint.y - thick / 2 }); arcpoints.push({ x: midpoint.x, y: midpoint.y - thick / 2 - doorlength }); arcpoints.push({ x: point1.x, y: point1.y - thick / 2 - doorlength }); if (point2.y < point1.y) { arcpoints.push({ x: point2.x + this.layer.parameter.simpleDoorDrift, y: point2.y - thick / 2 - doorlength }); arcpoints.push({ x: point2.x + this.layer.parameter.simpleDoorDrift, y: point2.y - thick / 2 }); arcpoints.push({ x: point2.x, y: point2.y - thick / 2 }); arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 - doorlength }); arcpoints.push({ x: point1.x - this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 }); arcpoints.push({ x: point1.x, y: point1.y - thick / 2 }); } else { arcpoints.push({ x: point2.x - this.layer.parameter.simpleDoorDrift, y: point2.y - thick / 2 - doorlength }); arcpoints.push({ x: point2.x - this.layer.parameter.simpleDoorDrift, y: point2.y - thick / 2 }); arcpoints.push({ x: point2.x, y: point2.y - thick / 2 }); arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 - doorlength }); arcpoints.push({ x: point1.x + this.layer.parameter.simpleDoorDrift, y: point1.y - thick / 2 }); arcpoints.push({ x: point1.x, y: point1.y - thick / 2 }); } } } else { var tl = {}; var a = Math.atan(line.a); tl.a = -1 / line.a; var temp_line1 = calculateLine.getLineForPoint(tl, point1); var temp_line2 = calculateLine.getLineForPoint(tl, point2); var temp_midline = calculateLine.getLineForPoint(tl, midpoint); var t1, t2, t3, t4, t5, t6; var p1, p2, p3, p4, p5, p6; var temp_line3 = {}; var temp_line4 = {}; var db = doorlength / Math.cos(a); var drift = (thick / 2) / Math.cos(a); var same_line1, same_line2; if (toward == 1) { same_line1 = { a: line.a, b: line.b + drift }; same_line2 = { a: line.a, b: line.b + drift + db }; t1 = calculateLine.getIntersectionPoint(temp_midline, same_line1); t2 = calculateLine.getIntersectionPoint(temp_midline, same_line2); t3 = calculateLine.getIntersectionPoint(temp_line2, same_line2); t4 = calculateLine.getIntersectionPoint(temp_midline, same_line1); t5 = calculateLine.getIntersectionPoint(temp_midline, same_line2); t6 = calculateLine.getIntersectionPoint(temp_line1, same_line2); if (temp_line2.b < temp_line1.b) { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b + Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); temp_line4.a = temp_line1.a; temp_line4.b = temp_line1.b - Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); } else { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b - Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); temp_line4.a = temp_line1.a; temp_line4.b = temp_line1.b + Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); } p1 = calculateLine.getIntersectionPoint(temp_line3, same_line2); p2 = calculateLine.getIntersectionPoint(temp_line3, same_line1); p3 = calculateLine.getIntersectionPoint(temp_line2, same_line1); p4 = calculateLine.getIntersectionPoint(temp_line4, same_line2); p5 = calculateLine.getIntersectionPoint(temp_line4, same_line1); p6 = calculateLine.getIntersectionPoint(temp_line1, same_line1); } else { same_line1 = { a: line.a, b: line.b - drift }; same_line2 = { a: line.a, b: line.b - drift - db }; t1 = calculateLine.getIntersectionPoint(temp_midline, same_line1); t2 = calculateLine.getIntersectionPoint(temp_midline, same_line2); t3 = calculateLine.getIntersectionPoint(temp_line2, same_line2); t4 = calculateLine.getIntersectionPoint(temp_midline, same_line1); t5 = calculateLine.getIntersectionPoint(temp_midline, same_line2); t6 = calculateLine.getIntersectionPoint(temp_line1, same_line2); if (temp_line2.b < temp_line1.b) { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b + Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); temp_line4.a = temp_line1.a; temp_line4.b = temp_line1.b - Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); } else { temp_line3.a = temp_line1.a; temp_line3.b = temp_line2.b - Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); temp_line4.a = temp_line1.a; temp_line4.b = temp_line1.b + Math.abs(this.layer.parameter.simpleDoorDrift / Math.sin(a)); } p1 = calculateLine.getIntersectionPoint(temp_line3, same_line2); p2 = calculateLine.getIntersectionPoint(temp_line3, same_line1); p3 = calculateLine.getIntersectionPoint(temp_line2, same_line1); p4 = calculateLine.getIntersectionPoint(temp_line4, same_line2); p5 = calculateLine.getIntersectionPoint(temp_line4, same_line1); p6 = calculateLine.getIntersectionPoint(temp_line1, same_line1); } arcpoints.push(t1); arcpoints.push(t2); arcpoints.push(t3); arcpoints.push(t4); arcpoints.push(t5); arcpoints.push(t6); arcpoints.push(p1); arcpoints.push(p2); arcpoints.push(p3); arcpoints.push(p4); arcpoints.push(p5); arcpoints.push(p6); } return arcpoints; }; CalculateElement.prototype.getSlidingPoints = function (point1, point2, toward, thick) { var calculateLine = this.layer.calculateLine; var line = calculateLine.createLine(point1, point2); var drawpoints = []; var point3, point4, point5, point6; var r = 10; if (line.hasOwnProperty('x')) { point3 = { x: point1.x - r, y: point1.y }; point4 = { x: point1.x - r, y: (point1.y + point2.y) / 2 }; point5 = { x: point1.x + r, y: (point1.y + point2.y) / 2 }; point6 = { x: point1.x + r, y: point2.y }; } else if (line.hasOwnProperty('y')) { point3 = { x: point1.x, y: point1.y - r }; point4 = { x: (point1.x + point2.x) / 2, y: point1.y - r }; point5 = { x: (point1.x + point2.x) / 2, y: point1.y + r }; point6 = { x: point2.x, y: point2.y + r }; } else { var tl = {}; var a = Math.atan(line.a); tl.a = -1 / line.a; var temp_line1 = calculateLine.createLine2(tl, point1); var temp_line2 = calculateLine.createLine2(tl, point2); var centerpoint = { x: (point1.x + point2.x) / 2, y: (point1.y + point2.y) / 2 }; var tempcenterline = calculateLine.createLine2(tl, centerpoint); var db = r / Math.cos(a); var like_line1 = { a: line.a, b: line.b + db }; var like_line2 = { a: line.a, b: line.b - db }; point3 = calculateLine.getIntersectionPoint(like_line1, temp_line1); point4 = calculateLine.getIntersectionPoint(like_line1, tempcenterline); point5 = calculateLine.getIntersectionPoint(like_line2, tempcenterline); point6 = calculateLine.getIntersectionPoint(like_line2, temp_line2); } drawpoints.push(point1); drawpoints.push(point2); drawpoints.push(point3); drawpoints.push(point4); drawpoints.push(point5); drawpoints.push(point6); return drawpoints; }; CalculateElement.prototype.getSymbolPoints = function (point1, point2, type, toward, thick) { var points = []; if (type == "OpenDoor" || type == "OpenWindow") { points.push(point1); points.push(point2); } else if (type == "SimpleDoor") { points = this.getSimpleDoorPoints(point1, point2, toward, thick); } else if (type == "BiFoldDoor") { points = this.getBiFoldDoorPoints(point1, point2, toward, thick); } else if (type == "SlidingDoor" || type == "SlidingWindow") { points = this.getSlidingPoints(point1, point2, toward, thick); } else if (type == "SingleCasement") { points = this.getSingleCasementPoints(point1, point2, toward, thick); } else if (type == "DoubleCasement") { points = this.getDoubleCasementPoints(point1, point2, toward, thick); } return points; };