unit.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import Model from '../model'
  7. import Operator from './operator'
  8. interface Unit extends Readonly<{
  9. // Structure-level unique identifier of the unit.
  10. id: number,
  11. // Provides access to the underlying data.
  12. model: Model,
  13. // Determines the operation applied to this unit.
  14. // The transform and and inverse are baked into the "getPosition" function
  15. operator: Operator,
  16. // Cache residue and chain indices for fast access.
  17. residueIndex: ArrayLike<number>,
  18. chainIndex: ArrayLike<number>
  19. }> {
  20. // // returns the untransformed position. Used for spatial queries.
  21. // getInvariantPosition(atom: number, slot: Vec3): Vec3
  22. // // gets the transformed position of the specified atom
  23. // getPosition(atom: number, slot: Vec3): Vec3
  24. }
  25. namespace Unit {
  26. export function create(model: Model, operator: Operator): Unit {
  27. const h = model.hierarchy;
  28. return { id: nextUnitId(), model, operator, residueIndex: h.residueSegments.segmentMap, chainIndex: h.chainSegments.segmentMap };
  29. }
  30. }
  31. export default Unit;
  32. let _id = 0;
  33. function nextUnitId() {
  34. const ret = _id;
  35. _id = (_id + 1) % 0x3fffffff;
  36. return ret;
  37. }