/** 
 *  BlackHole Source File
 *
 *  GNU Copyright (C) 2008  Gaspar Sinai gaspar(at)adys.org 
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, version 2,
 *  dated June 1991. See file COPYYING for details.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package sinai.gaspar.blackhole;

import java.awt.Panel;

/**
 * Make a coordinate transformation, so that 
 * a square x,y object becomes a circle.
 * FIXME: this class is currently not used.
 * @author Gaspar Sinai
 * @version 2008-04-30
 */
public class Circle  {
    // resolution * sinAtan values.
    final int resolution;
    final long cosAtan[];

    public Circle (int resolution) {
        this.resolution = resolution;
        cosAtan = new long[resolution+1];
        for (int i=0; i<=resolution; i++) {
            cosAtan[i] = (long) ((double) resolution 
                * Math.cos (Math.atan ((double) i / (double) resolution)));
        }
    }

    public long convertX (long x, long y) {
        if (x==0) return 0L;
        if (y==0) return x; 
        long cx = (x < 0) ? -x : x;
        long cy = (y < 0) ? -y : y;
        long tg = (cx < cy) ? (resolution * cx) / cy : (resolution * cy) / cx;
        return (cosAtan[(int)tg] * x) / resolution;
    }

    public long convertY (long x, long y) {
        if (y==0) return 0L;
        if (x==0) return y;
        long cx = (x < 0) ? -x : x;
        long cy = (y < 0) ? -y : y;
        long tg = (cx < cy) ? resolution * cx / cy : (resolution * cy) / cx;
        return (cosAtan[(int)tg] * y) / resolution;
    }
}
