예제 #1
0
        public override VisualUnit GetUnit(Point position)
        {
            if (First.Contains(position))
            {
                return(First);
            }
            if (Last.Contains(position))
            {
                return(Last);
            }

            double angleA = Math.Abs(Vector.AngleBetween(position - First.Position, Last.Position - First.Position));

            if (angleA > 90)
            {
                return(null);
            }

            double angleB = Math.Abs(Vector.AngleBetween(position - Last.Position, First.Position - Last.Position));

            if (angleB > 90)
            {
                return(null);
            }

            double h = (First.Position - position).Length * Math.Sin(angleA * Math.PI / 180);

            if (h <= Thickness)
            {
                return(this);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Name Constructor from String.
        /// </summary>
        /// <param name="NameParts">String name must be in American Format</param>
        public Name(String NameParts)
        {
            if (NameParts.Length <= 1)
            {
                return;
            }
            List <String> nameParts = new List <String>(Tools.Tokenize(NameParts, " ")); //tokenizes name into multiple names

            Original = NameParts;                                                        //sets original name value
            Match m;

            #region Prefix
            String Pattern = @"\b(([Dr].)|([Mr?s?]{2,3}))\.";         //regex pattern for prefix
            m = new Regex(Pattern).Match(nameParts.First <String>()); //checks for match to prefix pattern only in the first element of the string array
            if (m.Success)                                            //if match found
            {
                Prefix = nameParts.First <String>();                  //set prefix
                nameParts.Remove(nameParts[0]);                       //remove prefix from name array
            }
            if (nameParts.Count == 0)                                 //if name parts is empty return
            {
                return;
            }
            #endregion
            #region Suffix
            Pattern = @"\b(([iIvV]+(?!\.))|([JR]r\.)|([PMJ].[dD]?))\Z";    //pattern for suffix
            m       = new Regex(Pattern).Match(nameParts.Last <String>()); //checks only last index of name array
            if (m.Success)                                                 //if match found
            {
                Suffix = nameParts.Last <String>();                        //sets suffix
                nameParts.Remove(nameParts.Last <String>());               //removes suffix from name parts
            }
            if (Suffix != null)                                            //if suffix isnt null
            {
                Suffix = ", " + Suffix;                                    //adds comma and space for end of name
            }
            if (nameParts.Count == 0)
            {
                return;
            }
            #endregion
            #region Last Name
            Pattern = @"\w+\,";//regex pattern for name
            Regex lastRegex = new Regex(Pattern);
            Last = null;
            foreach (String namePart in nameParts)//looks for pattern match in rest of array
            {
                m = lastRegex.Match(namePart);
                if (m.Success && Last == null)//if there is a match
                {
                    Last = namePart;
                }
            }
            if (Last == null)                       //if last is null
            {
                Last = nameParts.Last <String>();   //sets last
            }
            nameParts.Remove(Last);                 //removes last name from name array
            if (Last.Contains(",") && Last != null) //if last contains a comma and isnt null
            {
                Last = Last.Substring(0, Last.Length - 1);
            }
            if (nameParts.Count == 0)//if no more parts of name then return
            {
                return;
            }
            #endregion
            #region First Name
            Pattern = @"\b(([\w]+\.?.(?!\,))|((?<=\,\s)\w+))";//regex pattern for First names
            Regex firstRegex = new Regex(Pattern);
            First = null;
            foreach (String namePart in nameParts)//looks for first name
            {
                m = firstRegex.Match(namePart);
                if (m.Success && First == null)//if first name is found
                {
                    First = namePart;
                }
            }
            nameParts.Remove(First);//removes first name from name parts
            if (First.Contains(",") && First != null)
            {
                Last = First.Substring(0, Last.Length - 1);
            }
            #endregion
            #region Middle Name
            Middle = null;
            nameParts.ForEach(part => Middle = Middle + part.Trim());//sets rest of name to be the middle
            if (Middle != null)
            {
                Middle = Middle + " ";//sets spaces for middle name string
            }
            #endregion
        }
예제 #3
0
 public override bool Contains(Vector2 point) => First.Contains(point) || Second.Contains(point);