Show HN: MockMechanics is now open source
The biggest let I have seen in my life:<p><pre><code>  (let [[track-name wagon-name] (if (= (get-in world [:parts part-1-name :type]) :track)
                                  [part-1-name part-2-name]
                                  [part-2-name part-1-name])
        track (get-in world [:parts track-name])
        wagon (get-in world [:parts wagon-name])
        track-position (get-part-position world track-name)
        wagon-position (get-part-position world wagon-name)
        layer (apply min (:visible-layers world))
        color-1 (new Color 10 10 10)
        gear (create-part :gear color-1 layer (:info world))
        gear-name (gen-keyword :gear)
        track-plane (get-track-plane track)
        axis (vector&#x2F;normalize (get-track-direction track))
        offset (vector&#x2F;multiply
                 axis
                 (point-plane-distance wagon-position track-plane))
        gear-transform (combine-transforms
                         (:transform track)
                         (make-transform offset [1 0 0 0]))
        wagon-parent-name (get-parent-part world wagon-name)
        wagon-parent (get-in world [:parts wagon-parent-name])
        wagon-parent-direction (get-track-direction wagon-parent)
        gear-position (get-transform-position gear-transform)
        point (point-line-projection gear-position [wagon-position wagon-parent-direction])
        to-wagon (vector&#x2F;normalize (vector&#x2F;subtract point gear-position))
        d (point-plane-distance
            wagon-position
            (line-&gt;plane [track-position to-wagon]))
        color-2 (new Color 128 128 128)
        rack (create-part :rack color-2 layer (:info world))
        rack-name (gen-keyword :rack)
        gear-position (get-transform-position gear-transform)
        h-distance (point-line-distance
                     (get-part-position world wagon-parent-name)
                     [gear-position to-wagon])
        wagon-parent-length (second (:scale wagon-parent))
        parallel-offset (- (&#x2F; wagon-parent-length 2) h-distance)
        parallel-offset (vector&#x2F;multiply
                          (vector&#x2F;normalize wagon-parent-direction) parallel-offset)
        perpendicular-offset (vector&#x2F;multiply to-wagon -0.125)
        wagon-rotation (get-rotation-component (:transform wagon))
        rack-angle (vector&#x2F;angle (apply-transform wagon-rotation [-1 0 0])
                                 (vector&#x2F;multiply to-wagon -1) wagon-parent-direction)
        rack-transform (combine-transforms
                         (make-transform [0 0 0] [0 1 0 rack-angle])
                         (combine-transforms
                           (:transform wagon)
                           (make-transform (vector&#x2F;add parallel-offset perpendicular-offset)
                                           [1 0 0 0])))
        tooth-height 0.09
        radius (- d 0.175 tooth-height)
        scale-1 [(* radius 2) 0.2 (* radius 2)]
        rack-length (+ wagon-parent-length 0.0)
        scale-2 [0.1 rack-length 0.2]
        w (set-value-0-transform world track-name)
        p1 (get-in w [:parts track-name])
        track-1-rotation (get-rotation-component (:transform p1))
        track-1-x (apply-transform track-1-rotation [1 0 0])
        angle-offset (- (vector&#x2F;angle track-1-x to-wagon axis))
        sign (- (vector&#x2F;dot-product to-wagon
                                    (vector&#x2F;cross-product
                                      wagon-parent-direction
                                      (get-track-direction track))))]</code></pre>