Example #1
0
        public static CharComparer Create([NotNull] System.StringComparer stringComparer)
        {
            if (stringComparer == null)
            {
                throw new ArgumentNullException(nameof(stringComparer));
            }

            // Handle common equivalents.
            if (stringComparer.Equals(System.StringComparer.InvariantCulture))
            {
                return(InvariantCulture);
            }
            if (stringComparer.Equals(System.StringComparer.InvariantCultureIgnoreCase))
            {
                return(InvariantCultureIgnoreCase);
            }
            if (stringComparer.Equals(System.StringComparer.Ordinal))
            {
                return(Ordinal);
            }
            if (stringComparer.Equals(System.StringComparer.OrdinalIgnoreCase))
            {
                return(OrdinalIgnoreCase);
            }

            // Build a comparer based on the string comparer.
            return(new StringComparer(stringComparer));
        }
Example #2
0
    public static void Read(BinaryValueReader reader, out System.StringComparer value)
    {
        byte comparerKey;

        reader.Read(out comparerKey);
        value = ByteToStringComparerMap[comparerKey] as System.StringComparer;
    }
Example #3
0
    public static void Write(BinaryValueWriter writer, System.StringComparer value)
    {
        // If System.StringComparer is not one of the 6 we recognize, comparerKey should be 0.
        byte comparerKey;

        StringComparerToByteMap.TryGetValue(value as System.Collections.Generic.IEqualityComparer <string> ?? System.Collections.Generic.EqualityComparer <string> .Default, out comparerKey);
        writer.Write(comparerKey);
    }
Example #4
0
        internal StringComparerAndComparison(StringComparer comparer, StringComparison comparison)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            Comparer   = comparer;
            Comparison = comparison;
        }
Example #5
0
 public static void InitSystemLib(System.StringComparer string_comparer)
 {
     _string_comparer = string_comparer;
 }
Example #6
0
 private StringComparer(StringComparison stringComparison)
 {
     this.stringComparison = stringComparison;
     this.stringComparer   = GetMatchingStringComparer(stringComparison);
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CharComparer"/> class.
 /// </summary>
 /// <param name="stringComparer">The string comparer to use.</param>
 public StringComparer([NotNull] System.StringComparer stringComparer)
 {
     _stringComparer = stringComparer;
 }
        internal StringComparerAndComparison(StringComparer comparer, StringComparison comparison)
        {
            if (comparer == null) throw new ArgumentNullException(nameof(comparer));

            Comparer = comparer;
            Comparison = comparison;
        }
Example #9
0
 // Gets a hash code for this string and this comparison. If strings A and B and comparition C are such
 // that String.Equals(A, B, C), then they will return the same hash code with this comparison C.
 public int GetHashCode(StringComparison comparisonType) => StringComparer.FromComparison(comparisonType).GetHashCode(this);
    GameObject RenderMolecule(List <Atom> Atoms, List <Bond> Bonds)
    {
        // this is  a parent gameobj that includes all atoms and bonds
        GameObject molecule = new GameObject("Molecule" + Random.Range(0, 100).ToString());


        var Balls        = new List <GameObject>(Atoms.Count);
        var Sticks       = new List <GameObject>(Bonds.Count);
        var Hydrogens    = new List <GameObject>();
        var Carbons      = new List <GameObject>();
        var Nitrogens    = new List <GameObject>();
        var Phorphoruses = new List <GameObject>();
        var Sulphurs     = new List <GameObject>();
        var Oxygens      = new List <GameObject>();


        //Use StringComparer
        System.StringComparer comparer = System.StringComparer.OrdinalIgnoreCase;


        // draw atoms
        for (int a = 0; a < Atoms.Count; a++)
        {
            GameObject sphere;
            string     ele = Atoms[a].Element;
            Debug.Log("ele".GetHashCode());

            // carbon as cube // but dont knw mght go against convention
            //if (strCompare(ele,"C"))
            //{
            //    sphere = Instantiate<GameObject>(Cube);
            //    Debug.Log("C deetcted");
            //}
            //else

            //{
            //    sphere = Instantiate<GameObject>(polySphere);
            //}

            sphere = Instantiate <GameObject>(polySphere);
            Balls.Add(sphere);
            //GameObject sphere =  GameObject.CreatePrimitive(PrimitiveType.Sphere);
            sphere.transform.position = Atoms[a].Position;
            sphere.transform.SetParent(molecule.transform, false);
            // func call to color atom
            ColorMe(sphere, Atoms[a]);
        }


        // draw bonds
        for (int b = 0; b < Bonds.Count; b++)
        {
            var atomIndex1 = Bonds[b].From - 1;
            var atomIndex2 = Bonds[b].To - 1;

            var from = Atoms[atomIndex1].Position;
            var to   = Atoms[atomIndex2].Position;

            //draw bonds

            GameObject cylin1 = Instantiate <GameObject>(polyCylinder);
            cylin1.GetComponent <Renderer>().material.color = Color.black;
            //Debug.Log(Vector3.Distance(from, to));
            cylin1.transform.position = (to - from) / 2.0f + from;

            var scale     = cylin1.transform.localScale;
            var bondWidth = 6.0f;

            scale.x = bondWidth;
            scale.y = bondWidth;
            scale.z = (to - from).magnitude * 32;

            cylin1.transform.localScale = scale;
            cylin1.transform.rotation   = Quaternion.FromToRotation(Vector3.up, to - from);
            cylin1.transform.Rotate(90, 0, 0);
            cylin1.transform.SetParent(molecule.transform, false);

            // renders second bond if exist
            if (Bonds[b].BondCount == 2)
            {
                GameObject cylin2 = Instantiate <GameObject>(secondBond);
                cylin2.GetComponent <Renderer>().material.color = Color.black;
                //Debug.Log(Vector3.Distance(from, to));
                var offset = cylin2.transform.up;
                cylin2.transform.position = (to - from) / 2.0f + from + offset * 0.15f;
                scale     = cylin2.transform.localScale;
                bondWidth = 6.0f;

                scale.x = bondWidth;
                scale.y = bondWidth;
                scale.z = (to - from).magnitude * 32;


                cylin2.transform.localScale = scale;
                cylin2.transform.rotation   = Quaternion.FromToRotation(Vector3.up, to - from);
                cylin2.transform.Rotate(90, 0, 0);
                cylin2.transform.SetParent(molecule.transform, false);
                cylin1.transform.position -= offset * 0.15f;
            }
        }

        // use later
        //molecule.transform.position = new Vector3(0,0,-15);

        return(molecule);
    }