Author Topic: Testing for a point  (Read 6040 times)

0 Members and 2 Guests are viewing this topic.

Shade

  • Guest
Testing for a point
« on: March 10, 2006, 09:52:58 AM »
How does one test for a point?

Example code...
Code: [Select]
(initget "Options")
(setq PNT (getpoint "\nSelect Point, <O>ptions: "));
(if (not PNT [color=Red]Point[/color])
   (OPTIONS)
);

I thought of testing the variable PNT to see if its a list, but I would like to know if there is a better more secure way of testing for a point
     
Thanks in advance for any help...
Shade

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Testing for a point
« Reply #1 on: March 10, 2006, 11:33:43 AM »
If you want to see if it is a point (list) then you can use the "type" function on the variable.
Code: [Select]
(if (= (type Pnt) 'LIST)
 .... do whatever
 ... or do your options thingy here.
)

??
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Testing for a point
« Reply #2 on: March 10, 2006, 11:45:12 AM »
Here is my "Over The Top" routine. :-o
Code: [Select]
;;;=======================[ getpoint_only.lsp ]=======================
;;; Author: Charles Alan Butler
;;; Version:  1.0 Jun. 16, 2005
;;; Purpose: Only get a point, do not return without one
;;; Sub_Routines: -None
;;; Arguments: -msg  string containing the prompt message
;;; Usage:  (getpoint_only msg)
;;; Returns: -the point picked
;;; Note: -User may enter a point at the command line 10,10 or 10,10,0
;;;====================================================================
;;  This is an attempt at preventing the user from entering a distance
;;  which ACAD uses with the cursor direction to derive the new point.
(defun getpoint_only (msg / pt loop fuzz lastp)
  (setq loop  t
        fuzz  0.0001
        lastp (getvar "lastpoint")
  )
  (setq msg (strcat "\n" (cond (msg) ("Please select a point: "))))
  ;;  in case the user pressed escape last time here
  (if (< fuzz (distance '(1.9999 1.9999 0.0) (getvar "lastpoint")))
    (setvar "lastpoint" '(1.9999 1.9999 0.0))
    (setvar "lastpoint" '(1.8999 1.8999 0.0))
  )
  (while loop
    ;;  pt must meet the following requirements
    (if (and (setq pt (getpoint msg))    ; not nil
             (listp pt)                  ; must be a list
             ;;  do not allow bad numeric entry
             (< fuzz (distance pt (getvar "lastpoint")))
        )
      (setq loop nil) ; ok to exit, else
      (prompt "\nYou must select a point, please try again. ")
    )
  )
  (setvar "lastpoint" lastp)
  pt
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Testing for a point
« Reply #3 on: March 10, 2006, 12:11:41 PM »
This is one way
Code: [Select]
(if (not (and pnt (listp pnt) (=(length pnt) 3)))
  (options)
)

or like tim said
Code: [Select]
(if (and pnt (listp pnt))
  (do your point stuff)
  (options)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Testing for a point
« Reply #4 on: March 10, 2006, 12:20:49 PM »
or like tim said
Code: [Select]
(if (and pnt (listp pnt))
  (do your point stuff)
  (options)
)
I didn't say it that direct.  I forgot all about "listp" Alan.  :wink:
I take the credit if you want to give it to me though.  :angel:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Testing for a point
« Reply #5 on: March 10, 2006, 01:21:32 PM »
Another...

Code: [Select]
(defun pt? (pt)
  (and (vl-consp pt)
       (= (length pt) 3)
       (vl-every '(lambda (coord) (= (type coord) 'real)) pt)))

zoltan

  • Guest
Re: Testing for a point
« Reply #6 on: March 10, 2006, 06:45:33 PM »
That's a good one, Luis.

At the end of the day, I would end up naming the function PointP, but that's just me :)

By the way, could'nt a point be a list of integers also?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Testing for a point
« Reply #7 on: March 10, 2006, 06:51:03 PM »
Yes, it can.
It can also be a 2d point, which is acceptable for most aCAD commands.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Testing for a point
« Reply #8 on: March 10, 2006, 07:02:11 PM »
Perhaps ;
Code: [Select]
(defun point-p3D (pt)
  (and (vl-consp pt)
       (= (length pt) 3)
       (vl-every '(lambda (coord) 'numberp) pt)
  )
)

Code: [Select]
(setq 3D '(1 2 3))
(setq 2D '(4 5))

(point-p3D 3d )
(point-p3D 2d )

// kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Testing for a point
« Reply #9 on: March 10, 2006, 07:25:19 PM »
Abused from another post --

Code: [Select]
(defun IsPoint ( point )
    (and
        (listp point)
        (< 1 (length point) 4)
        (vl-every 'numberp point)
    )
)

Code: [Select]
(defun Is3DPoint ( point )
    (and
        (listp point)
        (eq 3 (length point))
        (vl-every 'numberp point)
    )
)

(vl-every '(lambda (coord) 'numberp) pt)

Hmmm, digesting ...



Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Testing for a point
« Reply #10 on: March 10, 2006, 07:30:28 PM »
I can't help but wonder if the initial inquiry would be moot if initget were invoked before the getpoint call.  Hmmm.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Testing for a point
« Reply #11 on: March 10, 2006, 07:45:15 PM »

(vl-every '(lambda (coord) 'numberp) pt)

Hmmm, digesting ...

yep, supreme redundency :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Testing for a point
« Reply #12 on: March 10, 2006, 07:48:53 PM »
Abused from another post

I've noticed recently there are a lot of conversations I've forgotten.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Testing for a point
« Reply #13 on: March 10, 2006, 08:36:56 PM »
You're not alone Kerry.

The sleep medication I'm taking is really affecting my memory.

Speaking of such, humour that writes itself:  Over supper I was talking to my wife about said memory loss, and said something like "It's a little disconcerting how much the medication is affecting my memory".

She replies: "Really? What have you forgotten?"

<blink.mpg>

<crickets.wav>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Testing for a point
« Reply #14 on: March 10, 2006, 08:45:31 PM »
(clapping-enthusiastic.wav>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
Re: Testing for a point
« Reply #15 on: March 10, 2006, 09:41:29 PM »
By the way, could'nt a point be a list of integers also?

Yes...

Even a combination of integers and reals.... there is a better alternative in the post by MP.

I needed reals for that function... no remember why.... [real excuse #23214325423545343256432]