state.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { cloneDeep } from 'lodash'
  2. import Spline from 'cubic-spline-ts'
  3. export interface layer {
  4. layerWidth: number
  5. materialName: string
  6. n: number
  7. k: number
  8. nSpline: Spline|undefined
  9. kSpline: Spline|undefined
  10. }
  11. export interface simulationSetup {
  12. hostIndex: number
  13. fromWL: number; toWL:number; pointsWL:number
  14. layers: layer[]
  15. }
  16. export interface simulationSetupStateInterface {
  17. library: Map<string,simulationSetup>
  18. gui: simulationSetup
  19. current: simulationSetup
  20. }
  21. function setupFactory(hostIndex = 1,
  22. fromWL = 300, toWL=1000, pointsWL=101,
  23. layers = [
  24. {layerWidth:100, n:4, k:0.01, materialName:'nk',
  25. nSpline:undefined, kSpline:undefined
  26. },
  27. ]
  28. ):simulationSetup {
  29. return {hostIndex:hostIndex,
  30. fromWL:fromWL, toWL:toWL, pointsWL:pointsWL,
  31. layers: cloneDeep(layers)}
  32. }
  33. function state(): simulationSetupStateInterface {
  34. const gui = setupFactory()
  35. const current = cloneDeep(gui)
  36. const library = new Map<string,simulationSetup>()
  37. library.set('default', cloneDeep(gui))
  38. return {
  39. library,
  40. gui,
  41. current
  42. }
  43. };
  44. export default state;