;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/frame-size.el ;; ;; frame size = top of seat tube to center of bottom bracket ;; ;; source MTB: ;; https://www.evanscycles.com/help/bike-sizing-mountain (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)) ((158 168) (38 42)) ((168 178) (43 47)) ((178 185) (48 52)) ((185 193) (53 57)) ((193 198) (58 61)) ) '(((168 175) (54 55)) ; data source lost ((175 183) (56 58)) ((183 191) (58 60)) ))) (`((,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 " ; " (frame-size 180 t)) ; 49 cm (19") ;; (insert " ; " (frame-size 181 t)) ; 50 cm (20") ;; (insert " ; " (frame-size 180)) ; 57 cm (23") ;; (insert " ; " (frame-size 190)) ; 60 cm (24") (provide 'frame-size)