 (ns org.gavrog.clojure.selfdual2d
   (:use (org.gavrog.clojure
-          [delaney]))
+          [delaney]
+          [generators :only [results]]
+          [branchings2d :only [branchings]]))
   (:import (org.gavrog.jane.fpgroups SmallActionsIterator)
-           (org.gavrog.jane.numbers Whole)
-           (org.gavrog.joss.dsyms.basic DSymbol)
-           (org.gavrog.joss.dsyms.derived FundamentalGroup DSCover Covers)
-           (org.gavrog.joss.tilings Tiling)
-           (org.gavrog.joss.dsyms.generators DefineBranching2d))
+           (org.gavrog.joss.dsyms.derived FundamentalGroup DSCover)
+           (org.gavrog.joss.tilings Tiling))
   (:gen-class))
-
-(defn self-dual? [ds] (= ds (.dual ds)))
-
-(defn minimal? [ds] (.isMinimal ds))
 
 (defn euclidean? [ds] (= (curvature ds 1) 0))
 
 (defn proto-euclidean? [ds] (>= (curvature ds 1) 0))
 
-(defn good-face-sizes? [ds]
-  (let [t (map #(.m ds 0 1 %) (orbit-reps ds [0 1]))]
-    (and (<= (count (distinct t)) 2) (some #(= 3 %) t))))
-
 (defn- good-node [net pos v]
   (not (empty? (.goodCombinations net (.allIncidences net v) pos))))
 
 (defn convex? [ds]
-  (if-let [net (try (.getSkeleton (Tiling. ds))
+  (if-let [net (try (.getSkeleton (Tiling. (java-dsymbol ds)))
                  (catch IllegalArgumentException e))]
     (let [pos (.barycentricPlacement net)]
       (every? (partial good-node net pos)

(defn d-syms [max-size]
  (let [good? (andp self-dual? minimal? euclidean? convex?)]
    (for [dset (d-sets max-size)
          dsym (lazy-seq (DefineBranching2d. dset 3 3 Whole/ZERO))
          :when (good? dsym)]
    (.canonical dsym))))

;; Main entry point when used as a script
(defn -main [& args]
  (print-seq (d-syms (Integer/parseInt (first args)))
             str
             #(str "# Generated " %1 " symbols in " %2 " seconds.")))

    (reduce #(and %1 (apply %2 args)) true preds)))

(defn d-sets [max-size]
  (let [G (FundamentalGroup. (java-dsymbol "1:1,1,1"))]
    (filter (andp self-dual? proto-euclidean?)
            (map #(dsymbol (DSCover. G %))
                 (SmallActionsIterator. (.getPresentation G) max-size false)))))

(defn print-seq [xs format-item format-summary]
