location.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { StructureElement } from './structure';
  7. import { Bond } from './structure/structure/unit/bonds';
  8. import { ShapeGroup } from './shape/shape';
  9. import { PositionLocation } from '../mol-geo/util/location-iterator';
  10. import { Volume } from './volume';
  11. /** A null value Location */
  12. export const NullLocation = { kind: 'null-location' as const };
  13. export type NullLocation = typeof NullLocation
  14. export function isNullLocation(x: any): x is NullLocation {
  15. return !!x && x.kind === 'null-location';
  16. }
  17. /** A generic data Location */
  18. export interface DataLocation<T = unknown, E = unknown> {
  19. readonly kind: 'data-location',
  20. readonly tag: string
  21. readonly data: T,
  22. element: E
  23. }
  24. export function DataLocation<T = unknown, E = unknown>(tag: string, data: T, element: E): DataLocation<T, E> {
  25. return { kind: 'data-location', tag, data, element };
  26. }
  27. export function isDataLocation(x: any): x is DataLocation {
  28. return !!x && x.kind === 'data-location';
  29. }
  30. export type Location = StructureElement.Location | Bond.Location | ShapeGroup.Location | PositionLocation | DataLocation | NullLocation | Volume.Segment.Location