本帖最后由 vitalgg 于 2023-8-16 06:57 编辑
- (setq waco1
- '((0 468.548 1) (468.548 1332.85 1) (3041.5 675.413 4) (5396.91 547.939 3) (5944.85 360.787 3) (7145.64 278.132 3) (7423.77 991.957 3) (8415.73 468.926 4)))
- (princ "原表:")(princ waco1)
- ;; 按色号排序并分组
- (setq waco1 (vl-sort
- waco1
- '(lambda (x y)
- (<
- (last x)
- (last y)))))
- (setq waco1 (list:group-by
- waco1
- '(lambda (x y)
- (=
- (last x)
- (last y)))))
- ;; 组内起点从小到大排序
- (setq waco1 (mapcar
- '(lambda (x)
- (vl-sort
- x
- '(lambda (m n)
- (< (car m) (car n)))))
- waco1))
- ;; (princ "\n排序表:")(princ waco1)
- ;; 合并同色且连续的,即前一个的起点+长度 >= 紧临表的起点
- (defun join-line (lst / res fuzz)
- (setq fuzz 0.01)
- (setq res (cons (car lst) nil))
- (while (setq lst (cdr lst))
- (if
- (and
- (setq f (car res))
- (>= (+ (+ (car f) (cadr f)) fuzz) (caar lst)))
- (setq res (cons
- (list
- (caar res)
- (max
- (+ (cadar lst) (- (caar lst) (caar res)))
- (cadar res))
- (last (car res)))
- (cdr res)))
- (setq res (cons (car lst) res))))
- (reverse res)
- )
- (princ "\n结果:")(princ (apply 'append (mapcar 'join-line waco1)))
- (princ)
非得有现成的函数才会用容差吗?
(>= (+ (+ (car f) (cadr f)) fuzz) (caar lst)))
|