location.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. /** A null value Location */
  11. export const NullLocation = { kind: 'null-location' as const };
  12. export type NullLocation = typeof NullLocation
  13. export function isNullLocation(x: any): x is NullLocation {
  14. return !!x && x.kind === 'null-location';
  15. }
  16. /** A generic data Location */
  17. export interface DataLocation<T = unknown, E = unknown> {
  18. readonly kind: 'data-location',
  19. readonly tag: string
  20. readonly data: T,
  21. element: E
  22. }
  23. export function DataLocation<T = unknown, E = unknown>(tag: string, data: T, element: E): DataLocation<T, E> {
  24. return { kind: 'data-location', tag, data, element };
  25. }
  26. export function isDataLocation(x: any): x is DataLocation {
  27. return !!x && x.kind === 'data-location';
  28. }
  29. export type Location = StructureElement.Location | Bond.Location | ShapeGroup.Location | PositionLocation | DataLocation | NullLocation