UNPKG

molstar

Version:

A comprehensive macromolecular library.

91 lines 3.62 kB
"use strict"; /** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isPositionLocation = exports.PositionLocation = exports.LocationIterator = void 0; var linear_algebra_1 = require("../../mol-math/linear-algebra"); var location_1 = require("../../mol-model/location"); function LocationIterator(groupCount, instanceCount, stride, getLocation, nonInstanceable, isSecondary) { if (nonInstanceable === void 0) { nonInstanceable = false; } if (isSecondary === void 0) { isSecondary = function () { return false; }; } if (groupCount % stride !== 0) { throw new Error('incompatible groupCount and stride'); } var value = { location: location_1.NullLocation, index: 0, groupIndex: 0, instanceIndex: 0, isSecondary: false }; var hasNext = value.groupIndex < groupCount; var isNextNewInstance = false; var groupIndex = 0; var instanceIndex = 0; var voidInstances = false; return { get hasNext() { return hasNext; }, get isNextNewInstance() { return isNextNewInstance; }, groupCount: groupCount, instanceCount: instanceCount, count: groupCount * instanceCount, stride: stride, nonInstanceable: nonInstanceable, move: function () { if (hasNext) { value.groupIndex = groupIndex; value.instanceIndex = instanceIndex; value.index = instanceIndex * groupCount + groupIndex; value.location = getLocation(groupIndex, voidInstances ? -1 : instanceIndex); value.isSecondary = isSecondary(groupIndex, voidInstances ? -1 : instanceIndex); groupIndex += stride; if (groupIndex === groupCount) { ++instanceIndex; isNextNewInstance = true; if (instanceIndex < instanceCount) groupIndex = 0; } else { isNextNewInstance = false; } hasNext = groupIndex < groupCount; } return value; }, reset: function () { value.location = location_1.NullLocation; value.index = 0; value.groupIndex = 0; value.instanceIndex = 0; value.isSecondary = false; hasNext = value.groupIndex < groupCount; isNextNewInstance = false; groupIndex = 0; instanceIndex = 0; voidInstances = false; }, skipInstance: function () { if (hasNext && value.instanceIndex === instanceIndex) { ++instanceIndex; groupIndex = 0; hasNext = instanceIndex < instanceCount; } }, voidInstances: function () { voidInstances = true; } }; } exports.LocationIterator = LocationIterator; function PositionLocation(position) { return { kind: 'position-location', position: position ? linear_algebra_1.Vec3.clone(position) : (0, linear_algebra_1.Vec3)() }; } exports.PositionLocation = PositionLocation; function isPositionLocation(x) { return !!x && x.kind === 'position-location'; } exports.isPositionLocation = isPositionLocation; //# sourceMappingURL=location-iterator.js.map