;; 'sflib-path-get-length' returns the length of the specified path ;; ;; NOTE: If the end of the path is a X=0, Y=0 (and the slope ;; is zero there) then the value returned will be ;; slightly shorter (as much as 1.4) than actual. ;; (The path may *start* at 0,0) (define (sflib-path-get-length image pathname) (let* ( (path (gimp-path-get-points image pathname)) (last-index (* 9 (- (trunc (/ (+ (caddr path) 3) 9)) 1))) (points (cadr (cddr path))) (point-guess) (point-lo (list (aref points 0) (aref points 1))) (point-hi (list (aref points last-index) (aref points (+ last-index 1)))) (guess (sqrt (+ (* (- (car point-hi) (car point-lo)) (- (car point-hi) (car point-lo))) (* (- (cadr point-hi) (cadr point-lo)) (- (cadr point-hi) (cadr point-lo))))) ) (guess-lo 0) (guess-hi (* guess 2)) (Done FALSE) (pnt (gimp-path-get-point-at-dist image guess-hi)) ) (while (not (and (= (car pnt) 0) (= (cadr pnt) 0) (= (caddr pnt) 0))) (set! guess-hi (* guess-hi 2)) (set! pnt (gimp-path-get-point-at-dist image guess-hi)) ) (while (= Done FALSE) (set! point-guess (gimp-path-get-point-at-dist image guess)) (if (and (= (car point-guess) 0) (= (cadr point-guess) 0) (= (caddr point-guess) 0)) (begin (set! point-hi point-guess) (set! guess-hi guess) (set! guess (/ (+ guess guess-lo) 2)) ) (if (or (and (= (car point-guess) (car point-lo)) (= (cadr point-guess) (cadr point-lo)) ) (and (= (car point-guess) (car point-hi)) (= (cadr point-guess) (cadr point-hi)) )) (set! Done TRUE) (begin (set! point-lo point-guess) (set! guess-lo guess) (set! guess (/ (+ guess guess-hi) 2)) ) ) ) ) guess ) ) (script-fu-register "sflib-path-get-length" ;func name "Get Path Length" ;menu label "Get the length of a path" ;description "" ;author "" ;copyright notice "" ;date created "RGB RGBA GRAY GRAYA INDEXED INDEXEDA" ;image type that the script works on SF-IMAGE "Image:" 0 ;image variable SF-STRING "Path:" "" ;string (path variable) ) (script-fu-menu-register "sflib-path-get-length" "/Script-Fu/Utils")