/*
 * $Source: /mit/jik/sipbsrc/src/xscreensaver/RCS/scaling.c,v $
 * $Author: jik $
 *
 * This file is part of xscreensaver.  It contains code for figuring
 * out screen aspect ratios.  This stuff is a bit of magic that
 * probably doesn't work very well since the X server invariably seems
 * to have incorrect numbers for its aspect ratios, but it makes me
 * sleep better at night to know it's here.
 *
 * Author: Jonathan Kamens, MIT Project Athena and
 *                          MIT Student Information Processing Board
 *
 * Copyright (c) 1989 by Jonathan Kamens.  This code may be
 * distributed freely as long as this notice is kept intact in its
 * entirety and every effort is made to send all corrections and
 * improvements to the code back to the author.  Also, don't try to
 * make any money off of it or pretend that you wrote it.
 */

#if !defined(lint) && !defined(SABER)
     static char rcsid_scaling_c[] = "$Header: /mit/jik/sipbsrc/src/xscreensaver/RCS/scaling.c,v 1.10 1992/05/03 15:59:36 jik Exp $";
#endif

#include "xsaver.h"
#include <math.h>
#include "globals.h"

double cm_per_pixel_x;
double cm_per_pixel_y;

void init_scaling()
{
     cm_per_pixel_x = (double) DisplayWidthMM(dpy, screen) /
	  display_width / (double) 10.0;
     cm_per_pixel_y = (double) DisplayHeightMM(dpy, screen) /
	  display_height / (double) 10.0;
}

double cm_x(x)
int x;
{
     return((double) (cm_per_pixel_x * x));
}

double cm_y(y)
int y;
{
     return((double) (cm_per_pixel_y * y));
}

     
double line_length_cm(x, y)
int x, y;
{
     return(sqrt((double) (pow(cm_x(x), 2.0) + pow(cm_y(y), 2.0))));
}


int calc_delay(x_off, y_off, velocity)
int x_off, y_off, velocity;
{
     double line_length;
     double delay_minutes, delay_seconds, delay_milliseconds;
     int delay;
     
     line_length = line_length_cm(x_off, y_off);
     delay_minutes = line_length / (double) velocity;
     delay_seconds = 60.0 * delay_minutes;
     delay_milliseconds = delay_seconds * 1000;
     return (delay_milliseconds);
}

