Author Topic: Comparing List of Points  (Read 7147 times)

0 Members and 2 Guests are viewing this topic.

Patrick_35

  • Guest
Re: Comparing List of Points
« Reply #15 on: November 27, 2014, 05:49:48 AM »
Hi

To compare two list without vl-every

< ... >


(equal lst-1 lst-2 1e-4) --> T
(equal lst-1 lst-2 1e-5) --> nil

:-)
This only seems to work if the order is identical.
Yes, the goal is to see if the two lists are identical
Now, if the order does not matter, we can do
Code: [Select]
(equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
@+

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Comparing List of Points
« Reply #16 on: November 27, 2014, 12:13:05 PM »
Now, if the order does not matter, we can do
Code: [Select]
(equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
@+

Be careful with vl-sort:
Code: [Select]
_$ (setq lst-1 '(1 2 3 4 4 5) lst-2 '(1 2 2 3 4 5))
(1 2 2 3 4 5)
_$ (equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
T

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Comparing List of Points
« Reply #17 on: November 27, 2014, 12:47:40 PM »
Now, if the order does not matter, we can do
Code: [Select]
(equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
@+

Be careful with vl-sort:
Code: [Select]
_$ (setq lst-1 '(1 2 3 4 4 5) lst-2 '(1 2 2 3 4 5))
(1 2 2 3 4 5)
_$ (equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
T

1+

Maybe...
Code: [Select]
(defun f ( lst-1 lst-2 )
  (if (and (listp (car lst-1)) (listp (car lst-2)))
    (equal
      (mapcar 'nth
        (vl-sort-i lst-1 '(lambda ( a b ) (< (distance '(0.0 0.0 0.0) a) (distance '(0.0 0.0 0.0) b))))
        (mapcar '(lambda ( x ) lst-1) lst-1)
      )
      (mapcar 'nth
        (vl-sort-i lst-2 '(lambda ( a b ) (< (distance '(0.0 0.0 0.0) a) (distance '(0.0 0.0 0.0) b))))
        (mapcar '(lambda ( x ) lst-2) lst-2)
      )
      1e-4
    )
    (equal
      (mapcar 'nth
        (vl-sort-i lst-1 '<)
        (mapcar '(lambda ( x ) lst-1) lst-1)
      )
      (mapcar 'nth
        (vl-sort-i lst-2 '<)
        (mapcar '(lambda ( x ) lst-2) lst-2)
      )
      1e-4
    )
  )
)
« Last Edit: November 27, 2014, 01:07:11 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Comparing List of Points
« Reply #18 on: November 27, 2014, 01:23:31 PM »
I am stating the obvious here: Sorting a flat list of reals representing alternating X and Y coordinates of 2D points makes little sense.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Comparing List of Points
« Reply #19 on: November 27, 2014, 02:09:05 PM »
I am stating the obvious here: Sorting a flat list of reals representing alternating X and Y coordinates of 2D points makes little sense.

Agreed, but then neither does comparing arbitrary X & Y values between the two lists - if I've understood what the OP is looking to achieve, I would have expected an ordered comparison up to permutation, e.g. something like:

Code - Auto/Visual Lisp: [Select]
  1. (defun compare ( a b )
  2.     (defun recurse ( a b c )
  3.         (and a (or (equal (append a c) b 1e-8) (recurse (cddr a) b (append c (list (car a) (cadr a))))))
  4.     )
  5.     (recurse a b nil)
  6. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (compare '(1 2 3 4 5 6 7 8 9 0) '(5 6 7 8 9 0 1 2 3 4))
  2. T

Patrick_35

  • Guest
Re: Comparing List of Points
« Reply #20 on: November 27, 2014, 03:02:30 PM »
Now, if the order does not matter, we can do
Code: [Select]
(equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
@+

Be careful with vl-sort:
Code: [Select]
_$ (setq lst-1 '(1 2 3 4 4 5) lst-2 '(1 2 2 3 4 5))
(1 2 2 3 4 5)
_$ (equal (vl-sort lst-1 '<) (vl-sort lst-2 '<) 1e-4)
T
Oh yes, you are right, I had not seen that vl-sort truncates the result with integer
(vl-sort '(1 2 3 4 4 5) '<) --> (1 2 3 4 5)
(vl-sort '(1 2 2 3 4 5) '<) --> (1 2 3 4 5)
and (equal '(1 2 3 4 5) '(1 2 3 4 5)) return T

but (equal (vl-sort '(1.0 2.0 3.0 4.0 4.0 5.0) '<) (vl-sort '(1.0 2.0 2.0 3.0 4.0 5.0) '<)) work
and (equal (vl-sort '(1.0 2.0 3.0 4.0 4.0 5.0) '<) (vl-sort '(1.0 2.0 2.0 3.0 4.0 5.0) '<) 1e-4) work too

@+

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Comparing List of Points
« Reply #21 on: November 27, 2014, 03:50:52 PM »
Oh yes, you are right, I had not seen that vl-sort truncates the result with integer
Only with integers:
Code: [Select]
(vl-sort  '(3 2 1 3 1 2 2 2 1.0 1.0 1.0 1.0) '<)
(1 1.0 1.0 1.0 1.0 2 3)

(vl-sort  '("a" "A" "a") '<)
("A" "a" "a")

(vl-sort  '("a" "A" "a" "A") '<)
("A" "A" "a" "a")

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Comparing List of Points
« Reply #22 on: November 27, 2014, 04:38:25 PM »
Iterative approach:
Code - Auto/Visual Lisp: [Select]
  1. (defun Roy_Compare (lstA lstB / num revLstB)
  2.   (if (= (setq num (length lstA)) (length lstB))
  3.     (progn
  4.       (while
  5.         (and
  6.           (> num 0)
  7.           (not (equal lstA lstB 1e-8))
  8.         )
  9.         (setq num (- num 2))
  10.         (setq lstA (append (cddr lstA) (list (car lstA) (cadr lstA))))
  11.       )
  12.       (/= num 0)
  13.     )
  14.   )
  15. )

Code - Auto/Visual Lisp: [Select]
  1. (Roy_Compare '(1 2 3 4 5 6 7 8 9 0) '(5 6 7 8 9 0 1 2 3 4))

Of course there is still the issue of polylines that overlap but are reversed.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Comparing List of Points
« Reply #23 on: December 01, 2014, 11:20:03 AM »
< .. >
This only seems to work if the order is identical.

Yes,
I tried to visualise the use for comparing point lists where the point order does not matter.
.... wasn't successful.
Care to share the purpose of the test ?
Yes, I am using the boundary command to generate plines and as a result there are some instances where a duplicate polyline gets created but with a different order for the points. This causes the overkill command to fail to identify that they are identical and delete the duplicate. Basically, the polylines need to be identical, but the order that the points were drawn in do not need to be identical.