public void CalculateRunThroughLineSphereIntersection() { // arrange var sphereCenter = new Point(150, 150); const double SphereRadius = 5; var lineStartPoint = new Point(0, 0); var lineEndPoint = new Point(300, 300); Point?firstIntersection; Point?secondIntersection; // act var intersection = CalculationHelpers.CalculateLineSphereIntersection( sphereCenter, SphereRadius, lineStartPoint, lineEndPoint, out firstIntersection, out secondIntersection); // assert Assert.AreEqual(2, intersection); Assert.IsNotNull(firstIntersection); Assert.AreEqual(146.4644660940672624, firstIntersection.Value.X, 0.00001); Assert.AreEqual(146.4644660940672624, firstIntersection.Value.Y, 0.00001); Assert.IsNotNull(secondIntersection); Assert.AreEqual(153.5355339059327376, secondIntersection.Value.X, 0.00001); Assert.AreEqual(153.5355339059327376, secondIntersection.Value.Y, 0.00001); }
public void CalculateLineSphereIntersectionWithOppositeDirection() { // arrange var sphereCenter = new Point(150, 150); const double SphereRadius = 5; var lineStartPoint = new Point(140, 140); var lineEndPoint = new Point(0, 0); Point?firstIntersection; Point?secondIntersection; // act var intersection = CalculationHelpers.CalculateLineSphereIntersection( sphereCenter, SphereRadius, lineStartPoint, lineEndPoint, out firstIntersection, out secondIntersection); // assert Assert.AreEqual(0, intersection); Assert.IsNull(firstIntersection); Assert.IsNull(secondIntersection); }
internal static void Main() { Console.WriteLine(CalculationHelpers.CalculateTriangleArea(3, 4, 5)); Console.WriteLine(CalculationHelpers.DigitToWord(5)); Console.WriteLine(CalculationHelpers.FindMaximumValue(5, -1, 3, 2, 14, 2, 3)); ConsoleWriter.PrintToConsoleAsNumberInFormat(1.3, "f"); ConsoleWriter.PrintToConsoleAsNumberInFormat(0.75, "%"); ConsoleWriter.PrintToConsoleAsNumberInFormat(2.30, "r"); bool horizontal; bool vertical; Console.WriteLine(CalculationHelpers.CalculateDistance(3, -1, 3, 2.5, out horizontal, out vertical)); Console.WriteLine("Horizontal? " + horizontal); Console.WriteLine("Vertical? " + vertical); var peterOtherInfo = new PersonalInfo.PersonalInformation("From Sofia, born on 17.03.1992"); Student peter = new Student("Peter", "Ivanov", peterOtherInfo); var stellaOtherInfo = new PersonalInfo.PersonalInformation("From Vidin, gamer, high results, born on 03.11.1993"); Student stella = new Student("Stella", "Markova", stellaOtherInfo); Console.WriteLine("{0} older than {1} -> {2}", peter.FirstName, stella.FirstName, peter.IsOlderThan(stella)); }
public SingleVisit SaveSingleVisit(string licencePlate) { SingleVisit visit = SingleVisits.SingleOrDefault(x => x.ExitDate == null && x.Vehicle.NumberPlate == licencePlate); Vehicle vehicle = Vehicles.SingleOrDefault(x => x.NumberPlate == licencePlate); if (vehicle == null) //nie ma abo i pierwszy raz wjeżdża { vehicle = new Vehicle { NumberPlate = licencePlate }; Vehicles.Add(vehicle); } if (visit == null) //entry { visit = new SingleVisit { EntryDate = DateTime.Now, Vehicle = vehicle }; SingleVisits.Add(visit); } else //exit { visit.ExitDate = DateTime.Now; if (visit.Vehicle.Owner == null) //nie ma abonamentu { TimeSpan visitTime = (DateTime)visit.ExitDate - visit.EntryDate; visit.Price = CalculationHelpers.CauntThePrice(visitTime, Prices.ToList()); visit.Vehicle.TotalPay += (double)visit.Price; } } SaveChanges(); return(visit); }
public void CalculateGrazeLineSphereIntersection() { // arrange var sphereCenter = new Point(150, 150); const double SphereRadius = 5; var lineStartPoint = new Point(0, 0); var lineEndPoint = new Point(300, 286.179770816163); Point?firstIntersection; Point?secondIntersection; // act var intersection = CalculationHelpers.CalculateLineSphereIntersection( sphereCenter, SphereRadius, lineStartPoint, lineEndPoint, out firstIntersection, out secondIntersection); // assert Assert.AreEqual(1, intersection); Assert.IsNotNull(firstIntersection); Assert.AreEqual(153.45121834340819, firstIntersection.Value.X, 0.00001); Assert.AreEqual(146.38211498992513, firstIntersection.Value.Y, 0.00001); Assert.IsNull(secondIntersection); }
public static void Main() { Console.WriteLine(CalculationHelpers.CalcTriangleArea(3, 4, 5)); Console.WriteLine(CalculationHelpers.DigitToWord(5)); Console.WriteLine(CalculationHelpers.FindMaximumValue(5, -1, 3, 2, 14, 2, 3)); ConsoleWriter.PrintAsNumber(1.3, "f"); ConsoleWriter.PrintAsNumber(0.75, "%"); ConsoleWriter.PrintAsNumber(2.30, "r"); bool horizontal; bool vertical; Console.WriteLine(CalculationHelpers.CalculateDistance(3, -1, 3, 2.5, out horizontal, out vertical)); Console.WriteLine("Horizontal? " + horizontal); Console.WriteLine("Vertical? " + vertical); var peterOtherInfo = new PersonalInformation("From Paris, born on 10.10.2010"); Student peter = new Student("Pesho", "Peshov", peterOtherInfo); var stellaOtherInfo = new PersonalInformation("From Vraca, gamer, high results, born at 03.11.1993"); Student stella = new Student("Stella", "Peshova", stellaOtherInfo); Console.WriteLine("{0} older than {1} -> {2}", peter.FirstName, stella.FirstName, peter.IsOlderThan(stella)); }
public void PlottData() { Max = new float[dropDownList.Length - 1]; Min = new float[dropDownList.Length - 1]; nameList = new string[dropDownList.Length - 1]; if (TargetingScript.selectedTarget != null) { selectedIndex = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; } foreach (GameObject dataValues in GameObject.FindGameObjectsWithTag("DataBall")) { Destroy(dataValues); } foreach (var axisValue in GameObject.FindGameObjectsWithTag("3D_Axis_ValueText")) { Destroy(axisValue); } feature1Name = columnListDropDown[dropDownList[0].value]; feature2Name = columnListDropDown[dropDownList[1].value]; feature3Name = columnListDropDown[dropDownList[2].value]; feature4Name = columnListDropDown[dropDownList[3].value]; feature5Name = columnListDropDown[dropDownList[4].value]; for (int i = 0; i < dropDownList.Length - 1; i++) { nameList[i] = columnList[dropDownList[i].value + 1]; textList[i].text = nameList[i]; Min[i] = CalculationHelpers.FindMinValue(nameList[i], pointList); Max[i] = CalculationHelpers.FindMaxValue(nameList[i], pointList); } InstantiateDataPoint(Max, Min, nameList); RenderAxisValues(Max, Min); // Focus camera on new dataPoint if (CameraBehavior.teleportCamera) { CameraBehavior.RefocusCamera(pointList); } if (KNN.kPoints != null) { if (KNN.kPoints.Count > 0) { ColorManager.Blink(KNN.kPoints, pointList); } } }
public void CalculateLineIntersectionBetweenTwoNotCrossingLines() { // arrange var firstLineStartPoint = new Point(50, 700); var firstLineEndPoint = new Point(500, 57); var secondLineStartPoint = new Point(49, 699); var secondLineEndPoint = new Point(2, 30); // act var intersection = CalculationHelpers.GetLineIntersection( firstLineStartPoint, firstLineEndPoint, secondLineStartPoint, secondLineEndPoint); // assert Assert.IsNull(intersection); }
public void CalculateLineIntersectionBetweenTwoParallelLines() { // arrange var firstLineStartPoint = new Point(0, 0); var firstLineEndPoint = new Point(300, 300); var secondLineStartPoint = new Point(1, 1); var secondLineEndPoint = new Point(301, 301); // act var intersection = CalculationHelpers.GetLineIntersection( firstLineStartPoint, firstLineEndPoint, secondLineStartPoint, secondLineEndPoint); // assert Assert.IsNull(intersection); }
public void CalculateLineIntersectionBetweenTwoSuperPosedZeroLengthLines() { // arrange var firstLineStartPoint = new Point(150, 150); var firstLineEndPoint = new Point(150, 150); var secondLineStartPoint = new Point(150, 150); var secondLineEndPoint = new Point(150, 150); // act var intersection = CalculationHelpers.GetLineIntersection( firstLineStartPoint, firstLineEndPoint, secondLineStartPoint, secondLineEndPoint); // assert Assert.IsNull(intersection); }
public void CalculateLineIntersectionBetweenTwoLines() { // arrange var firstLineStartPoint = new Point(0, 0); var firstLineEndPoint = new Point(300, 300); var secondLineStartPoint = new Point(0, 300); var secondLineEndPoint = new Point(300, 0); // act var intersection = CalculationHelpers.GetLineIntersection( firstLineStartPoint, firstLineEndPoint, secondLineStartPoint, secondLineEndPoint); // assert Assert.IsNotNull(intersection); Assert.AreEqual(new Point(150, 150), intersection.Value); }
public void InputNewData() { // Set newDataPanel to active newDataPanel.SetActive(true); // Starting Y Position for inputFields float inputFieldYAxis = -17.5f; // Instantiate kAndWeighted prefab GameObject kAndWeighted = Instantiate(kAndWeightedPrefab, new Vector2(115, inputFieldYAxis), Quaternion.identity); // Set parent kAndWeighted.transform.SetParent(newDataContainer.transform, false); inputFieldYAxis -= 35; // Populate newDataPanel with inputFields for each attribute in dataset for (int i = 0; i < nFeatures; i++) { // Instatiate newDataPrefabs GameObject newInput = Instantiate(newDataInputFieldPrefab, new Vector2(115, inputFieldYAxis), Quaternion.identity); inputFieldYAxis -= 62; // Set parent newInput.transform.SetParent(newDataContainer.transform, false); // Get attribute textfield newInput.GetComponentInChildren <TMP_Text>().text = featureList[i]; // Set AverageValue in inputField newInput.GetComponentInChildren <TMP_InputField>().text = CalculationHelpers.FindAverage(featureList[i], pointList); } // Instantiate SaveAndCancel buttons GameObject saveAndCancelButtons = Instantiate(saveAndCancelButtonsPrefab, new Vector2(115, inputFieldYAxis), Quaternion.identity); // Set parent saveAndCancelButtons.transform.SetParent(newDataContainer.transform, false); // Add onClick listener to saveButton saveAndCancelButtons.transform.GetChild(0).gameObject.GetComponent <Button>().onClick.AddListener(SaveButton); // Add onClick listener to cancelButton saveAndCancelButtons.transform.GetChild(1).gameObject.GetComponent <Button>().onClick.AddListener(CancelButton); // When newDataPanel shows, newDataButton is none-Interactable GameObject.FindGameObjectWithTag("PCPNewDataButton").GetComponent <Button>().interactable = false; }
public static void Main() { Console.WriteLine(CalculationHelpers.CalculateTriangleArea(3, 4, 5)); Console.WriteLine(CalculationHelpers.DigitToText(5)); Console.WriteLine(CalculationHelpers.FindMaximumValue(5, -1, 3, 2, 14, 2, 3)); CalculationHelpers.FormatNumber(1.3, FormatOption.FloatingPoint); CalculationHelpers.FormatNumber(0.25, FormatOption.Percent); CalculationHelpers.FormatNumber(2.30, FormatOption.AlignRight); bool horizontal; bool vertical; Console.WriteLine(CalculationHelpers.CalculateDistance(3, -1, 3, 2.5, out horizontal, out vertical)); Console.WriteLine(CalculationHelpers.CheckAlignmentOfLine(3, -1, 3, 2.5)); Student studentOne = new Student() { FirstName = "Peter", LastName = "Ivanov", DateOfBirth = new DateTime(1980, 05, 01), Town = Town.Burgas, AdditionalInfo = "N/A" }; Student studentTwo = new Student() { FirstName = "Stella", LastName = "Markova", DateOfBirth = new DateTime(1993, 11, 03), Town = Town.Plovdiv, AdditionalInfo = "N/A" }; Console.WriteLine( "{0} older than {1} -> {2}", studentOne.FirstName, studentTwo.FirstName, studentOne.IsOlderThan(studentTwo)); }
private void CreateWindow() { List <string> attributes = CSVläsare.columnList; int ypos = 224; for (int i = 1; i < attributes.Count - 1; ++i) { Text descrip = Instantiate(description, new Vector2(-80, ypos), Quaternion.identity) as Text; descrip.transform.SetParent(newDataWindow.transform, false); descrip.text = attributes[i]; descrip.name = attributes[i]; InputField inputfield = Instantiate(input, new Vector2(71, ypos), Quaternion.identity) as InputField; inputfield.transform.SetParent(newDataWindow.transform, false); inputfield.name = attributes[i]; inputfield.text = CalculationHelpers.FindAverage(attributes[i], CSVläsare.pointList); ypos -= 20; } SaveData = Instantiate(button, new Vector2(71, ypos), Quaternion.identity) as Button; SaveData.GetComponentInChildren <Text>().text = "Save"; SaveData.transform.SetParent(newDataWindow.transform, false); SaveData.onClick.AddListener(SaveInput); SaveData.interactable = false; Button CancelButton = Instantiate(button, new Vector2(71, ypos - 20), Quaternion.identity) as Button; CancelButton.GetComponentInChildren <Text>().text = "Cancel"; CancelButton.onClick.AddListener(Cancel); CancelButton.transform.SetParent(newDataWindow.transform, false); newDataList.SetActive(true); newData.interactable = false; InvokeRepeating("SaveCheck", 0, 0.2f); }
public void TestGetSpell(String spellName) { Spell spell = CalculationHelpers.GetSpell(listFixture.SpellList, spellName); Assert.Equal(spellName, spell.Name); }
public void TestCalculateItemSetCritPercentage() { // round to 9 decimal digits Assert.Equal(8.547297297, Math.Round(CalculationHelpers.CalculateItemSetCritPercentage(listFixture.ItemList), 9)); }
public void TestCalculateItemSetMana() { Assert.Equal(4390, CalculationHelpers.CalculateItemSetMana(listFixture.ItemList)); }
public void TestCalculateItemSetAttribute(int expectedValue, String attribute) { Assert.Equal(expectedValue, CalculationHelpers.SumItemSetAttribute(listFixture.ItemList, attribute)); }
private void Denormalize() { if (KNN.KNNMode) { KNN.KNNMove = true; } if (SceneManager.GetActiveScene().name == "ParallelCoordinatePlot") { float mellanskillnad = ParallelCoordinatePlotter.ThisInstans.yMax - ParallelCoordinatePlotter.ThisInstans.yMin; string newPosition = (ParallelCoordinatePlotter.ThisInstans.yMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.y) / 10).ToString(); newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; ParallelCoordinatePlotter.ThisInstans.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().TargetFeature] = newPosition; if (KNN.KNNMode) { KNN.KNNMove = true; } ParallelCoordinatePlotter.ThisInstans.DrawBackgroundGrid(); ParallelCoordinatePlotter.ThisInstans.ReorderColumns(); } else if (SceneManager.GetActiveScene().name == "ValfriTeknik") { for (int i = 0; i < 3; i++) { float mellanskillnad = ScatterplotDimensions.Max[i] - ScatterplotDimensions.Min[i]; string newPosition = ""; if (i == 0) { newPosition = (ScatterplotDimensions.Min[i] + (mellanskillnad * TargetingScript.selectedTarget.transform.position.x) / 10).ToString("0.0"); } else if (i == 1) { newPosition = (ScatterplotDimensions.Min[i] + (mellanskillnad * TargetingScript.selectedTarget.transform.position.y) / 10).ToString("0.0"); } else if (i == 2) { newPosition = (ScatterplotDimensions.Min[i] + (mellanskillnad * TargetingScript.selectedTarget.transform.position.z) / 10).ToString("0.0"); } newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; ScatterplotDimensions.pointList[index][ScatterplotDimensions.nameList[i]] = newPosition; } ScatterplotDimensions.ThisInstans.PlottData(); } else if (SceneManager.GetActiveScene().name == "ScatterPlotMatrix") { float MinColumn = CalculationHelpers.FindMinValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column, ScatterPlotMatrix.pointList); float MaxColumn = CalculationHelpers.FindMaxValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column, ScatterPlotMatrix.pointList); float mellanskillnad = MaxColumn - MinColumn; string newPosition = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.x - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.x)) / 10).ToString("0.0"); newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; ScatterPlotMatrix.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column] = newPosition; float MinRow = CalculationHelpers.FindMinValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row, ScatterPlotMatrix.pointList); float MaxRow = CalculationHelpers.FindMaxValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row, ScatterPlotMatrix.pointList); mellanskillnad = MaxRow - MinRow; newPosition = (MinRow + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.y - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.y)) / 10).ToString("0.0"); newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; ScatterPlotMatrix.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row] = newPosition; ScatterPlotMatrix.ThisInstans.PlottData(); } else { float mellanskillnad = DataPlotter.ThisInstans.xMax - DataPlotter.ThisInstans.xMin; string newPosition = (DataPlotter.ThisInstans.xMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.x) / 10).ToString(); newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; DataPlotter.pointList[index][DataPlotter.xName] = newPosition; mellanskillnad = DataPlotter.ThisInstans.yMax - DataPlotter.ThisInstans.yMin; newPosition = (DataPlotter.ThisInstans.yMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.y) / 10).ToString(); newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; DataPlotter.pointList[index][DataPlotter.yName] = newPosition; if (MainMenu.renderMode == 1) { mellanskillnad = DataPlotter.ThisInstans.zMax - DataPlotter.ThisInstans.zMin; newPosition = (DataPlotter.ThisInstans.zMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.z) / 10).ToString(); newPosition = newPosition.Replace(',', '.'); index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; DataPlotter.pointList[index][DataPlotter.zName] = newPosition; } DataPlotter.ThisInstans.PlottData(); } }
public bool CheckPermission(ref string plateNumber, string loosedPlateNumber) { Vehicle vehicle = null; string[] expectedPlateNumber = null; if (plateNumber != string.Empty && plateNumber.Count() >= 5) { string tempPlateNumber = plateNumber; vehicle = Vehicles.SingleOrDefault(x => x.NumberPlate == tempPlateNumber); if (vehicle == null) { expectedPlateNumber = Vehicles.Select(x => x.NumberPlate).ToArray().Where(l => CalculationHelpers.LevenshteinDistance(tempPlateNumber, l) == 1).ToArray(); if (expectedPlateNumber.Count() == 1) { if (plateNumber.Count() == expectedPlateNumber[0].Count()) { string expectedString = expectedPlateNumber[0]; for (int i = 0; i < plateNumber.Count(); i++) { if (expectedString[i] == loosedPlateNumber[i] && expectedString[i] != plateNumber[i]) { vehicle = Vehicles.SingleOrDefault(x => x.NumberPlate == expectedString); plateNumber = expectedString; } } } } } } else { return(false); } return(true); }
public void PlottData() { if (TargetingScript.selectedTarget != null) { selectedIndex = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; selectedRow = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row; selectedColumn = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column; } ResetDataPlot(); for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { try { feature1Name = featureList[columnDropdownList[j].value]; feature2Name = featureList[columnDropdownList[k].value]; feature1 = featureList[columnDropdownList[0].value]; feature2 = featureList[columnDropdownList[1].value]; feature3 = featureList[columnDropdownList[2].value]; feature4 = featureList[columnDropdownList[3].value]; if (j == k) { GameObject summonPlane = Instantiate(planePointBackground, new Vector3(k * 1.2F + 0.5F, j * 1.2F + 0.5F, 0) * plotScale, Quaternion.Euler(0, 90, -90)); //Le textfält TMP_Text textField = Instantiate(ScatterplotMatrixText, new Vector3(k * 1.2F + 1, j * 1.2F + 0.3F, -0.01f) * plotScale, Quaternion.identity); textField.text = featureList[columnDropdownList[j].value]; } else if (k < j) { GameObject summonPlane = Instantiate(planePointBackground, new Vector3(k * 1.2F + 0.5F, j * 1.2F + 0.5F, 0) * plotScale, Quaternion.Euler(0, 90, -90)); // Get maxes of each axis float xMax = CalculationHelpers.FindMaxValue(feature1Name, pointList); float yMax = CalculationHelpers.FindMaxValue(feature2Name, pointList); // Get minimums of each axis float xMin = CalculationHelpers.FindMinValue(feature1Name, pointList); float yMin = CalculationHelpers.FindMinValue(feature2Name, pointList); string valueString; //Loop through Pointlist for (var i = 0; i < pointList.Count; i++) { GameObject dataPoint; // Get value in poinList at ith "row", in "column" Name, normalize valueString = pointList[i][feature1Name].ToString(); float x = (float.Parse(valueString, CultureInfo.InvariantCulture) - xMin) / (xMax - xMin); valueString = pointList[i][feature2Name].ToString(); float y = (float.Parse(valueString, CultureInfo.InvariantCulture) - yMin) / (yMax - yMin); int index = targetFeatures.IndexOf(pointList[i][columnList[columnList.Count - 1]].ToString()); // Instantiate dataPoint dataPoint = Instantiate(PointPrefab, new Vector3(x + k * 1.2F, y + j * 1.2F, 0) * plotScale, Quaternion.identity); // Set transform name dataPoint.transform.name = pointList[i][feature1Name] + " " + pointList[i][feature2Name]; // Set parent dataPoint.transform.parent = PointHolder.transform; dataPoint.GetComponent <StoreIndexInDataBall>().Index = i; dataPoint.GetComponent <StoreIndexInDataBall>().TargetFeature = pointList[i][columnList[columnList.Count - 1]].ToString(); dataPoint.GetComponent <StoreIndexInDataBall>().Feature1 = feature1; dataPoint.GetComponent <StoreIndexInDataBall>().Feature2 = feature2; dataPoint.GetComponent <StoreIndexInDataBall>().Column = featureList[columnDropdownList[j].value]; dataPoint.GetComponent <StoreIndexInDataBall>().Row = featureList[columnDropdownList[k].value]; dataPoint.GetComponent <StoreIndexInDataBall>().Feature3 = feature3; dataPoint.GetComponent <StoreIndexInDataBall>().Feature4 = feature4; dataPoint.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder = new Vector3(k * 1.2F + 0.5F, j * 1.2F + 0.5F, 0) * plotScale; dataPoint.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder += new Vector3(-5, -5, 0); if (!pointList[i].ContainsKey("DataBall")) { pointList[i].Add("DataBall", dataPoint); } else { pointList[i]["DataBall"] = dataPoint; } // Set color if (targetFeatures.Count() <= 10) { ColorManager.ChangeColor(dataPoint, index); } else { dataPoint.GetComponent <Renderer>().material.color = new Color(x, y, y, 1.0f); } //Reselect target if one was selected before. if (selectedIndex == i && dataPoint.GetComponent <StoreIndexInDataBall>().Column == selectedColumn && dataPoint.GetComponent <StoreIndexInDataBall>().Row == selectedRow) { TargetingScript.selectedTarget = dataPoint; TargetingScript.colorOff = TargetingScript.selectedTarget.GetComponent <Renderer>().material.color; TargetingScript.selectedTarget.GetComponent <Renderer>().material.color = Color.white; TargetingScript.selectedTarget.transform.localScale += new Vector3(+0.01f, +0.01f, +0.01f); selectedIndex = -1; } if (KNN.KNNMode && i == pointList.Count() - 1) { dataPoint.GetComponent <Renderer>().material.color = Color.white; dataPoint.transform.localScale += new Vector3(-0.01f, -0.01f, -0.01f); } } } } catch (Exception) { } if (KNN.kPoints != null) { if (KNN.kPoints.Count > 0) { ColorManager.Blink(KNN.kPoints, pointList); } } } } // Focus camera on new dataPoint if (CameraBehavior.teleportCamera) { CameraBehavior.RefocusCamera(pointList); } }
public void PlottData() { if (TargetingScript.selectedTarget != null) { selectedIndex = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; } DestroyDataBallsAndAxisValues(); xName = columnList[xList.value + 1]; yName = columnList[yList.value + 1]; xAxisText.text = xName; yAxisText.text = yName; // Get maxes of each axis xMax = CalculationHelpers.FindMaxValue(xName, pointList); yMax = CalculationHelpers.FindMaxValue(yName, pointList); zMax = 0f; // Get minimums of each axis xMin = CalculationHelpers.FindMinValue(xName, pointList); yMin = CalculationHelpers.FindMinValue(yName, pointList); zMin = 0f; // If renderMode is 3D if (MainMenu.renderMode == 1) { zName = columnList[zList.value + 1]; zAxisText.text = zName; zMax = CalculationHelpers.FindMaxValue(zName, pointList); zMin = CalculationHelpers.FindMinValue(zName, pointList); } string valueString; // If renderMode is 2D if (MainMenu.renderMode == 0) { // Destroy all dataValues before plotting new ones foreach (GameObject dataValues in GameObject.FindGameObjectsWithTag("dataValues")) { Destroy(dataValues); } DrawBackgroundGridAndValues(); } // If renderMode is 3D if (MainMenu.renderMode == 1) { RenderAxisValues(); } // Loop through Pointlist for (var i = 0; i < pointList.Count; i++) { GameObject dataPoint; // Get value in poinList at ith "row", in "column" Name, normalize valueString = pointList[i][xName].ToString(); float x = (float.Parse(valueString, CultureInfo.InvariantCulture) - xMin) / (xMax - xMin); valueString = pointList[i][yName].ToString(); float y = (float.Parse(valueString, CultureInfo.InvariantCulture) - yMin) / (yMax - yMin); float z = 1; //Instantiate datapoints if (MainMenu.renderMode == 0) { dataPoint = Instantiate(PointPrefab, new Vector3(x, y, 0) * plotScale, Quaternion.identity); dataPoint.transform.name = pointList[i][columnList[0]] + " " + pointList[i][xName] + " " + pointList[i][yName] + " " + pointList[i][columnList[columnList.Count() - 1]]; dataPoint.transform.parent = PointHolder.transform; } else { valueString = pointList[i][zName].ToString(); z = (float.Parse(valueString, CultureInfo.InvariantCulture) - zMin) / (zMax - zMin); dataPoint = Instantiate(PointPrefab, new Vector3(x, y, z) * plotScale, Quaternion.identity); dataPoint.transform.name = pointList[i][columnList[0]] + " " + pointList[i][xName] + " " + pointList[i][yName] + " " + pointList[i][zName] + " " + pointList[i][columnList[columnList.Count() - 1]]; dataPoint.transform.parent = PointHolder.transform; } if (!pointList[i].ContainsKey("DataBall")) { pointList[i].Add("DataBall", dataPoint); } else { pointList[i]["DataBall"] = dataPoint; } //Store values in dataPoint dataPoint.GetComponent <StoreIndexInDataBall>().Index = i; dataPoint.GetComponent <StoreIndexInDataBall>().TargetFeature = pointList[i][columnList[columnList.Count - 1]].ToString(); dataPoint.GetComponent <StoreIndexInDataBall>().Feature1 = xName; dataPoint.GetComponent <StoreIndexInDataBall>().Feature2 = yName; if (zName != null) { dataPoint.GetComponent <StoreIndexInDataBall>().Feature3 = zName; } //Assign color to dataPoint int index = targetFeatures.IndexOf(pointList[i][columnList[columnList.Count - 1]].ToString()); if (targetFeatures.Count() <= 10) { ColorManager.ChangeColor(dataPoint, index); } else { dataPoint.GetComponent <Renderer>().material.color = new Color(x, y, z, 1.0f); } //Reselect target if one was selected before. if (selectedIndex == i) { TargetingScript.selectedTarget = dataPoint; TargetingScript.colorOff = TargetingScript.selectedTarget.GetComponent <Renderer>().material.color; TargetingScript.selectedTarget.GetComponent <Renderer>().material.color = Color.white; TargetingScript.selectedTarget.transform.localScale += new Vector3(+0.01f, +0.01f, +0.01f); selectedIndex = -1; } } // Focus camera on new dataPoint if (CameraBehavior.teleportCamera) { CameraBehavior.RefocusCamera(pointList); } if (KNN.kPoints != null) { if (KNN.kPoints.Count > 0) { ColorManager.Blink(KNN.kPoints, pointList); } } }
public void DrawBackgroundGrid() { foreach (GameObject dataValues in GameObject.FindGameObjectsWithTag("dataValues")) { Destroy(dataValues); } foreach (GameObject dataValues in GameObject.FindGameObjectsWithTag("DataLineGrid")) { Destroy(dataValues); } // Draw vertical lines for (int i = 1; i <= 4; i++) { float xPos = SetColumnPosition(i); GameObject xLine = Instantiate(LinePrefab, new Vector3(xPos, 0f, -0.001f) * plotScale, Quaternion.identity); xLine.transform.tag = "DataLineGrid"; xLine.transform.parent = PointHolder.transform; xLine.transform.name = $"Column{i}Line"; LineRenderer xLineRenderer = xLine.GetComponent <LineRenderer>(); xLineRenderer.positionCount = 2; xLineRenderer.startWidth = 0.025f; xLineRenderer.endWidth = 0.025f; xLineRenderer.SetPosition(0, new Vector3(xPos, -0.05f, -0.001f) * plotScale); xLineRenderer.SetPosition(1, new Vector3(xPos, 1.05f, -0.001f) * plotScale); xLineRenderer.material.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); } yMax = 0f; yMin = float.Parse(pointList[0][featureList[0]].ToString(), CultureInfo.InvariantCulture); // Find and render Max- & Min-values on Y-Axis for (int i = 0; i < featureList.Count; i++) { float yMaxTempValue = CalculationHelpers.FindMaxValue(featureList[i], pointList); if (yMaxTempValue > yMax) { yMax = yMaxTempValue; } float yMinTempValue = CalculationHelpers.FindMinValue(featureList[i], pointList); if (yMinTempValue < yMin) { yMin = yMinTempValue; } } // Draw horizontal lines for (int i = 0; i <= 10; i++) { // Instantiate lines, set parent, set transform name GameObject yLine = Instantiate(LinePrefab, new Vector3(0, 0f, -0.001f) * plotScale, Quaternion.identity); yLine.transform.tag = "DataLineGrid"; yLine.transform.parent = PointHolder.transform; yLine.transform.name = $"Value{i}Line"; LineRenderer yLineRenderer = yLine.GetComponent <LineRenderer>(); yLineRenderer.positionCount = 2; yLineRenderer.startWidth = 0.025f; yLineRenderer.endWidth = 0.025f; yLineRenderer.SetPosition(0, new Vector3(0.15f, (float)i / 10, -0.001f) * plotScale); yLineRenderer.SetPosition(1, new Vector3(1.45f, (float)i / 10, -0.001f) * plotScale); yLineRenderer.material.color = new Color(0.5f, 0.5f, 0.5f, 0.4f); TMP_Text valuePointY = Instantiate(valuePrefab, new Vector3(1f, 0 + i, 0), Quaternion.identity); valuePointY.transform.name = $"Value{i}LineText"; float yValue = ((yMax - yMin) / 10) * i + yMin; valuePointY.text = yValue.ToString("0.00"); } }
//Uppdatera edit position fältet i realtid private void Denormalize() { int index = TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Index; if (SceneManager.GetActiveScene().name == "ValfriTeknik") { for (int i = 0; i < 3; i++) { float mellanskillnad = ScatterplotDimensions.Max[i] - ScatterplotDimensions.Min[i]; if (i == 0) { Xvalue.text = (ScatterplotDimensions.Min[i] + (mellanskillnad * TargetingScript.selectedTarget.transform.position.x) / 10).ToString("0.0").Replace('.', ','); } else if (i == 1) { Yvalue.text = (ScatterplotDimensions.Min[i] + (mellanskillnad * TargetingScript.selectedTarget.transform.position.y) / 10).ToString("0.0").Replace('.', ','); } else if (i == 2) { Zvalue.text = (ScatterplotDimensions.Min[i] + (mellanskillnad * TargetingScript.selectedTarget.transform.position.z) / 10).ToString("0.0").Replace('.', ','); } } } else if (SceneManager.GetActiveScene().name == "ScatterPlotMatrix") { float MinColumn = CalculationHelpers.FindMinValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column, ScatterPlotMatrix.pointList); float MaxColumn = CalculationHelpers.FindMaxValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column, ScatterPlotMatrix.pointList); float mellanskillnad = MaxColumn - MinColumn; float MinRow = CalculationHelpers.FindMinValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row, ScatterPlotMatrix.pointList); float MaxRow = CalculationHelpers.FindMaxValue(TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row, ScatterPlotMatrix.pointList); float mellanskillnadRow = MaxRow - MinRow; if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature1) { Xvalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.x - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.x)) / 10).ToString("0.0"); } else if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature1) { Xvalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.y - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.y)) / 10).ToString("0.0"); } else { Xvalue.text = ScatterPlotMatrix.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature1].ToString().Replace('.', ','); } if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature2) { Yvalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.x - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.x)) / 10).ToString("0.0"); } else if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature2) { Yvalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.y - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.y)) / 10).ToString("0.0"); } else { Yvalue.text = ScatterPlotMatrix.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature2].ToString().Replace('.', ','); } if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature3) { Zvalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.x - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.x)) / 10).ToString("0.0"); } else if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature3) { Zvalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.y - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.y)) / 10).ToString("0.0"); } else { Zvalue.text = ScatterPlotMatrix.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature1].ToString().Replace('.', ','); } if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Column == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature4) { Avalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.x - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.x)) / 10).ToString("0.0"); } else if (TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Row == TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature4) { Avalue.text = (MinColumn + (mellanskillnad * (TargetingScript.selectedTarget.transform.position.y - TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().ScatterPlotMatrixPositionFinder.y)) / 10).ToString("0.0"); } else { Avalue.text = ScatterPlotMatrix.pointList[index][TargetingScript.selectedTarget.GetComponent <StoreIndexInDataBall>().Feature4].ToString().Replace('.', ','); } } else { float mellanskillnad = DataPlotter.ThisInstans.xMax - DataPlotter.ThisInstans.xMin; Xvalue.text = (DataPlotter.ThisInstans.xMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.x) / 10).ToString("0.0"); mellanskillnad = DataPlotter.ThisInstans.yMax - DataPlotter.ThisInstans.yMin; Yvalue.text = (DataPlotter.ThisInstans.yMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.y) / 10).ToString("0.0"); if (MainMenu.renderMode == 1) { mellanskillnad = DataPlotter.ThisInstans.zMax - DataPlotter.ThisInstans.zMin; Zvalue.text = (DataPlotter.ThisInstans.zMin + (mellanskillnad * TargetingScript.selectedTarget.transform.position.z) / 10).ToString("0.0"); } } }