;;; 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; Package: 2DG; Syntax: Common-Lisp; Base: 10. -*-
(in-package '2DG)

(defun TEST-EDGES-TO-LINE-SEGMENTS (n)
  ;; Test with a single, simple curve.
  (labels ((numbers-from (n1 n2)		; Don't know which is bigger.  Don't include n1 or n2.
	     (if (< n1 n2) (loop for i from (1+ n1) below n2 collecting i)
		 (loop for i from (1+ n2) below n1 collecting i))))
    (let ((bit-array (make-raster-array 128 128 :element-type '(unsigned-byte 1)))
	  (last-y 0))
      (loop for x from 0 to 127
	    doing
	(let ((y (floor (* 127 (sin (* (/ x 127) PI))))))
	  (setf (raster-aref bit-array x y) 1)
	  (when (< 1 (abs (- y last-y)))
	    (loop for y in (numbers-from y last-y)
		  doing
	      (setf (raster-aref bit-array x y) 1)))
	  (setf last-y y)))
      (edges-to-line-segments bit-array n))))

(defun TEST-EDGE-IMAGE-STRINGS ()
  ;; Test with a single, simple curve.
  (labels ((numbers-from (n1 n2)		; Don't know which is bigger.  Don't include n1 or n2.
	     (if (< n1 n2) (loop for i from (1+ n1) below n2 collecting i)
		 (loop for i from (1+ n2) below n1 collecting i))))
    (let ((bit-array (make-raster-array 128 128 :element-type '(unsigned-byte 1)))
	  (last-y 0))
      (loop for x from 0 to 127
	    doing
	(let ((y (floor (* 127 (sin (* (/ x 127) PI))))))
	  (setf (raster-aref bit-array x y) 1)
	  (when (< 1 (abs (- y last-y)))
	    (loop for y in (numbers-from y last-y)
		  doing
	      (setf (raster-aref bit-array x y) 1)))
	  (setf last-y y)))
      (edge-image-strings bit-array))))

(defun TEST-EDGES-TO-LINE-SEGMENTS2 (n)
  (let ((bit-array (make-raster-array 128 128 :element-type '(unsigned-byte 1)))
	(y 0))
    (loop for x1 from 0 to 63
	  for x2 from 127 downto 64
	  doing
      (setf (raster-aref bit-array x1 y) 1)
      (setf (raster-aref bit-array x2 y) 1)
      (when (= (random 2) 0)
	(setf y (1+ y))))
    (edges-to-line-segments bit-array n)))
