0 Members and 1 Guest are viewing this topic.
If I'm understanding you guys tests correctly you are simply testing to see if the diagonals are equal. This is not sufficient. REGULARPOLYGON-P tests if all the sides are equal but doesn't test vertex angles or parallelism. A rectangle must have at least 2 right angles and opposite pairs of sides must be equal in length. There must also be two different side lengths to distinguish from a square.
What about checking for arc segments...
(defun RECTANGLE-p (ename fuzz / e pts) (and (eq (type ename) 'ename) (eq (cdr (assoc 0 (setq e (entget ename)))) "LWPOLYLINE") (setq pts (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= 10 (car x)))) e))) (= (length pts) 4) (setq legs (mapcar 'distance (append (cdr pts)(list (car pts)))(append (reverse (cdr (reverse pts)))(list (last pts))))) (vl-every '(lambda(x y)(equal x y fuzz))legs(reverse legs) ) ))
(defun regularpolygon-p (ename fuzz / ap d e p pts) (and (eq (type ename) 'ename) (eq (cdr (assoc 0 (setq e (entget ename)))) "LWPOLYLINE") (setq pts (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= 10 (car x)))) e))) (> (length pts) 2) (setq ap (mapcar '(lambda (p) (/ p (length pts))) (apply 'mapcar (cons '+ pts)))) (setq d (distance ap (car pts))) ;; Check for arc segments (vl-every '(lambda (x) (if (= 42 (car x)) (zerop (cdr x)) t ) ) e ) ;; Check distance from centroid to points (vl-every '(lambda (p) (grdraw ap p 1) (equal (distance ap p) d fuzz)) pts) ))(regularpolygon-p (car (entsel)) 0.0001)