// return index of point in the middle of p1 and p2 private int GetMiddlePoint(int p1, int p2, List<Vector3> vertices, Dictionary<MiddlePointCacheKey, int> middlePointIndexCache) { // first check if we have it already int smallerIndex = Mathf.Min(p1, p2); int greaterIndex = Mathf.Max(p1, p2); MiddlePointCacheKey key = new MiddlePointCacheKey { Key1 = smallerIndex, Key2 = greaterIndex }; int ret; if (middlePointIndexCache.TryGetValue(key, out ret)) { return ret; } // not in cache, calculate it Vector3 point1 = vertices[p1]; Vector3 point2 = vertices[p2]; Vector3 middle = new Vector3 ( (point1.x + point2.x) / 2f, (point1.y + point2.y) / 2f, (point1.z + point2.z) / 2f ); // add vertex makes sure point is on unit sphere int i = vertices.Count; vertices.Add(middle.normalized * Radius); // store it, return index middlePointIndexCache.Add(key, i); return i; }
public override bool Equals(object obj) { if (obj is MiddlePointCacheKey) { MiddlePointCacheKey k = (MiddlePointCacheKey)obj; return(k.Key1 == Key1 && k.Key2 == Key2); } return(false); }
// return index of point in the middle of p1 and p2 private int GetMiddlePoint(int p1, int p2, List<Vector3> vertices, Dictionary<MiddlePointCacheKey, int> middlePointIndexCache) { // first check if we have it already int smallerIndex = Mathf.Min(p1, p2); int greaterIndex = Mathf.Max(p1, p2); MiddlePointCacheKey key = new MiddlePointCacheKey { Key1 = smallerIndex, Key2 = greaterIndex }; int ret; if (middlePointIndexCache.TryGetValue(key, out ret)) { return ret; } // not in cache, calculate it Vector3 point1 = vertices[p1]; Vector3 point2 = vertices[p2]; Vector3 middle = new Vector3 ( (point1.x + point2.x) / 2f, (point1.y + point2.y) / 2f, (point1.z + point2.z) / 2f ); // add vertex makes sure point is on unit sphere int i = vertices.Count; vertices.Add(middle.normalized * Radius); // store it, return index middlePointIndexCache.Add(key, i); return i; }