#include "tree.h"
#include "ellipse.h"
#include "treelps.h"

/* Traverses `tree' in order and generates an array of `ellipse's 
   corresponding to ellipses centred at the points in `tree' with semi-x 
   axis a  and semi-y axis b */
void makeellipseinorder(point *tree,
			ellipse *ellipses,
			int *counter,
			double a,
			double b
			)
{
  register point *node;
  register point *nextnode;

  if(tree == NULL)
    return;

  node=left(tree);
  makeellipse(node,&(ellipses[*counter]),a,b);
  ++(*counter);

  while(node->right != NULL){
    nextnode=node->right;

    if(!(node->tag & 1)){       /* If node->right is not a thread */
      while(!(nextnode->tag & 2)) /* while nextnode->left is not */
                                  /* a thread */
	nextnode=nextnode->left;
    }

    node=nextnode;
    makeellipse(node,&(ellipses[*counter]),a,b);
    ++(*counter);
  }
}

/* Traverses `tree' in order and generates an array of `ellipse's 
   corresponding to the ellipses centred at the points in `tree' with 
   semi-x axis a and semi-y axis b */
void makeellipseinorder_min(point *tree,
			    ellipse *ellipses,
			    int *counter,
			    double a,
			    double b
			    )
{
  register point *node;
  register point *nextnode;

  if(tree == NULL)
    return;

  node=left(tree);
  if(node->min_life){
    makeellipse(node,&(ellipses[*counter]),a,b);
    ++(*counter);
  }

  while(node->right != NULL){
    nextnode=node->right;

    if(!(node->tag & 1)){       /* If node->right is not a thread */
      while(!(nextnode->tag & 2))  /* while nextnode->left is not */
                                   /* a thread */
	nextnode=nextnode->left;
    }

    node=nextnode;
    if(node->min_life){
      makeellipse(node,&(ellipses[*counter]),a,b);
      ++(*counter);
    }
  }
}
