awv3
Version:
⚡ AWV3 embedded CAD
92 lines (71 loc) • 3.17 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import * as THREE from 'three';
import BaseGraphics from './base';
function closestAngle(value, to) {
var pi2 = 2 * Math.PI;
while (Math.abs(value - pi2 - to) < Math.abs(value - to)) {
value -= pi2;
}
while (Math.abs(value + pi2 - to) < Math.abs(value - to)) {
value += pi2;
}
return value;
}
var Angular =
/*#__PURE__*/
function (_BaseGraphics) {
_inheritsLoose(Angular, _BaseGraphics);
function Angular() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _BaseGraphics.call.apply(_BaseGraphics, [this].concat(args, [2, 2, 2])) || this;
}
var _proto = Angular.prototype;
_proto.updateFromState = function updateFromState(info) {
var _BaseGraphics$prototy;
//take local coordinates of four points from CC data members
var _map = ['startPt', 'endPt', 'dimPt', 'cornerPt'].map(function (x) {
return new THREE.Vector3().fromArray(info.dimension.members[x].value);
}),
start = _map[0],
end = _map[1],
dim = _map[2],
corner = _map[3];
var extendCrn = info.dimension.members.extendToCorner.value; //calculate radius & polar angles of the arc
var radius = corner.distanceTo(dim);
var startAng = Math.atan2(start.y - corner.y, start.x - corner.x),
endAng = Math.atan2(end.y - corner.y, end.x - corner.x); //arc always goes from "start" to "end" according to "ccw" flag
if (!info.dimension.members.ccw.value) {
var _ref = [end, start, endAng, startAng];
start = _ref[0];
end = _ref[1];
startAng = _ref[2];
endAng = _ref[3];
}
if (endAng < startAng) endAng += 2 * Math.PI; //check if dim-pos is outside of sector
var midAng = (startAng + endAng) * 0.5;
var dimAng = Math.atan2(dim.y - corner.y, dim.x - corner.x);
dimAng = closestAngle(dimAng, midAng);
var outside = dimAng < startAng || dimAng > endAng; //set geometry for dimension
var _map2 = [start, end].map(function (x) {
return x.clone().sub(corner).setLength(radius).add(corner);
}),
startFoot = _map2[0],
endFoot = _map2[1];
var startTang = new THREE.Vector3(Math.sin(startAng), -Math.cos(startAng), 0).multiplyScalar(outside ? -1 : 1);
var endTang = new THREE.Vector3(-Math.sin(endAng), Math.cos(endAng), 0).multiplyScalar(outside ? -1 : 1);
this.updateLine(0, extendCrn ? corner : start, startFoot);
this.updateLine(1, endFoot, extendCrn ? corner : end);
this.updateArc(0, corner, radius, startAng, dimAng);
this.updateArc(1, corner, radius, endAng, dimAng);
this.updateArrow(0, startFoot, startTang);
this.updateArrow(1, endFoot, endTang);
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_BaseGraphics$prototy = _BaseGraphics.prototype.updateFromState).call.apply(_BaseGraphics$prototy, [this, info].concat(args));
};
return Angular;
}(BaseGraphics);
export { Angular as default };