;;; -*- lexical-binding: t -*- ;; This file: http://user.it.uu.se/~embe8573/emacs-init/frame-size.el ;; https://dataswamp.org/~incal/emacs-init/frame-size.el ;; ;; Update history: 2019-05-06 02:51 first release ;; 2019-07-31 06:33 - got away w/ globals ;; - support for road bikes ;; - size in inches as well as cm ;; ;; frame size = length of seat tube ;; ;; measured from the top of the seat tube ;; down to the center of the bottom bracket ;; ;; ;; ;; rider height MTB frame size ;; ;; (cm) (cm) ;; ;; 4'10" - 148 - 13" - 14" 33 - 37 ;; 5'2" 158 ;; ;; 5'2" - 158 - 15" - 16" 38 - 42 ;; 5'6" 168 ;; ;; 5'6" - 168 - 17" - 18" 43 - 47 ;; 5'10" 178 ;; ;; 5'10" - 178 - 19" - 20" 48 - 52 ;; 6'1" 185 ;; ;; 6'1" - 185 - 21" - 22" 53 - 57 ;; 6'4" 193 ;; ;; 6'4" - 193 - 23" - 24" 58 - 61 ;; 6'6" 198 ;; ;; ;; ;; Example how to do the interval math for ;; a particular height ;; ;; height h = 190 cm ;; ;; h \in [185 193] cm so ;; ;; MTB frame size m \in [53 57] cm ;; ;; (190 - 185)/(193 - 185.0) * (57 - 53) + 53 cm = 55.5 cm ;; ;; ;; note: border cases will favor the smaller ;; frame, because experience tells us ;; this makes sense (defun in-inclusive (a min max) (and (<= min a) (<= a max) )) (defun compute-frame-size (h mtb) (let*((table (if mtb '(((148 158) (33 37)) ; height to frame size ((158 168) (38 42)) ((168 178) (43 47)) ((178 185) (48 52)) ((185 193) (53 57)) ((193 198) (58 61)) ) '(((168 175) (54 55)) ; ditto road bike (URL source?) ((175 183) (56 58)) ((183 191) (58 60)) ))) (intervals (cl-find-if (lambda (e) (in-inclusive h (caar e) (cl-cadar e) )) table) ) (h-interval (car intervals)) (m-interval (cadr intervals)) (h-min (caar intervals)) (h-max (cadr h-interval)) (m-min (car m-interval)) (m-max (cadr m-interval)) (frame-cm (+ (* (/ (- h h-min) (- h-max h-min) 1.0) (- m-max m-min) ) m-min) ) (frame-cm-round (round frame-cm)) (frame-inches (round (/ frame-cm 2.54))) ) (message "frame size: %d cm (%d inches)" frame-cm-round frame-inches) )) ;; MTB test: ;; (compute-frame-size 180 t) ; "frame size: 49 cm (19 inches)" ;; (compute-frame-size 190 t) ; "frame size: 56 cm (22 inches)" ;; RB test: ;; (compute-frame-size 180 nil) ; "frame size: 57 cm (23 inches)" ;; (compute-frame-size 190 nil) ; "frame size: 60 cm (24 inches)"