tgraph.nim 570 B

1234567891011121314151617181920212223242526272829303132333435
  1. # bug #3452
  2. import math
  3. type
  4. Node* = concept n
  5. `==`(n, n) is bool
  6. Graph1* = concept g
  7. type N = Node
  8. distance(g, N, N) is float
  9. Graph2 = concept g
  10. distance(g, Node, Node) is float
  11. Graph3 = concept g
  12. var x: Node
  13. distance(g, x, x) is float
  14. XY* = tuple[x, y: int]
  15. MyGraph* = object
  16. points: seq[XY]
  17. static:
  18. assert XY is Node
  19. proc distance*( g: MyGraph, a, b: XY): float =
  20. sqrt( pow(float(a.x - b.x), 2) + pow(float(a.y - b.y), 2) )
  21. static:
  22. assert MyGraph is Graph1
  23. assert MyGraph is Graph2
  24. assert MyGraph is Graph3