马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
![](source/plugin/imc_colorcode/images/loading.gif) - (defun XD::Math:SnapNumber (n Ln / _Positions Ld rtn)
- (defun _Positions (x lst / p) ; MP ;; find all the positions of x
- ; in lst ;; (_Positions 1 '(0 0 1 0
- ; 0 1)) >> (2 5)
- (if (setq p (vl-position x lst))
- ((lambda (lst result)
- (while (setq p (vl-position x lst))
- (setq result (cons (+ 1 p (car result)) result)
- lst (cdr (member x lst))
- )
- )
- (reverse result)
- )
- (cdr (member x lst))
- (list p)
- )
- )
- )
- (cond
- ((or
- (not (numberp n))
- (not (vl-every 'numberp Ln))
- )
- (princ "\nInvalid inputs.")
- nil
- )
- ((setq Ld (mapcar
- '(lambda (x)
- (abs (- n x))
- )
- Ln
- )
- )
- (setq rtn (mapcar
- '(lambda (x)
- (nth x Ln)
- )
- (_Positions (apply
- 'min
- Ld
- ) Ld
- )
- )
- )
- )
- )
- (cond
- ((not rtn)
- nil
- )
- ((= 1 (length rtn))
- (car rtn)
- )
- (rtn)
- )
- )
命令: (XD::MATH:SNAPNUMBER 4 '(1 3 5 6))
(3 5)
命令: (XD::MATH:SNAPNUMBER 4.1 '(1 3 5 6))
5
命令: (XD::MATH:SNAPNUMBER 23 '(0 15 30 45 60 75 90))
30
|