diff --git a/examples/geometry/src/components.cljs b/examples/geometry/src/components.cljs index c54e0bd..f962811 100644 --- a/examples/geometry/src/components.cljs +++ b/examples/geometry/src/components.cljs @@ -1,6 +1,6 @@ (ns components (:require [reagent.core :as r] - [geometry :refer [x y] :as g])) + [geometry :refer [x y dist] :as g])) (def point-defaults {:stroke "black" @@ -46,3 +46,13 @@ [segment a b] [segment b c] [segment c a]]) + + +(defn circle [c r] + [:circle + {:cx (x c) + :cy (y c) + :r (dist c r) + :stroke-width 2 + :stroke "black" + :fill "rgba(0,0,0,0)"}]) diff --git a/examples/geometry/src/core.cljs b/examples/geometry/src/core.cljs index 3558e7a..9d173e4 100644 --- a/examples/geometry/src/core.cljs +++ b/examples/geometry/src/core.cljs @@ -28,6 +28,9 @@ (defn root [] [:g [c/triangle @p1 @p2 @p3] + [c/circle @p1 @p2] + [c/circle @p2 @p3] + [c/circle @p3 @p1] [c/draggable-point p1 mouse-info] [c/draggable-point p2 mouse-info] [c/draggable-point p3 mouse-info]]) @@ -48,4 +51,3 @@ "The corners are draggable"] [root]] (by-id "app"))) - diff --git a/examples/geometry/src/geometry.cljs b/examples/geometry/src/geometry.cljs index 2956ec5..b0e7f9d 100644 --- a/examples/geometry/src/geometry.cljs +++ b/examples/geometry/src/geometry.cljs @@ -24,5 +24,7 @@ (rand-point -1 2 -1 2)) - +(defn dist [p1 p2] + (js/Math.sqrt (+ (js/Math.pow (- (x p2) (x p1)) 2) + (js/Math.pow (- (y p2) (y p1)) 2))))