transparency.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Loci, EmptyLoci } from '../mol-model/loci';
  7. import { StructureElement, Structure } from '../mol-model/structure';
  8. import { Script } from '../mol-script/script';
  9. export { Transparency }
  10. interface Transparency {
  11. readonly loci: Loci
  12. readonly value: number
  13. readonly variant: Transparency.Variant
  14. }
  15. namespace Transparency {
  16. export type Variant = 'single' | 'multi'
  17. export const Empty: Transparency = { loci: EmptyLoci, value: 0, variant: 'single' }
  18. export function areEqual(tA: Transparency, tB: Transparency) {
  19. if (tA.value !== tB.value) return false
  20. if (tA.variant !== tB.variant) return false
  21. if (!Loci.areEqual(tA.loci, tB.loci)) return false
  22. return true
  23. }
  24. export function ofScript(script: Script, value: number, variant: Transparency.Variant, structure: Structure): Transparency {
  25. return { loci: Script.toLoci(script, structure), value, variant }
  26. }
  27. export function ofBundle(bundle: StructureElement.Bundle, value: number, variant: Transparency.Variant, structure: Structure): Transparency {
  28. return { loci: StructureElement.Bundle.toLoci(bundle, structure), value, variant }
  29. }
  30. }