// Start is called before the first frame update void Start() { motionSetup = gameObject.GetComponent <MotionSetup>(); motionSetup.instantTime = MathsFunctions.linspace(0, Settings.duration - (Settings.duration / (Settings.duration * Settings.FPS)), (int)(Settings.duration * Settings.FPS)); for (int i = 0; i < (int)(Settings.duration * Settings.FPS); i++) { if (oscillationInXAxis == true) { motionSetup.instantX[i] = (Mathf.Sin(motionSetup.instantTime[i] * Mathf.Abs(speed)) * Mathf.Abs(xDisplacement)) + centrePoint.x; } if (oscillationInYAxis == true) { motionSetup.instantY[i] = (Mathf.Sin(motionSetup.instantTime[i] * Mathf.Abs(speed)) * Mathf.Abs(yDisplacement)) + centrePoint.y; } if (oscillationInZAxis == true) { motionSetup.instantZ[i] = (Mathf.Sin(motionSetup.instantTime[i] * Mathf.Abs(speed)) * Mathf.Abs(zDisplacement)) + centrePoint.z; } if (oscillationInXAxis == false) { motionSetup.instantX[i] = 0 + centrePoint.x; } if (oscillationInYAxis == false) { motionSetup.instantY[i] = 0 + centrePoint.y; } if (oscillationInZAxis == false) { motionSetup.instantZ[i] = 0 + centrePoint.z; } } }
// Start is called before the first frame update void Start() { motionSetup = gameObject.GetComponent <MotionSetup>(); motionSetup.instantTime = MathsFunctions.linspace(0, Settings.duration - (Settings.duration / (Settings.duration * Settings.FPS)), (int)(Settings.duration * Settings.FPS)); for (int i = 0; i < (int)(Settings.duration * Settings.FPS); i++) { float theta = Mathf.PI / 180 * (((endEl - startEl) / motionSetup.instantTime[motionSetup.instantTime.Length - 1] * motionSetup.instantTime[i]) + startEl); float phi = Mathf.PI / 180 * (((endAz - startAz) / motionSetup.instantTime[motionSetup.instantTime.Length - 1] * motionSetup.instantTime[i]) + startAz); if (movementIsClockwise == false) { motionSetup.instantX[i] = (Mathf.Sin(theta) * Mathf.Cos(phi) * radiusMultiplier) + centrePoint.x; motionSetup.instantY[i] = (Mathf.Cos(theta) * Mathf.Abs(height)) + centrePoint.y; motionSetup.instantZ[i] = (Mathf.Sin(theta) * Mathf.Sin(phi) * radiusMultiplier) + centrePoint.z; } else { motionSetup.instantX[i] = -(Mathf.Sin(theta) * Mathf.Cos(phi) * radiusMultiplier) + centrePoint.x; motionSetup.instantY[i] = (Mathf.Cos(theta) * Mathf.Abs(height)) + centrePoint.y; motionSetup.instantZ[i] = (Mathf.Sin(theta) * Mathf.Sin(phi) * radiusMultiplier) + centrePoint.z; } } }
public GameObject DrawDebugLine(Vector3 start, Vector3 end, Material mat) { float distance = Vector3.Distance(start, end); Vector3 vectRotation = new Vector3(0.0f, 0.0f, MathsFunctions.RotationOfLine(start, end) - 90f); Quaternion rotation = new Quaternion(); rotation.eulerAngles = vectRotation; Vector3 midPoint = (start + end) / 2; //Get midpoint between target and current system midPoint = new Vector3(midPoint.x, midPoint.y, -2.0f); //Create vector from midpoint LineRenderScript lineRenderScript = MasterScript.systemListConstructor.systemList[0].systemObject.GetComponent <LineRenderScript>(); GameObject line = (GameObject)Instantiate(lineRenderScript.line, midPoint, rotation); line.renderer.material = mat; float width = 0.20f; if (mat == MasterScript.turnInfoScript.humansMaterial || mat == MasterScript.turnInfoScript.selkiesMaterial) { width = 0.1f; } line.transform.localScale = new Vector3(width, distance, 0f); return(line); }
private void SortConnectionsByAngle(int i) //Sorts the permanent connections of a system into clockwise order from first added connection { Vector3 zeroVector = MasterScript.systemListConstructor.systemList [i].systemObject.transform.position; //Centre which other points are relevant to for (int j = MasterScript.systemListConstructor.systemList[i].permanentConnections.Count; j > 0; --j) //For all connections { bool swapsMade = false; //Say no swaps have been made for (int k = 1; k < j; ++k) //Sort smallest to largest { float angleK = MathsFunctions.RotationOfLine(MasterScript.systemListConstructor.systemList[i].permanentConnections[k].transform.position, zeroVector); //Get angle between centre and this point float angleKMinusOne = MathsFunctions.RotationOfLine(MasterScript.systemListConstructor.systemList[i].permanentConnections[k - 1].transform.position, zeroVector); if (angleK < angleKMinusOne) { GameObject temp = MasterScript.systemListConstructor.systemList[i].permanentConnections[k]; MasterScript.systemListConstructor.systemList[i].permanentConnections[k] = MasterScript.systemListConstructor.systemList[i].permanentConnections[k - 1]; MasterScript.systemListConstructor.systemList[i].permanentConnections[k - 1] = temp; swapsMade = true; } } if (swapsMade == false) { break; } } }
private void SortExternalPoints() //Used to sort the external points clockwise from the centre of the map { for (int j = externalPoints.Count; j > 0; --j) //For all external points { bool swapsMade = false; //Say no swaps have been made for (int k = 1; k < j; ++k) //While k is less than j (anything above current j value is sorted) { float angleK = MathsFunctions.RotationOfLine(new Vector3(60f, 60f, 0f), externalPoints[k].transform.position); //Get the angle the current external point makes with the centre float angleKMinus1 = MathsFunctions.RotationOfLine(new Vector3(60f, 60f, 0f), externalPoints[k - 1].transform.position); //Get the angle the previous point makes with the centre if (angleK < angleKMinus1) //Sort smallest to largest { GameObject tempExternal = externalPoints[k]; //Create a temporary gameobject to store the point externalPoints[k] = externalPoints[k - 1]; //And swap them externalPoints[k - 1] = tempExternal; swapsMade = true; //A swap has been made } } if (swapsMade == false) //If no swaps made, list must have been sorted { break; //So break } } }
public void DivideByTwo() { int expected = MathsFunctions.Divide_TwoNumbers(10, 2); Assert.AreEqual(5, expected); }
public bool IsValidConnection(GameObject thisSystem, GameObject targetSystem) //Returns true if no intersection { Vector3 lineA = MathsFunctions.ABCLineEquation(thisSystem.transform.position, targetSystem.transform.position); //Line equation from current system to target system Vector3 roughCentre = (thisSystem.transform.position + targetSystem.transform.position) / 2f; if (roughCentre.x < 65f && roughCentre.x > 55f) //If the intersection exists in the galactic core, ignore it { if (roughCentre.y < 65f && roughCentre.y > 55f) { return(false); } } for (int i = 0; i < coordinateList.Count; ++i) //For all existing connections { if (coordinateList[i].systemOne == thisSystem && coordinateList[i].systemTwo == targetSystem) //If a connection already exists between the current system and the target system, continue to the next connection { continue; } if (coordinateList[i].systemTwo == thisSystem && coordinateList[i].systemOne == targetSystem) //Continuation of above { continue; } if (coordinateList[i].systemOne == thisSystem || coordinateList[i].systemTwo == thisSystem) //If the connection contains this system it will not make intersections with the temporary connection { continue; } if (coordinateList[i].systemOne == targetSystem || coordinateList[i].systemTwo == targetSystem) //If the connection contains the target system it will not make intersections with the temporary connection { continue; } //if(CheckIfIntersectionCouldOccur(thisSystem, targetSystem, coordinateList[i].systemOne, coordinateList[i].systemTwo) == false) //{ // continue; // Vector3 lineB = MathsFunctions.ABCLineEquation(coordinateList[i].systemOne.transform.position, coordinateList[i].systemTwo.transform.position); //Get the line equation between of the connection Vector2 intersection = MathsFunctions.IntersectionOfTwoLines(lineA, lineB); //Find the intersection of the two lines if (intersection == Vector2.zero) //If the lines are parallel the method returns a zero vector continue to the next connection { continue; } if (MathsFunctions.PointLiesOnLine(thisSystem.transform.position, targetSystem.transform.position, intersection)) //If the intersection lies on the temporary connection { if (MathsFunctions.PointLiesOnLine(coordinateList[i].systemOne.transform.position, coordinateList[i].systemTwo.transform.position, intersection)) //And it lies on the current permanent connection { return(false); //Return true, an intersection does exist } } } return(true); }
// Start is called before the first frame update void Start() { motionSetup = gameObject.GetComponent <MotionSetup>(); motionSetup.instantTime = MathsFunctions.linspace(0, Settings.duration - (Settings.duration / (Settings.duration * Settings.FPS)), (int)(Settings.duration * Settings.FPS)); motionSetup.instantX = MathsFunctions.linspace(startCoordinates.x, endCoordinates.x, motionSetup.instantTime.Length); motionSetup.instantY = MathsFunctions.linspace(startCoordinates.y, endCoordinates.y, motionSetup.instantTime.Length); motionSetup.instantZ = MathsFunctions.linspace(startCoordinates.z, endCoordinates.z, motionSetup.instantTime.Length); }
public void Update() { if (MasterScript.systemListConstructor.loaded == true && iterator == 0) { //start = true; } if (start == true) { triangles.Clear(); tempTri.Clear(); unvisitedStars.Clear(); externalPoints.Clear(); CacheNearestStars(); //First add all the star systems to a list Triangle newTri = new Triangle(); //Create a new triangle newTri.points.Add(unvisitedStars [0]); //Add the first 3 ordered points from the centre newTri.points.Add(unvisitedStars [1]); newTri.points.Add(unvisitedStars[2]); newTri.lines.Add(MathsFunctions.ABCLineEquation(newTri.points[0].transform.position, newTri.points[1].transform.position)); //Calculate the line equations between the points newTri.lines.Add(MathsFunctions.ABCLineEquation(newTri.points[1].transform.position, newTri.points[2].transform.position)); newTri.lines.Add(MathsFunctions.ABCLineEquation(newTri.points[2].transform.position, newTri.points[0].transform.position)); externalPoints.Add(unvisitedStars [0]); //Add the points to the external points list externalPoints.Add(unvisitedStars [1]); externalPoints.Add(unvisitedStars [2]); triangles.Add(newTri); //Add the triangle to the triangle list unvisitedStars.RemoveRange(0, 3); //Remove the points from the unvisited points list start = false; iterate = true; timer = Time.time; } if (start == false && iterate == true) { if (iterator < unvisitedStars.Count) { LinkPointToTris(iterator); CacheTempTris(iterator); DrawDebugTriangles(); ++iterator; timer = Time.time; } if (iterator == unvisitedStars.Count) { DrawDebugTriangles(); iterate = false; } } }
public bool CheckIsDelaunay(Triangle triOne, Triangle triTwo) { List <GameObject> sharedSides = MasterScript.triangulation.CheckIfSharesSide(triOne, triTwo); //Find if triangles share a side (this actually returns the 2 shared and 2 unshared vertices) if (sharedSides.Count == 4) //If 4 vertices are shared { GameObject sharedPointA = sharedSides[0]; //Assign the shared points GameObject sharedPointB = sharedSides[1]; GameObject unsharedPointA = sharedSides[2]; //Assign the unshared points GameObject unsharedPointB = sharedSides[3]; float angleAlpha = 0f, angleBeta = 0f; //Set some angles to 0 angleAlpha = MathsFunctions.AngleBetweenLineSegments(unsharedPointA.transform.position, sharedPointA.transform.position, sharedPointB.transform.position); //First angle is at one unshared point angleBeta = MathsFunctions.AngleBetweenLineSegments(unsharedPointB.transform.position, sharedPointA.transform.position, sharedPointB.transform.position); //Second angle is at the other unshared point Vector3 sharedPointLine = MathsFunctions.ABCLineEquation(sharedPointA.transform.position, sharedPointB.transform.position); //Get the line between the shared points Vector3 unsharedPointLine = MathsFunctions.ABCLineEquation(unsharedPointA.transform.position, unsharedPointB.transform.position); //Get the line between the unshared points Vector2 intersection = MathsFunctions.IntersectionOfTwoLines(sharedPointLine, unsharedPointLine); //Find the intersection of the two lines if (MathsFunctions.PointLiesOnLine(sharedPointA.transform.position, sharedPointB.transform.position, intersection) == false) //If the intersection does not lie between the shared points then this is a non convex hull { return(true); //So it cannot be flipped, continue to the next triangle } if (angleAlpha + angleBeta > 180f) //If the polygon is convex, and the two angles combine to be greater than 180 degrees, the triangles are non delaunay, so we flip them { int triPosOne = MasterScript.triangulation.triangles.IndexOf(triOne); //Find the position of the two triangles in the triangles list int triPosTwo = MasterScript.triangulation.triangles.IndexOf(triTwo); triOne.points[0] = unsharedPointA; //Reassign the vertices of tri one to make the previously unshared vertices the shared vertices. One of the previously shared vertices is now the unshared vertex. triOne.points[1] = unsharedPointB; triOne.points[2] = sharedPointA; triOne.lines[0] = MathsFunctions.ABCLineEquation(triOne.points[0].transform.position, triOne.points[1].transform.position); //Get the line equations for all the sides triOne.lines[1] = MathsFunctions.ABCLineEquation(triOne.points[1].transform.position, triOne.points[2].transform.position); triOne.lines[2] = MathsFunctions.ABCLineEquation(triOne.points[2].transform.position, triOne.points[0].transform.position); MasterScript.triangulation.triangles[triPosOne] = triOne; //Replace the original triangle with this new, flipped triangle triTwo.points[0] = unsharedPointA; //Do the same for tri two triTwo.points[1] = unsharedPointB; triTwo.points[2] = sharedPointB; triTwo.lines[0] = MathsFunctions.ABCLineEquation(triTwo.points[0].transform.position, triTwo.points[1].transform.position); triTwo.lines[1] = MathsFunctions.ABCLineEquation(triTwo.points[1].transform.position, triTwo.points[2].transform.position); triTwo.lines[2] = MathsFunctions.ABCLineEquation(triTwo.points[2].transform.position, triTwo.points[0].transform.position); MasterScript.triangulation.triangles[triPosTwo] = triTwo; ++flips; //Increase the number of flips that have been made this pass. return(false); //Return false (a flip has been made) } } return(true); //Otherwise continue to the next triangle }
public void AddTwoNumbersTest() { //Arrange int a = 10; int b = 5; //Act int total = MathsFunctions.AddTwoNumbers(a, b); //Assert Assert.AreEqual(15, total); }
public void SubstractTwoNumbersTest() { //Arrange int a = 10; int b = 5; //Act int expected = MathsFunctions.SubrTractTwoNumbers(a, b); //Assert Assert.AreEqual(5, expected); }
public void AverageofTwoNumbers() { //Arrange int a = 10; int b = 2; //Act int expected = MathsFunctions.AverageTwoNumbers(a, b); //Assert Assert.AreEqual(6, expected); }
// Start is called before the first frame update void Start() { motionSetup = gameObject.GetComponent <MotionSetup>(); motionSetup.instantTime = MathsFunctions.linspace(0, Settings.duration - (Settings.duration / (Settings.duration * Settings.FPS)), (int)(Settings.duration * Settings.FPS)); for (int i = 0; i < (int)(Settings.duration * Settings.FPS); i++) { motionSetup.instantX[i] = transform.position.x; motionSetup.instantY[i] = transform.position.y; motionSetup.instantZ[i] = transform.position.z; } }
public void MultiplyThreeNumbersTest() { //Arrange int a = 1; int b = 2; int c = 3; //Act int result = MathsFunctions.MultiplyThreeNumbers(a, b, c); //Assert Assert.AreEqual(6, result); }
public static float AngleBetweenLineSegments(Vector3 origin, Vector3 pointA, Vector3 pointB) { float angleA = MathsFunctions.RotationOfLine(pointA, origin); float angleB = MathsFunctions.RotationOfLine(pointB, origin); float testAngle = Mathf.Max(angleA, angleB) - Mathf.Min(angleA, angleB); if (testAngle > 180f) { testAngle = 360f - testAngle; } return(testAngle); }
private bool IsIllegalIntersection(int externalPoint, int unvisitedPoint, Vector3 curToExtLine) { for (int j = 0; j < triangles.Count; ++j) //For every triangle { if (triangles[j].isInternal == true) //If the triangle is internal we don't need to worry about it, so move onto the next triangle { continue; } for (int k = 0; k < 3; ++k) //For each line in that triangle { GameObject pointA = null; //Get the points at each end of the line GameObject pointB = null; if (k == 0) { pointA = triangles[j].points[0]; pointB = triangles[j].points[1]; } if (k == 1) { pointA = triangles[j].points[1]; pointB = triangles[j].points[2]; } if (k == 2) { pointA = triangles[j].points[2]; pointB = triangles[j].points[0]; } if (pointA.name == externalPoints[externalPoint].name || pointB.name == externalPoints[externalPoint].name) //If the line contains the external point we can ignore it { continue; } Vector2 intersection = MathsFunctions.IntersectionOfTwoLines(curToExtLine, triangles[j].lines[k]); //Get the intersection of the line with the current star to external point line if (MathsFunctions.PointLiesOnLine(externalPoints[externalPoint].transform.position, unvisitedStars[unvisitedPoint].transform.position, intersection)) //If the point lies elsewhere on the line { if (MathsFunctions.PointLiesOnLine(pointA.transform.position, pointB.transform.position, intersection)) { return(true); //This IS an illegal intersection so return that, otherwise keep checking } } } } return(false); }
private void CheckForNonDelaunayTriangles() { List <Triangle> numberofnondelaunay = new List <Triangle>(); for (int i = 0; i < triangles.Count; ++i) { for (int j = 0; j < triangles.Count; ++j) { if (i == j) { continue; } List <GameObject> sharedSides = CheckIfSharesSide(triangles[i], triangles[j]); if (sharedSides.Count == 4) { GameObject sharedPointA = sharedSides[0]; GameObject sharedPointB = sharedSides[1]; GameObject unsharedPointA = sharedSides[2]; GameObject unsharedPointB = sharedSides[3]; float angleAlpha = 0f, angleBeta = 0f; angleAlpha = MathsFunctions.AngleBetweenLineSegments(unsharedPointA.transform.position, sharedPointA.transform.position, sharedPointB.transform.position); angleBeta = MathsFunctions.AngleBetweenLineSegments(unsharedPointB.transform.position, sharedPointA.transform.position, sharedPointB.transform.position); Vector3 sharedPointLine = MathsFunctions.ABCLineEquation(sharedPointA.transform.position, sharedPointB.transform.position); Vector3 unsharedPointLine = MathsFunctions.ABCLineEquation(unsharedPointA.transform.position, unsharedPointB.transform.position); Vector2 intersection = MathsFunctions.IntersectionOfTwoLines(sharedPointLine, unsharedPointLine); if (MathsFunctions.PointLiesOnLine(sharedPointA.transform.position, sharedPointB.transform.position, intersection) == false) //Is non-convex { continue; } if (angleBeta + angleAlpha > 180) { numberofnondelaunay.Add(triangles[i]); } } } } Debug.Log(numberofnondelaunay.Count + " | " + triangles.Count); }
public bool IsValidAngle(GameObject thisSystem, GameObject targetSystem) //Returns true if angle within limits { int current = MasterScript.RefreshCurrentSystem(thisSystem); for (int i = 0; i < MasterScript.systemListConstructor.systemList[current].permanentConnections.Count; ++i) { float angleA = MathsFunctions.AngleBetweenLineSegments(thisSystem.transform.position, targetSystem.transform.position, MasterScript.systemListConstructor.systemList[current].permanentConnections[i].transform.position); float angleB = MathsFunctions.AngleBetweenLineSegments(targetSystem.transform.position, thisSystem.transform.position, MasterScript.systemListConstructor.systemList[current].permanentConnections[i].transform.position); if (angleA <= 10.0f || angleB <= 10.0f) { return(false); } } return(true); }
// Start is called before the first frame update void Start() { motionSetup = gameObject.GetComponent <MotionSetup>(); motionSetup.instantTime = MathsFunctions.linspace(0, Settings.duration - (Settings.duration / (Settings.duration * Settings.FPS)), (int)(Settings.duration * Settings.FPS)); motionSetup.instantY = MathsFunctions.linspace(-height / 2, height / 2, (int)(Settings.duration * Settings.FPS)); for (int i = 0; i < (int)(Settings.duration * Settings.FPS); i++) { if (movementIsClockwise == false) { motionSetup.instantX[i] = (Mathf.Cos(motionSetup.instantTime[i] * Mathf.Abs(radialSpeed)) * Mathf.Abs(width) * radiusMultiplier) + centrePoint.x; motionSetup.instantY[i] = motionSetup.instantY[i] + centrePoint.y; motionSetup.instantZ[i] = (Mathf.Sin(motionSetup.instantTime[i] * Mathf.Abs(radialSpeed)) * Mathf.Abs(depth) * radiusMultiplier) + centrePoint.z; } else { motionSetup.instantX[i] = -(Mathf.Cos(motionSetup.instantTime[i] * Mathf.Abs(radialSpeed)) * Mathf.Abs(width) * radiusMultiplier) + centrePoint.x; motionSetup.instantY[i] = motionSetup.instantY[i] + centrePoint.y; motionSetup.instantZ[i] = (Mathf.Sin(motionSetup.instantTime[i] * Mathf.Abs(radialSpeed)) * Mathf.Abs(depth) * radiusMultiplier) + centrePoint.z; } } }
public void SimpleTriangulation() //This function controls the triangulation and conversion to delaunay of the stars { CacheNearestStars(); //First add all the star systems to a list Triangle newTri = new Triangle(); //Create a new triangle newTri.points.Add(unvisitedStars [0]); //Add the first 3 ordered points from the centre newTri.points.Add(unvisitedStars [1]); newTri.points.Add(unvisitedStars[2]); newTri.lines.Add(MathsFunctions.ABCLineEquation(newTri.points[0].transform.position, newTri.points[1].transform.position)); //Calculate the line equations between the points newTri.lines.Add(MathsFunctions.ABCLineEquation(newTri.points[1].transform.position, newTri.points[2].transform.position)); newTri.lines.Add(MathsFunctions.ABCLineEquation(newTri.points[2].transform.position, newTri.points[0].transform.position)); externalPoints.Add(unvisitedStars [0]); //Add the points to the external points list externalPoints.Add(unvisitedStars [1]); externalPoints.Add(unvisitedStars [2]); triangles.Add(newTri); //Add the triangle to the triangle list unvisitedStars.RemoveRange(0, 3); //Remove the points from the unvisited points list for (int i = 0; i < unvisitedStars.Count; ++i) //For all unchecked points { LinkPointToTris(i); //Link this unvisited point to all possible external points CacheTempTris(i); //Add all the triangles formed by this linking to the triangle list } bool isDelaunay = false; //Say that the list isn't delaunay while (isDelaunay == false) //While it isn't delaunay { isDelaunay = MasterScript.voronoiGenerator.TriangulationToDelaunay(); //Make it delaunay, if the method returns true, the triangulation is delaunay and the while loop will stop } CheckForNonDelaunayTriangles(); //Debugging method outputs the number of non-delaunay triangles to the log. This has not output any bad values for some time. }
private void CheckInteriorPoints() //Checks through external point list to see if any points have become internal ones (are within the polygon formed by linking triangles { List <int> pointsToRemove = new List <int> (); for (int i = 0; i < externalPoints.Count; ++i) { float tempAngle = 0; for (int j = 0; j < triangles.Count; ++j) { if (triangles[j].isInternal) { continue; } for (int k = 0; k < 3; ++k) { if (triangles[j].points[k] == externalPoints[i]) { int a = 0, b = 0; if (k == 0) { a = 1; b = 2; } if (k == 1) { a = 0; b = 2; } if (k == 2) { a = 0; b = 1; } tempAngle += MathsFunctions.AngleBetweenLineSegments(triangles[j].points[k].transform.position, triangles[j].points[a].transform.position, triangles[j].points[b].transform.position); break; } } } if (Math.Round(tempAngle, 2) >= 360f) { pointsToRemove.Add(i); } } for (int j = 0; j < triangles.Count; ++j) //For all triangles { bool isInternalTri = true; //Say its internal for (int k = 0; k < 3; ++k) //For all points in that triangle { if (externalPoints.Contains(triangles[j].points[k])) //If one of them is external { isInternalTri = false; //The tri isn't internal } } if (isInternalTri) { triangles[j].isInternal = true; } } int counter = 0; for (int i = 0; i < pointsToRemove.Count; ++i) { externalPoints.RemoveAt(pointsToRemove[i] - counter); ++counter; } }
public void CreateVoronoiCells() //This appears to be fine { MasterScript.triangulation.SimpleTriangulation(); for (int j = 0; j < MasterScript.systemListConstructor.systemList.Count; ++j) //For all systems { VoronoiCellVertices newCell = new VoronoiCellVertices(); //Create new voronoi cell Vector3 voronoiCentre = MasterScript.systemListConstructor.systemList[j].systemObject.transform.position; //Centre of voronoi cell is the current system location for (int i = 0; i < MasterScript.triangulation.triangles.Count; ++i) //For all triangles { if (MasterScript.triangulation.triangles[i].points.Contains(MasterScript.systemListConstructor.systemList[j].systemObject)) //If the triangle has the current system as one of it's vertices { Vector3 systemA = MasterScript.triangulation.triangles[i].points[0].transform.position; //System A equals this system Vector3 systemB = MasterScript.triangulation.triangles[i].points[1].transform.position; //System B is another point in the triangle Vector3 systemC = MasterScript.triangulation.triangles[i].points[2].transform.position; //System C is the final point in the triangle Vector3 lineAB = MathsFunctions.PerpendicularLineEquation(systemA, systemB); //Get the line equations of the line perpendicular to the midpoint between two points Vector3 lineBC = MathsFunctions.PerpendicularLineEquation(systemB, systemC); Vector3 voronoiVertex = MathsFunctions.IntersectionOfTwoLines(lineAB, lineBC); //One of the voronoi vertices is the circumcentre of the triangle float angle = MathsFunctions.RotationOfLine(voronoiVertex, voronoiCentre); //Get the angle of the vertex relative to the centre of the voronoi cell newCell.vertexAngles.Add(angle); //Add the angle to the cells angle list (this is to sort the vertices clockwise) newCell.vertices.Add(voronoiVertex); //Add the vertex to the cells vertex list } } voronoiVertices.Add(newCell); //Add the cell to the list of cells } for (int i = 0; i < voronoiVertices.Count; ++i) //For all voronoi cells { for (int j = voronoiVertices[i].vertexAngles.Count; j > 0; --j) //For all vertices in the cell { bool swapsMade = false; for (int k = 1; k < j; ++k) //While k is less than j (anything above current j value is sorted) { if (voronoiVertices[i].vertexAngles[k] < voronoiVertices[i].vertexAngles[k - 1]) //Sort smallest to largest { float tempAng = voronoiVertices[i].vertexAngles[k]; Vector3 tempPos = voronoiVertices[i].vertices[k]; voronoiVertices[i].vertexAngles[k] = voronoiVertices[i].vertexAngles[k - 1]; voronoiVertices[i].vertices[k] = voronoiVertices[i].vertices[k - 1]; voronoiVertices[i].vertexAngles[k - 1] = tempAng; voronoiVertices[i].vertices[k - 1] = tempPos; swapsMade = true; } } if (swapsMade == false) //If no swaps made, list must have been sorted { break; //So break } } for (int j = 1; j < voronoiVertices[i].vertices.Count; ++j) //For all the vertices { if (voronoiVertices[i].vertices[j] == voronoiVertices[i].vertices[j - 1]) //If there are duplicates { voronoiVertices[i].vertices.RemoveAt(j); //Remove one --j; } } } for (int i = 0; i < voronoiVertices.Count; ++i) //For all cells { GameObject newCell = new GameObject("Voronoi Cell"); //Create new gameobject newCell.AddComponent("MeshRenderer"); //Add meshrenderer to create a mesh newCell.AddComponent("MeshFilter"); //Add meshfilter to apply materials newCell.AddComponent("MeshCollider"); //Add meshcollider (why?) MeshFilter newMesh = (MeshFilter)newCell.GetComponent("MeshFilter"); //Get a reference to the meshfilter List <Vector3> vertices = new List <Vector3>(); //Create new list of vertices for (int j = 0; j < voronoiVertices[i].vertices.Count; ++j) //For all the voronoi cell's vertices { int nextVertex = j + 1; //Get the next vertex if (nextVertex == voronoiVertices[i].vertices.Count) { nextVertex = 0; } int prevVertex = j - 1; //Get the previous vertex if (prevVertex == -1) { prevVertex = voronoiVertices[i].vertices.Count - 1; } Vector3 lineA = voronoiVertices[i].vertices[prevVertex] - voronoiVertices[i].vertices[j]; //Line from vertex to next vertex Vector3 lineB = voronoiVertices[i].vertices[nextVertex] - voronoiVertices[i].vertices[j]; //Line from vertex to previous vertex Vector3 bisector = (lineA.normalized + lineB.normalized) / 2f; //Bisector line float yIntersect = voronoiVertices[i].vertices[j].y - (bisector.y / bisector.x) * voronoiVertices[i].vertices[j].x; //Cintersect = y - mx Vector3 bisectorIntersect = new Vector3(0f, yIntersect, 0f); //Get the y intersect of the bisector float vertAngle = MathsFunctions.AngleBetweenLineSegments(voronoiVertices[i].vertices[j], voronoiVertices[i].vertices[prevVertex], voronoiVertices[i].vertices[nextVertex]) / 2f; //Get the angle between the lines float hypotenuseLength = 0.5f / Mathf.Sin(vertAngle * Mathf.Deg2Rad); //Find the length of the hypotenuse (how far in the new vertex should be Vector3 dir = bisectorIntersect - voronoiVertices[i].vertices[j]; //Find the direction that the new vertex points to from the current vertex dir = bisector.normalized; //Normalise the direction vertices.Add(voronoiVertices[i].vertices[j]); //Add the original vertex to the new vertex list vertices.Add(voronoiVertices[i].vertices[j] + (dir * hypotenuseLength)); //Add this indented vertex to the new vertex list } for (int j = 0; j < vertices.Count; ++j) //For all the vertices { float x = vertices[j].x - MasterScript.systemListConstructor.systemList[i].systemObject.transform.position.x; //Set the x relative to the centre (used to be prevent the vertices being offset from the gameobject centre) float y = vertices[j].y - MasterScript.systemListConstructor.systemList[i].systemObject.transform.position.y; //Do the same for the y Vector3 newPos = new Vector3(x, y, 0f); vertices[j] = newPos; } newMesh.mesh.vertices = vertices.ToArray(); //Add the vertices to the mesh vertex list List <int> tris = new List <int>(); //Create new tris for (int j = 0; j < vertices.Count; ++j) //Create tris from the vertices { int nextVertex = j + 1; int afterNextVertex = j + 2; if (nextVertex == vertices.Count) { nextVertex = 0; afterNextVertex = 1; } if (afterNextVertex == vertices.Count) { afterNextVertex = 0; } if (j % 2 != 0) { tris.Add(afterNextVertex); tris.Add(nextVertex); tris.Add(j); } else { tris.Add(j); tris.Add(nextVertex); tris.Add(afterNextVertex); } } List <Vector2> uvs = new List <Vector2>(); for (int j = 0; j < newMesh.mesh.vertices.Length; ++j) { Vector2 uvCoordinate = new Vector2(newMesh.mesh.vertices[j].x, newMesh.mesh.vertices[j].z); uvs.Add(uvCoordinate); } newMesh.mesh.triangles = tris.ToArray(); newMesh.mesh.uv = uvs.ToArray(); newMesh.mesh.RecalculateNormals(); newMesh.mesh.RecalculateBounds(); newMesh.mesh.Optimize(); newCell.renderer.material = MasterScript.turnInfoScript.emptyMaterial; newCell.renderer.material.shader = Shader.Find("Transparent/Diffuse"); Color newColour = newCell.renderer.material.color; newColour = new Color(newColour.r, newColour.g, newColour.b, 0f); newCell.renderer.material.color = newColour; newCell.AddComponent <SystemRotate>(); newCell.name = "Voronoi Cell" + i.ToString(); newCell.tag = "VoronoiCell"; newCell.transform.position = new Vector3(MasterScript.systemListConstructor.systemList[i].systemObject.transform.position.x, MasterScript.systemListConstructor.systemList[i].systemObject.transform.position.y, 0f); newCell.transform.parent = voronoiCellContainer.transform; //voronoiCells.Add (newCell); } }
private void LinkPointToTris(int curPoint) //Send the current unvisited star as the seed point SOMETHING WRONG { for (int i = 0; i < externalPoints.Count; ++i) //For all the external points { int nextPoint = i + 1; //Assign the next point if (nextPoint == externalPoints.Count) //If the next point is out of range { nextPoint = 0; //Set it to the first point in the list } Vector3 lineCurToExternal = MathsFunctions.ABCLineEquation(unvisitedStars[curPoint].transform.position, externalPoints[i].transform.position); //Create a line between the external point and the unvisited star if (IsIllegalIntersection(i, curPoint, lineCurToExternal)) //If there is an illegal intersection between the external point-current point line and the external point-unvisited point line { continue; //Move onto the next external point } Vector3 lineCurToNextExternal = MathsFunctions.ABCLineEquation(unvisitedStars[curPoint].transform.position, externalPoints[nextPoint].transform.position); if (IsIllegalIntersection(nextPoint, curPoint, lineCurToNextExternal)) //If there is an illegal intersection between the next point-current point line and the external point-unvisited point line { continue; //Move onto the next external point } bool illegal = false; //Say that the line is not illegal for (int j = 0; j < externalPoints.Count; ++j) //Check through all other external points { if (j == i || j == nextPoint) { continue; } if (MathsFunctions.IsInTriangle(externalPoints[i].transform.position, externalPoints[nextPoint].transform.position, unvisitedStars[curPoint].transform.position, externalPoints[j].transform.position) == true) //If the point lies in any of the triangles { //if(MathsFunctions.PointsAreColinear(externalPoints[i].transform.position, externalPoints[nextPoint].transform.position, externalPoints[j].transform.position) == false) //{ //if(MathsFunctions.PointsAreColinear(externalPoints[i].transform.position, unvisitedStars[curPoint].transform.position, externalPoints[j].transform.position) == false) //{ //if(MathsFunctions.PointsAreColinear(externalPoints[nextPoint].transform.position, unvisitedStars[curPoint].transform.position, externalPoints[j].transform.position) == false) //{ illegal = true; //It is an illegal triangle break; // //} //} //} } } if (illegal) //If it's an illegal triangle { continue; //Skip to the next point } GameObject pointA = externalPoints[i]; //Otherwise assign the points of the triangle GameObject pointB = externalPoints[nextPoint]; GameObject pointC = unvisitedStars[curPoint]; Triangle newTri = new Triangle(); //Create a new triangle object newTri.points.Add(pointA); //Add the points newTri.points.Add(pointB); newTri.points.Add(pointC); newTri.lines.Add(MathsFunctions.ABCLineEquation(pointA.transform.position, pointB.transform.position)); //Calculate the line equations between the points newTri.lines.Add(MathsFunctions.ABCLineEquation(pointB.transform.position, pointC.transform.position)); newTri.lines.Add(MathsFunctions.ABCLineEquation(pointC.transform.position, pointA.transform.position)); tempTri.Add(newTri); //Add the triangle to the temptriangle list } }
//Calcuation Controller Action public void CalculateAction(List<CategoryViewModel> jCategory) { foreach (var group in jCategory) { foreach (var item in group.Functions) { if (item.Function == "Input") { item.Output = InputFunctions.Output(item.Type, item.Output); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Logic check at Column Level string colLogic = null; bool colLogicParse = true; if(group.Logic != null) { foreach (var bit in group.Logic) { var grouplastLogic = group.Logic.Last(); string grouplastLogicOperator = grouplastLogic.Operator; Logic Logic = new Logic(); colLogic = Logic.Output(jCategory, bit, group.ID, 0); Expression ex = new Expression(colLogic); try { colLogicParse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (grouplastLogicOperator == "AND" && colLogicParse == false) { break; } else if (grouplastLogicOperator == "OR" && colLogicParse == true) { colLogicParse = true; break; } } } if (item.Parameter.Count > 0) { string logic = null; bool logicparse = true; string MathString = null; bool PowOpen = false; //Logic check at column level if (colLogicParse == true) { foreach (var bit in item.Logic) { var lastLogic = item.Logic.Last(); string lastLogicOperator = lastLogic.Operator; Logic Logic = new Logic(); logic = Logic.Output(jCategory, bit, group.ID, item.ID); Expression ex = new Expression(logic); try { logicparse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (lastLogicOperator == "AND" && logicparse == false) { break; } else if (lastLogicOperator == "OR" && logicparse == true) { logicparse = true; break; } } } else { logicparse = false; } //Run code if logic if met at column and row level if (logicparse == true) { int paramCount = 1; foreach (var param in item.Parameter) { string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param); logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID +") - " + item.Name); if (item.Function == "Maths") { Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); MathString = Maths.Output(jparameters,jCategory,group.ID,item.ID,MathString,PowOpen); PowOpen = Maths.PowOpen(jparameters, PowOpen); if (paramCount == item.Parameter.Count) { Expression e = new Expression(MathString); var Calculation = e.Evaluate(); bool DeciParse; decimal CalculationDeci; string Rounding; DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci); Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } if (DeciParse == true) { decimal Output = CalculationDeci; MathematicalFunctions MathematicalFunctions = new MathematicalFunctions(); try { Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Output = Convert.ToString(Output); } else { item.Output = "0"; } } paramCount = paramCount + 1; } else if (item.Function == "ErrorsWarnings") { ErrorsWarnings Errors = new ErrorsWarnings(); ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializer.Deserialize(jparameters, typeof(ErrorsWarnings)); item.Name = parameters.Type; item.Output = parameters.String1; } else if (item.Function == "Comments") { Comments Errors = new Comments(); Comments parameters = (Comments)javaScriptSerializer.Deserialize(jparameters, typeof(Comments)); item.Output = parameters.String1; } else if (item.Function == "Period") { DateFunctions DateFunctions = new DateFunctions(); Period Periods = new Period(); try { item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Factors") { Factors Factors = new Factors(); Factors parameters = (Factors)javaScriptSerializer.Deserialize(jparameters, typeof(Factors)); try { item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Type = parameters.OutputType; } else if (item.Function == "DateAdjustment") { Dates Dates = new Dates(); try { item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "DatePart") { DatePart DateParts = new DatePart(); try { item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "MathsFunctions") { MathsFunctions MathsFunctions = new MathsFunctions(); try { item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "ArrayFunctions") { ArrayFunctions ArrayFunctions = new ArrayFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); try { item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if(parameters.Function == "Count") { item.Type = "Decimal"; } else { item.Type = parameters.LookupType; } } else if (item.Function == "StringFunctions") { StringFunctions StringFunctions = new StringFunctions(); StringFunctions parameters = (StringFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(StringFunctions)); try { item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if(parameters.Type == "Len") { item.Type = "Decimal"; } else { item.Type = "String"; } } } //Expected results on the builder this sets the required ones if (item.ExpectedResult == null || item.ExpectedResult == "") { item.Pass = "******"; } else if (item.ExpectedResult == item.Output) { item.Pass = "******"; } else { item.Pass = "******"; } OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Ignores the row if logic is not met dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID); if(Convert.ToString(LogicReplace) == Convert.ToString(item.Name)) { item.Output = null; } else { item.Output = Convert.ToString(LogicReplace); } item.Pass = "******"; OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } } } } } }
//Calcuation Controller Action public void CalculateAction(List <CategoryViewModel> jCategory) { foreach (var group in jCategory) { foreach (var item in group.Functions) { if (item.Function == "Input") { item.Output = InputFunctions.Output(item.Type, item.Output); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Logic check at Column Level string colLogic = null; bool colLogicParse = true; if (group.Logic != null) { foreach (var bit in group.Logic) { var grouplastLogic = group.Logic.Last(); string grouplastLogicOperator = grouplastLogic.Operator; Logic Logic = new Logic(); colLogic = Logic.Output(jCategory, bit, group.ID, 0); Expression ex = new Expression(colLogic); try { colLogicParse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (grouplastLogicOperator == "AND" && colLogicParse == false) { break; } else if (grouplastLogicOperator == "OR" && colLogicParse == true) { colLogicParse = true; break; } } } if (item.Parameter.Count > 0) { string logic = null; bool logicparse = true; string MathString = null; bool PowOpen = false; //Logic check at column level if (colLogicParse == true) { foreach (var bit in item.Logic) { var lastLogic = item.Logic.Last(); string lastLogicOperator = lastLogic.Operator; Logic Logic = new Logic(); logic = Logic.Output(jCategory, bit, group.ID, item.ID); Expression ex = new Expression(logic); try { logicparse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (lastLogicOperator == "AND" && logicparse == false) { break; } else if (lastLogicOperator == "OR" && logicparse == true) { logicparse = true; break; } } } else { logicparse = false; } //Run code if logic if met at column and row level if (logicparse == true) { int paramCount = 1; foreach (var param in item.Parameter) { string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param); logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID + ") - " + item.Name); if (item.Function == "Maths") { Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); MathString = Maths.Output(jparameters, jCategory, group.ID, item.ID, MathString, PowOpen); PowOpen = Maths.PowOpen(jparameters, PowOpen); if (paramCount == item.Parameter.Count) { Expression e = new Expression(MathString); var Calculation = e.Evaluate(); bool DeciParse; decimal CalculationDeci; string Rounding; DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci); Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } if (DeciParse == true) { decimal Output = CalculationDeci; MathematicalFunctions MathematicalFunctions = new MathematicalFunctions(); try { Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Output = Convert.ToString(Output); } else { item.Output = "0"; } } paramCount = paramCount + 1; } else if (item.Function == "ErrorsWarnings") { ErrorsWarnings Errors = new ErrorsWarnings(); ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializer.Deserialize(jparameters, typeof(ErrorsWarnings)); item.Name = parameters.Type; item.Output = parameters.String1; } else if (item.Function == "Comments") { Comments Errors = new Comments(); Comments parameters = (Comments)javaScriptSerializer.Deserialize(jparameters, typeof(Comments)); item.Output = parameters.String1; } else if (item.Function == "Period") { DateFunctions DateFunctions = new DateFunctions(); Period Periods = new Period(); try { item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Factors") { Factors Factors = new Factors(); Factors parameters = (Factors)javaScriptSerializer.Deserialize(jparameters, typeof(Factors)); try { item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Type = parameters.OutputType; } else if (item.Function == "DateAdjustment") { Dates Dates = new Dates(); try { item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "DatePart") { DatePart DateParts = new DatePart(); try { item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Return") { Return Return = new Return(); try { item.Output = Return.Output(jparameters, jCategory, group.ID, item.ID); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); return; } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "MathsFunctions") { MathsFunctions MathsFunctions = new MathsFunctions(); try { item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID, group); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "ArrayFunctions") { ArrayFunctions ArrayFunctions = new ArrayFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); try { item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if (parameters.Function == "Count") { item.Type = "Decimal"; } else { item.Type = parameters.LookupType; } } else if (item.Function == "StringFunctions") { StringFunctions StringFunctions = new StringFunctions(); StringFunctions parameters = (StringFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(StringFunctions)); try { item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if (parameters.Type == "Len") { item.Type = "Decimal"; } else { item.Type = "String"; } } else if (item.Function == "Function") { Function Functions = new Function(); Function parameters = (Function)javaScriptSerializer.Deserialize(jparameters, typeof(Function)); FunctionConfiguration calcFunction = db.FunctionConfiguration.Find(Convert.ToInt32(parameters.ID)); List <CategoryViewModel> calcFunctionConfig = (List <CategoryViewModel>)javaScriptSerializer.Deserialize(calcFunction.Configuration, typeof(List <CategoryViewModel>)); //replace inputs from main configuration to function foreach (var row in calcFunctionConfig[0].Functions) { int index = parameters.Input.FindIndex(a => a.Name == row.Name); if (index >= 0) { row.Output = parameters.Input[index].Output; } else { row.Output = null; } } foreach (var input in calcFunctionConfig[0].Functions) { if (input.Output != null) { input.Output = Convert.ToString(Functions.Output(jparameters, jCategory, group.ID, item.ID, input.Output, input.Type)); } } //run the function with the new inputs Calculate Calculate = new Calculate(); calcFunctionConfig = Calculate.DebugResults(calcFunctionConfig); item.SubOutput = Calculate.OutputResults(calcFunctionConfig); foreach (var col in calcFunctionConfig) { int index = col.Functions.FindIndex(a => a.Function == "Return"); if (index >= 0) { item.Output = col.Functions[index].Output; foreach (var thing in col.Functions[index].Parameter) { foreach (var test in thing) { if (test.Key == "Datatype") { item.Type = test.Value; } } } } } } } //Expected results on the builder this sets the required ones if (item.ExpectedResult == null || item.ExpectedResult == "") { item.Pass = "******"; } else if (item.ExpectedResult == item.Output) { item.Pass = "******"; } else { item.Pass = "******"; } OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name, SubOutput = item.SubOutput }); } else { //Ignores the row if logic is not met dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID); if (Convert.ToString(LogicReplace) == Convert.ToString(item.Name)) { item.Output = null; } else { item.Output = Convert.ToString(LogicReplace); } item.Pass = "******"; OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name, SubOutput = item.SubOutput }); } } } } } }