Deleting the same lines from a list
DeleteDuplicatesBy[lines, Sort @@ # &]
or
DeleteDuplicates[Sort @@@ lines]
The key is to realize that we have to Apply
Sort
one level deeper because of the head Line
.
Another possibility is to use RegionEqual
:
Length @ lines
Length @ DeleteDuplicates[lines, RegionEqual]
8
7
If your lines had more than 2 segments, than using Sort
to canonicalize wouldn't work.
It is because the arguments of the 5-th and 8-th terms go in different order. Indeed, let us take only the arguments:
arg = lines[[All, 1]];
and let us try to compare the arguments of the 5th and 8th terms:
arg[[5]] === arg[[8]]
(* False *)
Now let us sort the arguments:
newArg = Sort /@ lines[[All, 1]]
and let us check the 5th and 8th terms
newArg[[5]] === newArg[[8]]
(* True *)
Now the duplicates will be deleted, and here is the result:
Line /@ DeleteDuplicates[newArg]
Have fun!