If you are using Script-fu and your script is for versions 2.2.x of the
GIMP then the following function will return the length of a given path.
 It will work with version 2.3 but will generate some deprecation
warnings (and 2.3 provides better methods).

;; '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 
    )
  )

-- 
Paolo Herms
Sun, 24 Sep 2006 07:52:03 -0700

> Hello,
> I've got a cartographic image and I designed a path on it.
> Is there any way to find out its length?

_______________________________________________
Gimp-user mailing list
Gimp-user@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-user

Reply via email to