;;; This software is being provided to you, the LICENSEE, by the
;;; Massachusetts Institute of Technology (M.I.T.), and the NEC Research
;;; Institute (NECI) under the following license.  By obtaining, using
;;; and/or copying this software, you agree that you have read,
;;; understood, and will comply with these terms and conditions:
;;; 
;;; Permission to use, copy, modify and distribute, including the right to
;;; grant others rights to distribute at any tier, this software and its
;;; documentation for research purposes only and without fee or royalty is
;;; hereby granted, provided that you agree to comply with the following
;;; copyright notice and statements, including the disclaimer, and that
;;; the same appear on ALL copies of the software and documentation,
;;; including modifications that you make for internal use or for
;;; distribution:
;;; 
;;; Copyright 1995 by the Massachusetts Institute of Technology.  All
;;; rights reserved.  Copyright 1995 by NEC Research Institute Inc. All
;;; rights reserved
;;; 
;;; THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. and NECI MAKE NO
;;; REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way of example,
;;; but not limitation, M.I.T. and NECI MAKE NO REPRESENTATIONS OR
;;; WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
;;; THAT THE USE OF THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT
;;; INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER
;;; RIGHTS.
;;; 
;;; The name of the Massachusetts Institute of Technology or M.I.T., or
;;; NEC Research Institute, or NECI may NOT be used in advertising or
;;; publicity pertaining to distribution of the software.  Title to
;;; copyright in this software and any associated documentation shall at
;;; all times remain with M.I.T. and NECI, and USER agrees to preserve
;;; same.
;;; 

;;; -*- Mode:LISP; Base:10; Package:2DG; Syntax:Common-lisp; Lowercase:Yes -*-

(defun TEST-LEAST-SQUARES-RHO-THETA (&optional rot (angle 0))
  (let ((line (make-line (make-point 0 0) (make-point (* 10 (cos angle)) (* 10 (sin angle)))))
	(dy 0)); (random-between 0 .1)))
    (let ((pts (loop for x from 0 below 10 by .1
		     collecting
		     (if (= 0 (mod (* x 10) 2))
			 (make-point x dy)
			 (make-point x (- dy))))))
      (let* ((pose-vars (when rot (random-pose-vars)))
	     (line (if rot (apply-pose-vars line pose-vars) line))
	     (pts (if rot (loop for pt in pts collecting (apply-pose-vars pt pose-vars)) pts)))
	(let ((min-line (car (least-squares-rho-theta pts))))
	(list min-line line dy (average (loop for p in pts collecting (distance p line)))
	      (average (loop for p in pts collecting (distance p min-line))))))))
  )

(defun TEST-LEAST-SQUARES-RHO-THETA-2 (&optional (dx 0) (dy 0) (angle 0))
  (let ((line (make-line (make-point dx dy) (make-point (+ dx (* 10 (cos angle))) (+ dy (* 10 (sin angle)))))))
    (let ((pts (loop for d from 0 below 10 by .1
		     collecting
		       (make-point (+ dx (* d (cos angle))) (+ dy (* d (sin angle)))))))
      (let ((min-line (car (least-squares-rho-theta pts))))
	(list line min-line (average (loop for p in pts collecting (distance p line)))
	      (average (loop for p in pts collecting (distance p min-line))))))))

(defun TEST-LEAST-SQUARES-SLOPE-INTERCEPT-2 (&optional (dx 0) (dy 0) (angle 0))
  (let ((line (make-line (make-point dx dy) (make-point (+ dx (* 10 (cos angle))) (+ dy (* 10 (sin angle)))))))
    (let ((pts (loop for d from 0 below 10 by .1
		     collecting
		       (make-point (+ dx (* d (cos angle))) (+ dy (* d (sin angle)))))))
      (let ((min-line (car (least-squares-slope-intercept pts))))
	(list line min-line (average (loop for p in pts collecting (distance p line)))
	      (average (loop for p in pts collecting (distance p min-line))))))))

