Архитектурный шаблон "Мрак в моделях" на нескольких языках и платформах
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
678B

  1. protocol Context {
  2. var itemsCount: Float { get }
  3. }
  4. protocol Position {
  5. var x: Float { get }
  6. var y: Float { get }
  7. }
  8. func memoryGap() -> Float {
  9. return memorySide() + memorySpace()
  10. }
  11. func memorySide() -> Float {
  12. return 50
  13. }
  14. func memorySpace() -> Float {
  15. return 20
  16. }
  17. func memoryItemPositions(c: Context) -> [Position] {
  18. var pos: [Position] = []
  19. let ids = Array.from(Array(c.itemsCount).keys());
  20. ids.forEach(i => {
  21. let row = Math.floor(i / 4)
  22. let x = memoryGap() + (i - row * 4) * memoryGap()
  23. let y = memoryGap() + row * memoryGap()
  24. // @ts-ignore
  25. pos.push(memoryCreatePosition(x, y))
  26. })
  27. return pos
  28. }