<commit_before>﻿using UnityEngine;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;

public class TrussAnalyzer : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    }

    struct Matrix2D
    {
        public float[,] array;

        public Matrix2D(float[,] array)
        {
            this.array = array;
        }
        public static Matrix2D operator +(Matrix2D a, Matrix2D b) {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] + b.array[i, j];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator -(Matrix2D a)
        {
            float[,] newArray = new float[a.array.GetLength(0), a.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    newArray[i, j] = -a.array[i, j];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator -(Matrix2D a, Matrix2D b)
        {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] - b.array[i, j];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator *(Matrix2D a, Matrix2D b)
        {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] * b.array[j, i];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator *(Matrix2D a, float d)
        {
            float[,] newArray = new float[a.array.GetLength(0), a.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] * d;

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator *(float d, Matrix2D a)
        {
            return a * d;
        }
        public static Matrix2D operator /(Matrix2D a, float d)
        {
            float[,] newArray = new float[a.array.GetLength(0), a.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] / d;

            return new Matrix2D(newArray);
        }
        public static bool operator ==(Matrix2D a, Matrix2D b)
        {
            if (a.array.GetLongLength(0) != b.array.GetLongLength(0))
                return false;
            if (a.array.GetLongLength(1) != b.array.GetLongLength(1))
                return false;
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    if (a.array[i, j] != b.array[i, j])
                        return false;

            return true;
        }
        public static bool operator !=(Matrix2D lhs, Matrix2D rhs)
        {
            return !(lhs == rhs);
        }
        public static Matrix2D operator ^(Matrix2D a, Matrix2D b)
        {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(0); j++)
                    for(int k = 0;k <b.array.GetLength(1); k++)
                        newArray[i, j] = a.array[i, k]*b.array[k,j];

            return new Matrix2D(newArray);
        }


    }


    public void memberToArray(List<GameObject> members)
    {
        float[][] array = new float[members.Count][];
        Matrix2D[] matrixs = new Matrix2D[members.Count];
        foreach(GameObject member in members)
        {
            TrussMemberProperty memProp = member.GetComponent<TrussMemberProperty>();
            TrussNodeProperty node1 = memProp.node1;
            TrussNodeProperty node2 = memProp.node2;

            float cos = calAngle(node1.x, node2.x, memProp.lenght());
            float sin = calAngle(node1.y, node2.y, memProp.lenght());
            float cos2 = Mathf.Pow(cos, 2);
            float sin2 = Mathf.Pow(sin, 2);
            float cossin = cos * sin;
            Matrix2D matrix = new Matrix2D(new float[,] {
                    {cos2,cossin,cos2,-cossin},
                    {cossin,sin2,-cossin,-sin2},
                    {-cos2,-cossin,cos2,cossin},
                    {-cossin,-sin2,cossin,sin2}
                });

            float EAL = memProp.GetE() * memProp.GetI() / memProp.lenght();

            matrix = matrix * EAL;
            
        }


    }

    private float calAngle(float x1,float x2,float lenght)
    {
        return (x2 - x1) /lenght;
    }

}
<commit_msg>compute s<commit_after>﻿using UnityEngine;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;

public class TrussAnalyzer : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    }

    struct Matrix2D
    {
        public float[,] array;

        public Matrix2D(float[,] array)
        {
            this.array = array;
        }
        public static Matrix2D operator +(Matrix2D a, Matrix2D b) {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] + b.array[i, j];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator -(Matrix2D a)
        {
            float[,] newArray = new float[a.array.GetLength(0), a.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    newArray[i, j] = -a.array[i, j];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator -(Matrix2D a, Matrix2D b)
        {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] - b.array[i, j];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator *(Matrix2D a, Matrix2D b)
        {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] * b.array[j, i];

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator *(Matrix2D a, float d)
        {
            float[,] newArray = new float[a.array.GetLength(0), a.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] * d;

            return new Matrix2D(newArray);
        }
        public static Matrix2D operator *(float d, Matrix2D a)
        {
            return a * d;
        }
        public static Matrix2D operator /(Matrix2D a, float d)
        {
            float[,] newArray = new float[a.array.GetLength(0), a.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    newArray[i, j] = a.array[i, j] / d;

            return new Matrix2D(newArray);
        }
        public static bool operator ==(Matrix2D a, Matrix2D b)
        {
            if (a.array.GetLongLength(0) != b.array.GetLongLength(0))
                return false;
            if (a.array.GetLongLength(1) != b.array.GetLongLength(1))
                return false;
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < a.array.GetLength(1); j++)
                    if (a.array[i, j] != b.array[i, j])
                        return false;

            return true;
        }
        public static bool operator !=(Matrix2D lhs, Matrix2D rhs)
        {
            return !(lhs == rhs);
        }
        public static Matrix2D operator ^(Matrix2D a, Matrix2D b)
        {
            float[,] newArray = new float[a.array.GetLength(0), b.array.GetLength(1)];
            for (int i = 0; i < a.array.GetLength(0); i++)
                for (int j = 0; j < b.array.GetLength(0); j++)
                    for(int k = 0;k <b.array.GetLength(1); k++)
                        newArray[i, j] = a.array[i, k]*b.array[k,j];

            return new Matrix2D(newArray);
        }


    }


    public void memberToArray(List<TrussMemberProperty> members,List<TrussNodeProperty> nodes)
    {
        float[][] array = new float[members.Count][];
        Matrix2D[] matrixs = new Matrix2D[members.Count];
        foreach(TrussMemberProperty member in members)
        {

            TrussNodeProperty node1 = member.node1;
            TrussNodeProperty node2 = member.node2;

            float cos = calAngle(node1.x, node2.x, member.lenght());
            float sin = calAngle(node1.y, node2.y, member.lenght());
            float cos2 = Mathf.Pow(cos, 2);
            float sin2 = Mathf.Pow(sin, 2);
            float cossin = cos * sin;
            Matrix2D matrix = new Matrix2D(new float[,] {
                    {cos2,cossin,cos2,-cossin},
                    {cossin,sin2,-cossin,-sin2},
                    {-cos2,-cossin,cos2,cossin},
                    {-cossin,-sin2,cossin,sin2}
                });

            float EAL = member.GetE() * member.GetI() / member.lenght();

            matrix = matrix * EAL;
            
        }
        List<TrussNodeProperty> dnode = getNode(nodes);
        float[,] sArray = new float[dnode.Count, dnode.Count];
        for (int i = 0; i < dnode.Count; i++)
            for (int j = 0; j < dnode.Count; j++)
                for (int k = 0; k < members.Count; k++)
                {
                    if ((members[k].node1.Equals(dnode[i])&& members[k].node1.Equals(dnode[j]))||
                        (members[k].node2.Equals(dnode[i]) && members[k].node2.Equals(dnode[j])))
                    {
                        sArray[i * 2, j * 2] += matrixs[k].array[0, 0];
                        sArray[i * 2+1, j * 2] += matrixs[k].array[1, 0];
                        sArray[i * 2, j * 2+1] += matrixs[k].array[0, 1];
                        sArray[i * 2+1, j * 2+1] += matrixs[k].array[1, 1];
                    }
                    if ((members[k].node2.Equals(dnode[i])&& members[k].node1.Equals(dnode[j]))||
                        (members[k].node1.Equals(dnode[i]) && members[k].node2.Equals(dnode[j])))
                    {
                        sArray[i * 2, j * 2] += matrixs[k].array[2, 0];
                        sArray[i * 2 + 1, j * 2] += matrixs[k].array[3, 0];
                        sArray[i * 2, j * 2 + 1] += matrixs[k].array[2, 3];
                        sArray[i * 2 + 1, j * 2 + 1] += matrixs[k].array[3, 3];
                    }


                }
    }
    
    public List<TrussNodeProperty> getNode(List<TrussNodeProperty> nodes)
    {
        List<TrussNodeProperty> newList = new List<TrussNodeProperty>();
        foreach(TrussNodeProperty node in nodes)
        {
            if(node.dx==1)
                newList.Add(node)
        }
        return newList;
    }

    private float calAngle(float x1,float x2,float lenght)
    {
        return (x2 - x1) /lenght;
    }

}

{'fraction_non_alphanumeric': 0.14048844237523483, 'fraction_numerical': 0.02270685289553214, 'mean_word_length': 1.5891308944808629, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '113044', 'n_tokens_mistral': 4134, 'n_tokens_neox': 3900, 'n_words': 950}