Пример #1
0
 static public int DoubleCompare(MyPointDouble pt1, MyPointDouble pt2)
 {
     if (pt2.x > pt1.x)
     {
         return(1);
     }
     if (pt2.x < pt1.x)
     {
         return(-1);
     }
     return(0);
 }
Пример #2
0
 public bool AreEqual(MyPointDouble pt2)
 {
     epsilon = 100 * double.Epsilon;
     if ((Math.Abs(x - pt2.x) < epsilon) && (Math.Abs(y - pt2.y) < epsilon))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
 public int CompareTo(object obj)
 {
     if (obj is MyPointDouble)
     {
         MyPointDouble pt1 = (MyPointDouble)obj;
         if ((pt1.x == x) && (pt1.y == y))
         {
             return(0);
         }
         if ((y > pt1.y) || ((y == pt1.y) && (x > pt1.x)))
         {
             return(1);
         }
         return(-1);
     }
     else
     {
         throw new ArgumentException("object is not MyPointDouble");
     }
 }
Пример #4
0
        /// <summary>
        /// The procedure locates at the argument list the last item whose key is smaller or equal than the itemToFind object - the value 0 is returned if none such item exists.
        /// The method assumes that elements at list are sorted in the ascending order. It isn't however checked by the method.
        /// </summary>
        /// <param mainFile="itemToFind">the item which has to be located</param>
        /// <param mainFile="list">the nonempty list</param>
        /// <returns>The 1-based Number of the last item at the list which is smaller or  equal the itemToFind. If none exists than returns 0.</returns>
        public static int FindAtList(MyPointDouble itemToFind, ref List <ElementPointer> list)
        {
            if (list == null)
            {
                throw new ArgumentNullException();
            }
            if (list.Count == 0)
            {
                throw new ArgumentException("The passed argument is empty");
            }

            //The 1-based Number at the argument list of the FIRST item which is larger than itemToFind and 0 in the case in which such item does not exist
            int FirstLarger = (list.FindIndex(
                                   delegate(ElementPointer SoughtItem)
            {
                return(SoughtItem.LeftDown.CompareTo(itemToFind) > 0);
            }
                                   ) + 1);

            //if FirstLarger==0 then all elements at the list are EQUAL or LESS than itemToFind and the Number of the LAST ITEM at the list should be returned

            if (FirstLarger == 0)
            {
                return(list.Count);
            }

            //if FirstLarger==1 then all elements at the list are LARGER than itemToFind and the VALUE 0 should be returned

            if (FirstLarger == 1)
            {
                return(0);
            }

            //In other cases the element preceding FirstLarger should be returned
            return(FirstLarger - 1);
        }
Пример #5
0
        /// <summary>
        /// It is assumed that the list is sorted with the help of the Sort method (in the increasing order). The procedure locates at the argument list the last item which is smaller than the itemToFind object.
        /// </summary>
        /// <param mainFile="itemToFind">the item which has to be located</param>
        /// <param mainFile="list">the nonempty list</param>
        /// <returns>The 1-based Number of the last item at the list which is smaller or  equal the itemToFind. If none exists than returns 0.</returns>
        public static int FindAtList(MyPointDouble itemToFind, List <MyPointDouble> list)
        {
            if (list == null)
            {
                throw new ArgumentNullException();
            }
            if (list.Count == 0)
            {
                throw new ArgumentException("The passed argument is empty");
            }

            //if itemToFind is smaller than list[0] then return(-1)
            if (itemToFind.CompareTo(list[0]) == -1)
            {
                return(-1);
            }


            if (itemToFind.CompareTo(list[0]) == 0)
            {
                return(-1);
            }



            //if itemToFind is larger than list.Last then return the Number of elements at list
            if ((itemToFind.CompareTo(list.Last()) == 1) || (itemToFind.CompareTo(list.Last()) == 0))
            {
                return(list.Count);
            }



            int Start = 1;
            int End   = list.Count;

            while
            (true)
            {
                if ((End - Start) <= 1)
                {
                    return(Start);
                }

                int Middle = ((Start + End) / 2);


                //if the element at the Middle position is larger than itemToFind then put the value Middle into the variable End
                if (list[Middle - 1].CompareTo(itemToFind) == 1)
                {
                    End = Middle;
                }

                //if the element at the Middle position is larger than itemToFind then put the value Middle into the variable End
                if (list[Middle - 1].CompareTo(itemToFind) == (-1))
                {
                    Start = Middle;
                }

                //if the element at the Middle position has the same value as the itemToFind then look at which position stands the element which is larger than itemToFind

                if (list[Middle - 1].CompareTo(itemToFind) == (0))
                {
                    for (int Iterator = (Middle - 1); Iterator >= 1; Iterator--)
                    {
                        if (list[Iterator - 1].CompareTo(itemToFind) != 0)
                        {
                            return(Iterator);
                        }
                    }
                    return(-1);
                }
            }

            //    return (-1);
        }
Пример #6
0
 public double CosOfAngle(MyPointDouble Vectorg)
 {
     return((this * Vectorg) / (this.Length() * Vectorg.Length()));
 }
Пример #7
0
        public static MyPointDouble operator -(MyPointDouble c1, MyPointDouble c2)
        {
            MyPointDouble ret = new MyPointDouble(c1.x - c2.x, c1.y - c2.y, c1.z - c2.z);

            return(ret);
        }
Пример #8
0
        public static MyPointDouble operator +(MyPointDouble c1, MyPointDouble c2)
        {
            MyPointDouble ret = new MyPointDouble(c1.x + c2.x, c1.y + c2.y, c1.z + c2.z);

            return(ret);
        }
Пример #9
0
 public MyPointDouble(MyPointDouble MPDg)
 {
     x = MPDg.x;
     y = MPDg.y;
     z = MPDg.z;
 }
Пример #10
0
 public double Distance(MyPointDouble ptg)
 {
     return(Math.Sqrt((x - ptg.x) * (x - ptg.x) + (y - ptg.y) * (y - ptg.y) + (z - ptg.z) * (z - ptg.z)));
 }
Пример #11
0
 /// <summary>
 /// Fills the instance with coordinates of the left down point bounding the area in which the element is situated
 /// </summary>
 /// <param mainFile="leftDownX">the abscissa of the element</param>
 /// <param mainFile="leftDownY">the ordinate of the element</param>
 /// <param mainFile="elementNumber">the Number of the element</param>
 public ElementPointer(double leftDownX, double leftDownY, int elementNumber)
 {
     ElementNumber = elementNumber;
     LeftDown      = new MyPointDouble(leftDownX, leftDownY);
 }
Пример #12
0
 /// <summary>
 /// Fills the instance with coordinates of the left down point bounding the area in which the element is situated
 /// </summary>
 /// <param mainFile="leftDown">the "left down" boundary of the element</param>
 /// <param mainFile="elementNumber">the Number of the element</param>
 public ElementPointer(MyPointDouble leftDown, int elementNumber)
 {
     ElementNumber = elementNumber;
     LeftDown      = new MyPointDouble(leftDown);
 }