TEST for you

TEST for you

john.uhden
Mentor Mentor
967 Views
5 Replies
Message 1 of 6

TEST for you

john.uhden
Mentor
Mentor

Tell me what's wrong with this function.  It gets used numerous times in a routine I am writing.

No, it's not that the @Anonymous function is missing.  Yes, I found the error this morning.

It is something for which we must always watch out.

Hint:  It caused the creation of 72-vertex polylines when they should have been 4-vertex.

  ;;--------------------------------------------------------
  ;; Function to rotate a set of points (data) in the format
  ;; (pt pt pt ... ) about a base point (bp) from p1 to p2:
  ;;
  (defun @rotdata (bp p1 p2 data / delta ang p newdata)
     (setq delta (@delta (angle bp p1)(angle bp p2))) ;; changed (08-07-18)
     (foreach p data
        (setq p (polar bp (+ (angle bp p) delta)(distance bp p))
             new (cons p new)
        )
     )
     (reverse new)
  )

John F. Uhden

0 Likes
Accepted solutions (2)
968 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

The 'new' variable is not localized, so as the function "gets used numerous times," on subsequent uses 'new' keeps getting added to, instead of being limited to the result from the current 'data' list.  It would suffice to just change 'newdata ' in the localized variables list to 'new' as used in the function definition [or vice versa] -- as it is, 'newdata' doesn't exist in the routine.

 

[You also have a localized variable 'ang' that doesn't exist in the routine, but that wouldn't keep it from working right.]

Kent Cooper, AIA
Message 3 of 6

Moshe-A
Mentor
Mentor
Accepted solution

Hi John,

 

there are 2 unused local variables  ang  + newdata

new variable is global? 

 

moshe

 

 

Message 4 of 6

john.uhden
Mentor
Mentor

Excellent!

@Kent1Cooper and @Moshe-A have very sharp and experienced eyes.

Technically, Moshe gets an A, but Kent gets an A+.

John F. Uhden

0 Likes
Message 5 of 6

ronjonp
Mentor
Mentor

FWIW I'd use mapcar for something like this then you don't need to reverse the result:

(defun @rotdata2 (bp p1 p2 data / delta delta)
  (setq delta (@delta (angle bp p1) (angle bp p2)))
  (mapcar '(lambda (x) (polar bp (+ (angle bp x) delta) (distance bp x))) data)
)

 

Message 6 of 6

john.uhden
Mentor
Mentor
I have a bundle of old stuff that looks like kindergarten work. But at
least it works.
Thanks!

John F. Uhden

0 Likes