#lang racket/base

; A library to provide basis structures for graphs
(provide
  ; Point structure
  point point-x point-y
  point-equal?
  point-add
  ; Edge structure
  edge edge-first edge-last
  edge-equal?
  )

; 2d Point structure
; Structure
(struct point (x y)
  #:methods gen:equal+hash
    [(define (equal-proc p1 p2 recursive-equal?)
      (point-equal? p1 p2))
     (define (hash-proc p recursive-equal-hash)
        (+ (point-x p)
           (* 1000 (point-y p))))
     (define (hash2-proc p recursive-equal-hash)
        (+ (point-y p)
           (* 100 (point-x p))))]
  )
; Equality
(define (point-equal? p1 p2)
  (and (eq? (point-x p1) (point-x p2))
       (eq? (point-y p1) (point-y p2))))
; Addition
(define (point-add p1 p2)
  (point
    (+ (point-x p1) (point-x p2))
    (+ (point-y p1) (point-y p2))))

; Edge between two points
(struct edge (first last))
; Edge equality. Edge are not directed : (edge A B) and (edge B A) are equal
(define (edge-equal? e1 e2)
  (or (and (point-equal? (edge-first e1) (edge-first e2))
           (point-equal? (edge-last e1) (edge-last e2)))
      (and (point-equal? (edge-first e1) (edge-last e2))
           (point-equal? (edge-last e1) (edge-first e2)))))
