/*   @(#) $Header: itrig.h,v  abrown Exp $
 * Author:
 *	"Allen Brown" http://brown.armoredpenguin.com/~abrown/contact.html
 * Description:
 *   Header file for integer trigonometry functions.
 *
 * Copyright (C) 2006,2007,2008 Allen Brown
 *
 * License:
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation; either version 2
 *   of the License, or (at your option) any later version.
 *   
 *   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.,
 *     51 Franklin Street, Fifth Floor,
 *     Boston, MA  02110-1301, USA.
 */
#ifndef ITRIG_H
  #define ITRIG_H

  #include "varsizes.h"

  #define NavUnitPerDegree 10 /* Each angle degree divided into tenths. */
  #define ITRIGMULT 255 /* Values in table are scaled */
  #define ITRIG_SIN 0
  #define ITRIG_COS 1
  #define ITRIG_QUADRANT 2
  #define ITRIG_ATAN2W 0
  #define ITRIG_HEADING2W 1
  #define ITRIG_RELATIVE2 0

/* --------------------------------------------------------------
 * ISIN() and ICOS() return this sine and cosine of the angle a.
 *   The returned value is scaled by 100 to reduce roundoff error.
 *   The value of a is scaled by NavUnitPerDegree.
 */
  #define ICOS(a) itrig(ITRIG_COS,(a))
  #define ISIN(a) itrig(ITRIG_SIN,(a))
/* --------------------------------------------------------------
 * IQUADRANT() returns a number 1-4 to indicate which
 *   quadrant of the cartesian coord system the angle points into.
 */
  #define IQUADRANT(n) itrig(ITRIG_QUADRANT,(n))
/* --------------------------------------------------------------
 * IRELATIVE() returns an angle.  That angle is functionally
 *   equivalent to the angle (a1).  But it is shifted to be
 *   within 180 degrees of (a2).  For instance, if a1=-3600
 *   (-360 degrees) and a2=400 (40 degrees), IRELATIVE()
 *   will return 0.
 */
  #define IRELATIVE(a1,a2) itrig2(ITRIG_RELATIVE2,(a1),(a2))
/* --------------------------------------------------------------
 * atan2 defines angles starting on the +x axis and
 * turning counter-clockwise.
 * heading2 defines angles starting on the +y axis
 * and turning clockwise.
 * Note that IATAN2(), IHEADING(), and itrig2w() follow
 * the lead of atan2() in putting the "y" before the "x" in
 * the parameter list.  All other functions place "x" first.
 */
  #define IATAN2(y,x) itrig2w(ITRIG_ATAN2W,(y),(x))
  #define IHEADING2(y,x) itrig2w(ITRIG_HEADING2W,(y),(x))
//#define abs(a) ((a)>0?(a):(-a))

/* --------------------------------------------------------------
 * itrig(), itrig2(), and itrig2w() are function calls used
 * by the macros defined above.  Users should use the macros
 * and not call the functions directly.
 */
  int16 itrig(int16 trigtype, int16 angle);
  int16 itrig2(int16 trigtype, int16 angle1, int16 angle2);
  int16 itrig2w(int16 trigtype, int32 y, int32 x);
#endif
/*
 * $Log: itrig.h,v $
 * Revision 1.6  2006/03/06 19:27:35  abrown
 * Add functions for IQUADRANT(), IRELATIVE().  Remap constants for
 * existing functions.  Change itrig2() to itrig2w() so we make space
 * for a new itrig2() that doesn't take wide parameters.  It does
 * better angle comparison.
 * Remap the cos/sin code with a fully decoded switch in order to
 * make space for IQUADRANT() code.
 *
 * Revision 1.5  2006/03/05 20:30:47  abrown
 * Major cleanup to IATAN2():  Change order of y,x parameters to
 * match atan2().  Make table size configurable.  Fix quadrant
 * decision code.  Test all four quadrants.  (All 8 octants, really.)
 * Report test results with accuracy numbers for each trig function.
 * Create IHEADING2() type function.
 *
 * Revision 1.4  2006/02/24 02:09:05  abrown
 * Get started on adding an atan2 function.
 *
 * Revision 1.3  2006/02/21 22:48:44  abrown
 * Use variable types defined in varsizes.h.
 *
 * Revision 1.2  2006/02/20 22:08:05  abrown
 * Improve accuracy down to 0.35% error (was 0.85%).
 *
 * Revision 1.1  2006/02/20 20:36:39  abrown
 * Create integer trig function from the old quad_trig in quadrature.c.
 *
 */

