;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/frame-size.el ;; ;; frame size definition: ;; center of bottom bracket to top of seat tube ;; ;; sources: ;; https://www.bikeradar.com/advice/sizing-and-fit/road-bike-sizing/ ;; https://www.evo.com/guides/mountain-bike-fit-size-geometry (require 'cl-lib) (defun in-interval (a min max &optional exclusive) (let ((op (if exclusive #'< #'<=))) (and (apply op (list min a)) (apply op (list a max)) ))) (defun frame-size (h &optional mtb) (pcase-let*((table (if mtb '(((148 158) (33 37)) ; XS ((158 168) (38 42)) ; S ((168 178) (43 47)) ; M ((178 185) (48 52)) ; L ((185 193) (53 57)) ; XL ((193 198) (58 61)) ; XXL ) '(((148 152) (47 48)) ; XXS ((152 160) (49 50)) ; XS ((160 168) (51 53)) ; S ((168 175) (54 55)) ; M ((175 183) (56 58)) ; L ((183 191) (58 60)) ; XL ((191 198) (61 63)) ; XXL ))) (`((,h-min ,h-max) (,f-min ,f-max)) (cl-find-if (lambda (e) (in-interval h (caar e) (cadar e)) ) table) ) (f-cm (+ (* (/ (- h h-min) (- h-max h-min) 1.0) (- f-max f-min) ) f-min) ) (f-cm-round (round f-cm)) (f-inches (round (/ f-cm 2.54))) ) (message "%d cm (%d\")" f-cm-round f-inches) )) ;; (insert " ; MTB: " (frame-size 180 t)) ; MTB: 49 cm (19") ;; (insert " ; road bike: " (frame-size 180 )) ; road bike: 57 cm (23") (provide 'frame-size)