Create line segment from two points in Clojure -


What's the best way to do this? Even i have so far

  (line-segment [start-end] (x-direction (stomach (- (first end))) y-direction ( Ab (- (last end) (last end)] (cond (= 0 x-direction) (some ...) (= 0 y-direction) (some ...))))   

Here is my ultimate goal

  user => (line segment [5 6] [5 8]) ([5 6] [5 7] [5 8] )   

And yes, there are no diagonals, only x or y movement.

thanks

Post-text "itemprop =" text ">

I think it's a beautiful elegant The solution is: <(the last edge) y2 (if (> x1 x2) () -1) 1 (1) DI (if (> y1 y2 -1) ([x (range x1 (+ dx X2) dx y (category y1 (+ yy 2))) [] [xy])))

REPL session:

  users> ; (Line Segment [5 6] [5 8]) ([5 6] [5 7] [5 8]) Users & gt; (Line segment [5 8] [5 6]) ([5 8] [5 7] [5 6]) Users & gt; (Line segment [-2 7] [1 7]) ([-27] [-17] [0 7] [1 7]) User & gt; (Line Segment [1 7] [-27]) ([1 7] [0 7] [-17] [-27])   

This function is a LazySeq even if your sample output is formatted as a vector. I thought it was not important.

Comments