Created
August 24, 2015 11:29
-
-
Save lorddoig/232ceab75569bcbedab5 to your computer and use it in GitHub Desktop.
CLJS goog.math.Rect wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-ns | |
(:refer-clojure :exclude [contains?]) | |
(:require [goog.math.Rect :as grect]) | |
(:import goog.math.Rect)) | |
(defprotocol IRectangle | |
(bounding-rect [this other]) | |
(ceil [this]) | |
(contains? [this other]) | |
(difference [this other]) | |
(distance [this point]) | |
(floor [this]) | |
(get-bottom-right [this]) | |
(get-center [this]) | |
(get-size [this]) | |
(get-top-left [this]) | |
(intersection [this rect]) | |
(intersects? [this rect]) | |
(round [this]) | |
(scale [this sx] | |
[this sx sy]) | |
(squared-distance [this point]) | |
(translate [this tx] | |
[this tx ty])) | |
(extend-type Rect | |
IEquiv | |
(-equiv [this other] | |
(grect/equals this other)) | |
ILookup | |
(-lookup | |
([this k] | |
(-lookup this k nil)) | |
([this k not-found] | |
(case k | |
:w (.-width this) | |
:width (.-width this) | |
:h (.-height this) | |
:height (.-height this) | |
:x (.-left this) | |
:left (.-left this) | |
:y (.-top this) | |
:top (.-top this) | |
not-found))) | |
IRectangle | |
(bounding-rect [this other] (.boundingRect (.clone this) other)) | |
(ceil [this] (.ceil (.clone this))) | |
(contains? [this other] (.contains this other)) | |
(difference [this other] (.difference this other)) | |
(distance [this point] (.distance this point)) | |
(floor [this] (.floor (.clone this))) | |
(get-bottom-right [this] (.getBottomRight this)) | |
(get-center [this] (.getCenter this)) | |
(get-size [this] (.getSize this)) | |
(get-top-left [this] (.getTopLeft this)) | |
(intersection [this other] (.intersection (.clone this) other)) | |
(intersects? [this other] (.intersects this other)) | |
(round [this] (.round (.clone this))) | |
(scale | |
([this sx] (.scale (.clone this) sx)) | |
([this sx sy] (.scale (.clone this) sx sy))) | |
(squared-distance [this point] (.squaredDistance this point)) | |
(translate | |
([this tx] (.translate (.clone this) tx)) | |
([this tx ty] (.translate (.clone this) tx ty)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment