/// <summary> /// Returns true if there is a duplicate icon in the scene. Uses locality hashing to do so /// </summary> Boolean SameIconExists(Vector3 point, string text) { int key = LevenshteinDistance.GetLevenshteinKey(text); List <GameObject> iconList; // Compare icon against all other icons that have a similar text if (iconDictionary.TryGetValue(key, out iconList)) { foreach (GameObject go in iconList) { string goText = go.GetComponent <IconAction>().Text; if (LevenshteinDistance.GetLevenshteinDistance(text, goText) < LevenshteinDistance.ToleranceLevel && Vector3.Distance(point, go.transform.position) < 0.135) { return(true); } } } return(false); }
/// <summary> /// Place icons given a hit to the spatial mapping /// </summary> public void PlaceIcons(RaycastHit centerHit, String runningText, Vector3 topLeft, Vector3 topRight, Vector3 bottomRight, Vector3 bottomLeft, Vector3 combinedTopLeft, Vector3 combinedTopRight, Vector3 combinedBottomRight, Vector3 combinedBottomLeft) { if (SameIconExists(centerHit.point, runningText)) // Avoid duplicates { return; } // Put icon into the scene GameObject icon = Instantiate(Icon); icon.transform.position = centerHit.point; icon.GetComponent <IconAction>().Text = runningText; icon.transform.rotation = Quaternion.LookRotation(-centerHit.normal); // Change icon size ChangeCircleIconScale(icon, combinedTopLeft, combinedTopRight, combinedBottomLeft); // Change icon color based on coordinates icon.GetComponent <Interactible>().OriginalMaterial = GetMaterial(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y, icon); // Add icon to dictionary to prevent duplicates later on int key = LevenshteinDistance.GetLevenshteinKey(runningText); List <GameObject> iconList; if (iconDictionary.TryGetValue(key, out iconList)) { iconList.Add(icon); } else { iconList = new List <GameObject>(); iconList.Add(icon); iconDictionary.Add(key, iconList); } // Update counts and indicators NumIcons++; numIconsDetectedInOneCall++; NewTextDetected = true; }