#region Written by Tamas Budavari (budavari@jhu.edu)
/**
 * SphericalLib.Root
 * 
 * SphericalLib is a .NET library to deal with geometry on the unit sphere.
 * It is intented to be used for complex survey footprint descriptions in
 * standalone applications as well as in web services and perhaps Yukon.
 * 
 * Written by Tamas Budavari (budavari@pha.jhu.edu)
 * See bottom of file for revision history
 * 
 * Current revision:
 *   ID:          $Id: Root.cs,v 1.1.1.1 2006/11/14 02:56:39 gupchup Exp $
 *   Revision:    $Revision: 1.1.1.1 $
 *   Date:        $Date: 2006/11/14 02:56:39 $
 */
using System;
using System.Collections.Generic;
#endregion

namespace Spherical
{
	/// <summary>
	/// A root is an intersection of two circles in a convex
	/// </summary>
    [CLSCompliant(true)]
	internal class Root
    {
        #region Private members

        private Cartesian point;
		private int parent1, parent2;
		private List<int> coveredBy;
        private List<int> maskedBy;
		private RootStatus status;
		private int good;

        #endregion
        #region Public properties

        public Cartesian Point
        {
            get { return point; }
            set { point = value; }
        }

        public int Parent1
        {
            get { return parent1; }
        }

        public int Parent2
        {
            get { return parent2; }
        }

        public RootStatus Status
        {
            get { return status; }
        }

        public int Good
        {
            get { return good; }
            set { good = value; }
        }

        #endregion
        #region Constructor

        /// <summary>
        /// Create a root from the point, its parents and use the given convex 
        /// to set the status and store which convex covers and masks it.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="c"></param>
        /// <param name="parent1"></param>
        /// <param name="parent2"></param>
		public Root (Cartesian point, Convex c, double tolerance, int parent1, int parent2)
		{
			this.point = point;
			this.parent1 = parent1;
			this.parent2 = parent2;
            c.IndexCoversMasks(point, tolerance, out coveredBy, out maskedBy);
			this.status = RootStatus.Unknown;

			// if all halfspaces cover it, then inside. Otherwise outside
			if (this.coveredBy.Count == c.HalfspaceList.Count) 		
				this.status = RootStatus.Inside;
			else  	
				this.status = RootStatus.Outside;
        }

        #endregion
        #region Methods

        public bool MaskedByExists(Predicate<int> match)
        {
            return maskedBy.Exists(match);
        }

        #endregion
        #region ToString and revision

        /// <summary>
        /// String representation
        /// </summary>
        /// <returns></returns>
		public override string ToString()
		{
			return String.Format("{0} ({1},{2}) {3}", point, parent1,parent2, status);
		}

		/// <summary>
		/// Revision from CVS
		/// </summary>
		public static string Revision
		{
			get	{ return "$Revision: 1.1.1.1 $"; }
        }

        #endregion
    }
}

#region Revision History
/* Revision History

        $Log: Root.cs,v $
        Revision 1.1.1.1  2006/11/14 02:56:39  gupchup
        no message

        Revision 1.4  2006/05/22 18:55:54  budavari
        BinaryFormatter now works with Region and co

        Revision 1.3  2006/04/19 16:51:01  budavari
        EVerything is now CLS compliant

        Revision 1.2  2006/02/28 16:26:59  budavari
        Major revision: public properties

        Revision 1.1  2006/01/24 15:56:05  budavari
        Re-structured directory layout to accommodate more projects

        Revision 1.7  2005/12/02 21:32:30  budavari
        member variables do start with small letter ;-) XML still the same

        Revision 1.6  2005/12/01 22:34:57  budavari
        Area struct added and fully functional

        Revision 1.5  2005/11/30 20:50:28  budavari
        Cosmetics... #region specifications etc added

        Revision 1.4  2005/11/30 15:52:42  budavari
        Doc added

        Revision 1.3  2005/11/30 15:31:58  budavari
        Header changes

        Revision 1.2  2005/11/15 22:20:20  budavari
        Using Generics - almost there

        Revision 1.1  2005/11/15 15:25:36  budavari
        Everything is a class, things are coming together for area computation, etc. Will moved to C# 2.0

 */
#endregion