Permalink
Browse files

* Points.java: cleanup.

  • Loading branch information...
1 parent 25ef81e commit 7ab378155a2d35218ee9a140f2d46b7fa6f48b76 @swannodette committed Aug 14, 2009
Showing with 4 additions and 44 deletions.
  1. +0 −7 Points.java
  2. +2 −29 convex_hull.clj
  3. +2 −8 time_hull.clj
View
@@ -1,7 +0,0 @@
-import javax.vecmath.Vector2d;
-
-public class Points {
- static public Vector2d[] points(Object array){
- return (Vector2d[]) array;
- }
-}
View
@@ -1,26 +1,13 @@
(ns convex-hull
- (:import [javax.vecmath Vector2d])
- (:import Points)
- (:use clojure.contrib.math))
+ (:import [javax.vecmath Vector2d]))
(set! *warn-on-reflection* 1)
-(definline points
- "Casts to Vector2d[]"
- [xs] `(. Points points ~xs))
-
(def #^java.util.Random r (java.util.Random.))
(defmacro point [x y]
`(new Vector2d (float ~x) (float ~y)))
-(comment
- (defmacro sub [v1 v2]
- `(let [#^Vector2d temp# (.clone ~v1)]
- (.sub temp# ~v2)
- temp#))
-)
-
(def #^Vector2d mutable-point (point 0 0))
(defmacro sub [v1 v2]
`(do
@@ -30,17 +17,6 @@
(.sub mutable-point# ~v2)
mutable-point#)))
-(comment
- (def #^Vector2d mutable-point (point 0 0))
- (defmacro sub [v1 v2]
- `(do
- (.set mutable-point (.x ~v1) (.y ~v1))
- (let [#^Vector2d mutable-point# mutable-point
- #^Vector2d v# ~v2]
- (.sub mutable-point# ~v2)
- mutable-point#)))
- )
-
(defn #^"[Ljavax.vecmath.Vector2d;" point-array [n]
(make-array Vector2d n))
@@ -91,9 +67,6 @@
(areduce vs i result (aget vs (int 0))
(point-min result (aget vs i))))
-(defn angle-and-point [#^Vector2d point #^Vector2d base]
- [(pseudo-angle (sub point base)) point])
-
(defn find-point-with-least-angle-from [#^Vector2d base angle #^"[Ljavax.vecmath.Vector2d;" vs]
(let [angle (float angle)]
(loop [i (int 0) #^Vector2d result nil result-angle (float 0)]
@@ -116,7 +89,7 @@
(let [#^Vector2d starting-point (find-min-point vs)]
(println starting-point)
(loop [hull-list [starting-point] angle (float 0) #^Vector2d last-point starting-point]
- (let [[angle #^Vector2d next-point] (find-point-with-least-angle-from last-point angle (points vs))
+ (let [[angle #^Vector2d next-point] (find-point-with-least-angle-from last-point angle vs)
#^Vector2d first-point (first hull-list)]
(if (.equals next-point first-point)
hull-list
View
@@ -1,8 +1,6 @@
(ns time-hull
(:use convex-hull)
- (:import [javax.vecmath Vector2d])
- (:import TimeJarvisMarch)
- (:import Points))
+ (:import [javax.vecmath Vector2d]))
(set! *warn-on-reflection* 1)
@@ -12,9 +10,8 @@
(doseq [x hull-points] (println x)))
(comment
- ;; takes 0.438 ms for 8000000 iterations, that's more like it
+ ;; notes
;; 356ms if we call .equals and create a point in each loop
-
;; 80ms if we don't create the vector
;; we should have a mutable vector we use to hold results
;; ~43ms if nothing happens
@@ -27,9 +24,6 @@
;; ~450ms with pseudo-angle as macro
;; < ~450ms with quadrant-one-pseudo-angle as macro
;; ~350ms with type hinted pseudo-angle macro
- ;; ~600ms with two calls to pseudo-angle
- ;; ~650ms with two if expressions
- ;; > 1000ms if we actually operate on next
(time
(do
(set! *warn-on-reflection* 1)

0 comments on commit 7ab3781

Please sign in to comment.