Skip to content
Snippets Groups Projects
Unverified Commit bdb42e39 authored by Alexander Rose's avatar Alexander Rose Committed by GitHub
Browse files

Merge pull request #809 from giagitom/principal-axis-spec

Adding principal axes spec
parents 198f884d 6edd54ee
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ Note that since we don't clearly distinguish between a public and private interf
## [Unreleased]
- Add principal axes spec and fix edge cases
- Add a uniform color theme for NtC tube that still paints residue and segment dividers in a different color
- Mesh exporter improvements
- Support points & lines in glTF export
......
/**
* Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2017-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
......@@ -24,6 +24,8 @@ import { Mat3 } from './mat3';
import { Quat } from './quat';
import { EPSILON } from './common';
const _isFinite = isFinite;
export { ReadonlyVec3 };
interface Vec3 extends Array<number> { [d: number]: number, '@type': 'vec3', length: 3 }
......@@ -48,6 +50,10 @@ namespace Vec3 {
return out;
}
export function isFinite(a: Vec3): boolean {
return _isFinite(a[0]) && _isFinite(a[1]) && _isFinite(a[2]);
}
export function hasNaN(a: Vec3) {
return isNaN(a[0]) || isNaN(a[1]) || isNaN(a[2]);
}
......
/**
* Copyright (c) 2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Gianluca Tomasello <giagitom@gmail.com>
*/
import { NumberArray } from '../../../mol-util/type-helpers';
import { PrincipalAxes } from '../matrix/principal-axes';
describe('PrincipalAxes', () => {
it('same-cartesian-plane', () => {
const positions: NumberArray = [ // same y coordinate
0.1945, -0.0219, -0.0416,
-0.0219, -0.0219, -0.0119,
];
const { origin } = PrincipalAxes.ofPositions(positions).boxAxes;
expect(origin[0] !== Infinity && origin[1] !== Infinity && origin[2] !== Infinity).toBe(true);
});
});
/**
* Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Gianluca Tomasello <giagitom@gmail.com>
*/
import { Matrix } from './matrix';
......@@ -123,12 +124,17 @@ namespace PrincipalAxes {
const dirB = Vec3.setMagnitude(Vec3(), a.dirB, (d2a + d2b) / 2);
const dirC = Vec3.setMagnitude(Vec3(), a.dirC, (d3a + d3b) / 2);
const okDirA = Vec3.isFinite(dirA);
const okDirB = Vec3.isFinite(dirB);
const okDirC = Vec3.isFinite(dirC);
const origin = Vec3();
const addCornerHelper = function (d1: number, d2: number, d3: number) {
Vec3.copy(tmpBoxVec, center);
Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirA, d1);
Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirB, d2);
Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirC, d3);
if (okDirA) Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirA, d1);
if (okDirB) Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirB, d2);
if (okDirC) Vec3.scaleAndAdd(tmpBoxVec, tmpBoxVec, a.dirC, d3);
Vec3.add(origin, origin, tmpBoxVec);
};
addCornerHelper(d1a, d2a, d3a);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment