This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-02
Channels
- # aleph (6)
- # beginners (37)
- # boot (415)
- # cider (17)
- # cljs-dev (79)
- # cljsjs (3)
- # cljsrn (18)
- # clojars (3)
- # clojure (34)
- # clojure-france (6)
- # clojure-italy (1)
- # clojure-korea (1)
- # clojure-russia (22)
- # clojure-spec (64)
- # clojure-uk (47)
- # clojurebridge (6)
- # clojurescript (61)
- # clojurex (1)
- # cloverage (11)
- # component (6)
- # cursive (73)
- # data-science (6)
- # datascript (4)
- # datomic (38)
- # editors (1)
- # emacs (4)
- # events (16)
- # funcool (5)
- # garden (3)
- # hoplon (17)
- # jobs (2)
- # klipse (74)
- # off-topic (3)
- # om (81)
- # onyx (35)
- # parinfer (4)
- # pedestal (1)
- # perun (20)
- # planck (9)
- # proton (1)
- # re-frame (17)
- # reagent (3)
- # ring-swagger (1)
- # rum (7)
- # untangled (63)
- # vim (8)
i’m curious how someone might find the intersections between a vector of points: input: [[1 3] [2 4] [5 6]] output: [[1 4] [5 6]] I started off trying to do this with a reduce, but im not sure how to handle the case when the return value is a merged list.
excuse my ignorance, but how do you find an intersection between some points? don't you need, like, vectors, or straight lines?
Right, I should have said lines as represented by 2 points.
there is formula for this: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
I will continue my server questions. I have clojure server with clojurescript front and I have used cljs-ajax with JSON to transfer data between them. In server side I have used wrap-restful-format to serialize data structures to JSON but it seems really picky on what kind of structure I give it to it
So is there better library for handling JSON server side? Or maybe better Clojure specific way to transfer data between server and front?
@neurogoo there is transit: https://github.com/cognitect/transit-clj and several libraries with support for it, I think cljs-ajax has it as default even. I use this middleware with ring: https://github.com/jalehman/ring-transit and it worked out so far
input: [[1 3] [2 4] [5 6]]
output: [[1 4] [5 6]]
the input would be 3 lines.
the output would be the merged lines merge((1,3), (2,4)) => (1,4) and in the case when they dont intersect, then just the original lines/inputs merge((1,4), (5,6)) => [(1,4), (5,6)].
That second aspect is what causes it hard to see how i can use reduce.maybe the confusion is because their is only 1 dimension with these “points” more specifically im trying to find if two “times” overlap so the input would be more like
(sunday_at_5, sunday_at_7), (sunday_at_4, sunday_at_6)
[1 3]
and [2 4]
are points, not lines - unless you intend them as vectors starting from origin, but in that case they do not intersect
@vandr0iy Line1 = 1-to-3 Line2 = 2-to-4 There is only one dimension. so instead of (x,y) this is just (x,x). Does that make sense
right, so maybe the right word here is range instead of line.
@rauh thanks, i forgot the importance of finding the right word before searching for an answer. Using interval i get a lot better search results.
yes, you're looking for merging intervals, you should easily find proper algorithms
(defn merge-intervals [vs]
(let [sorted (sort (map (comp vec sort) vs))
f (fn [res el]
(let [[a b] (first res)
[na nb] el]
(if (< na b)
(cons [a nb] (rest res))
(cons el res))))]
(reverse (reduce f [(first sorted)] (rest sorted)))))
A simplification for this:
(vec (flatten (vector [1 2 3] [2 4 5]))) ; returns [1 2 3 2 4 5]
eludes me. Can anyone think of one?OK. May have it. `(vec (concat
yeah i sut spotted it
Thanks
@tsulej thanks! Ill give this a look. I see reduce in their which peeks my curiosity as i banged my head trying to make that fit.
@gamecubate: into
often surprises: (into [1 2 3] [2 4 5])
Ah yes. Thanks @mfikes. Humbling that, having finished writing a pretty big project in cljs&reagent front-end + node.js backend project, I’m still weak on basic stuff.
Ways to go.