Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private static _getMatrixFace = (rotMatrix: Matrix3d): Face => {
if (!CubeNavigationAid._isMatrixFace(rotMatrix)) {
return Face.None;
}
for (const face in cubeNavigationFaceRotations) {
// istanbul ignore else
if (face in cubeNavigationFaceRotations) {
const loc = cubeNavigationFaceRotations[face];
if (rotMatrix.isAlmostEqual(loc)) {
return face as Face;
}
}
}
// matrix is in a non-standard rotation of face
return Face.None;
}
private _handleViewRotationChangeEvent = (args: ViewRotationChangeEventArgs) => {
const { animation, dragging, endRotMatrix } = this.state;
const activeContentControl = this.props.contentControlOverride !== undefined ? this.props.contentControlOverride : /* istanbul ignore next */ ContentViewManager.getActiveContentControl();
// istanbul ignore else
if (activeContentControl && activeContentControl.isViewport && activeContentControl.viewport === args.viewport && animation >= 1 && !dragging) {
const newMatrix = activeContentControl.viewport.view.getRotation().clone();
if (!endRotMatrix.isAlmostEqual(newMatrix)) {
this.setState({ startRotMatrix: newMatrix, endRotMatrix: newMatrix, animation: 1, face: Face.None });
}
}
}
public static faceCellToPos = (face: Face, x: number, y: number) => {
const faceVect = cubeNavigationFaceLocs[face];
const route = cubeNavigationRoutes[face];
const faceX = x < 0 ? route.left : x > 0 ? route.right : Face.None;
const xVect = faceX !== Face.None ? cubeNavigationFaceLocs[faceX] : Vector3d.createZero();
const faceY = y < 0 ? route.up : y > 0 ? route.down : Face.None;
const yVect = faceY !== Face.None ? cubeNavigationFaceLocs[faceY] : Vector3d.createZero();
return faceVect.plus(xVect).plus(yVect);
}
}
public static faceCellToPos = (face: Face, x: number, y: number) => {
const faceVect = cubeNavigationFaceLocs[face];
const route = cubeNavigationRoutes[face];
const faceX = x < 0 ? route.left : x > 0 ? route.right : Face.None;
const xVect = faceX !== Face.None ? cubeNavigationFaceLocs[faceX] : Vector3d.createZero();
const faceY = y < 0 ? route.up : y > 0 ? route.down : Face.None;
const yVect = faceY !== Face.None ? cubeNavigationFaceLocs[faceY] : Vector3d.createZero();
return faceVect.plus(xVect).plus(yVect);
}
}
public static faceCellToPos = (face: Face, x: number, y: number) => {
const faceVect = cubeNavigationFaceLocs[face];
const route = cubeNavigationRoutes[face];
const faceX = x < 0 ? route.left : x > 0 ? route.right : Face.None;
const xVect = faceX !== Face.None ? cubeNavigationFaceLocs[faceX] : Vector3d.createZero();
const faceY = y < 0 ? route.up : y > 0 ? route.down : Face.None;
const yVect = faceY !== Face.None ? cubeNavigationFaceLocs[faceY] : Vector3d.createZero();
return faceVect.plus(xVect).plus(yVect);
}
}
public static faceCellToPos = (face: Face, x: number, y: number) => {
const faceVect = cubeNavigationFaceLocs[face];
const route = cubeNavigationRoutes[face];
const faceX = x < 0 ? route.left : x > 0 ? route.right : Face.None;
const xVect = faceX !== Face.None ? cubeNavigationFaceLocs[faceX] : Vector3d.createZero();
const faceY = y < 0 ? route.up : y > 0 ? route.down : Face.None;
const yVect = faceY !== Face.None ? cubeNavigationFaceLocs[faceY] : Vector3d.createZero();
return faceVect.plus(xVect).plus(yVect);
}
}
public static initialize() {
if (undefined !== this._removeListener)
return;
this._removeListener = IModelApp.viewManager.onSelectedViewportChanged.addListener(ViewportComponentEvents.handleSelectedViewportChanged);
}
/** @internal - for unit testing */
public static terminate() {
if (this._removeListener) {
this._removeListener();
this._removeListener = undefined;
}
}
public static face = Face.None;
public static readonly origin = Point3d.createZero();
public static readonly extents = Vector3d.createZero();
public static readonly rotationMatrix = Matrix3d.createIdentity();
public static readonly onDrawingViewportChangeEvent = new DrawingViewportChangeEvent();
public static readonly onCubeRotationChangeEvent = new CubeRotationChangeEvent();
public static readonly onStandardRotationChangeEvent = new StandardRotationChangeEvent();
public static readonly onViewRotationChangeEvent = new ViewRotationChangeEvent();
public static readonly onViewClassFullNameChangedEvent = new ViewClassFullNameChangedEvent();
public static readonly onViewIdChangedEvent = new ViewIdChangedEvent();
private static handleSelectedViewportChanged(args: SelectedViewportChangedArgs): void {
if (args.current)
ViewportComponentEvents.setViewMatrix(args.current);
}
public static setCubeMatrix(rotMatrix: Matrix3d, face = Face.None, complete: boolean = false): void {
private _handleMouseUp = (event: React.MouseEvent) => {
const { vector, face } = this.props;
const { clientX, clientY } = event;
this.props.onFaceCellHoverChange(vector, CubeHover.None);
const mouse = Point2d.create(clientX, clientY);
if (this._startMouse && this._startMouse.isAlmostEqual(mouse)) {
const isFace = Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z) === 1;
this.props.onFaceCellClick(vector, isFace ? face : Face.None);
}
}
}