Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is vector4 intended to be = to clojure persistent vector? #3

Open
joinr opened this issue Feb 1, 2020 · 3 comments
Open

Is vector4 intended to be = to clojure persistent vector? #3

joinr opened this issue Feb 1, 2020 · 3 comments

Comments

@joinr
Copy link

joinr commented Feb 1, 2020

Messing with some pixel operations, scanning to eliminate blank pixels (naively), I want to filter out
[255.0 255.0 255.0 255.0] and record [x y] coords that are non-blank...

(defn extract-outline [pixels]
  (let [blank [255.0 255.0 255.0 255.0]
        [w h] ((juxt c2d/width c2d/height)  pixels)]
    (->> (for  [x (range w)
                y (range h)]
           (let [p (p/get-color pixels x y)]
             (when (not= p blank)
               [x y])))
         (filter identity)
         vec)))

Input pixels is a result of to-pixels from an image. I believe a vector4 buffer.

The problem is, = between the vec4 that's stored in pixels and the literal 4-element vector I denoted is not considered structurally equal. So, every pixel is returned. I'm guessing the simple way out is to to use vec4 explicitly instead of clojure's vector. Is this intentional?

@genmeblog
Copy link
Contributor

genmeblog commented Feb 1, 2020

Thanks for spotting it out. Probably I have to think again about equality (https://github.com/generateme/fastmath/blob/master/src/fastmath/vector.clj#L632)

For your case you can convert blank to color (which is vec4): c/to-color [255.0 255.0 255.0 255.0]) or just set blank to white (c/color 255.0 255.0 255.0 255.0) or c/to-color :white.

@genmeblog
Copy link
Contributor

Considering your example, from efficiency point of view, it's good to have the same types (color ie. vec4). But in fastmath I see that it's crucial to follow Clojure perception of identity vs equality. It should refactored for sure.

@joinr
Copy link
Author

joinr commented Feb 1, 2020

Can maybe mitigate perf hit with a specific instance check for vector. Or force callers to use vec4 equality somehow. Not a huge deal, just something counterintuitive I ran across. I would be okay if an exception was raised too, telling me to use vec4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants