public static PointIsInside ( |
||
point | ||
nodes | List |
|
edges | List |
|
Результат | bool |
void GenerateSubEdgeTargets() { UnityEngine.Random.seed = subEdgeRandomSeed; int safeCount = 0; int pointCount = 0; subEdgeTargets = new List <Vector3>(); while (safeCount < 1000) { safeCount++; //Get random point inside the boundaries float randX = UnityEngine.Random.Range(minX, maxX); float randZ = UnityEngine.Random.Range(minZ, maxZ); Vector3 point = new Vector3(randX, 0f, randZ); //If point is inside the polygon, proceed if (EdgeGraphUtility.PointIsInside(point, nodes, edges)) { //Check if the point is inside the margins if (subEdgeTargetMargin > 0) { float toClosest = Mathf.Infinity; //Edge closest; foreach (var edge in edges) { Vector2 closestXZ = Edge.GetClosestPointOnEdge(point, nodes.Find(x => x.ID == edge.Node1).Position, nodes.Find(x => x.ID == edge.Node2).Position); Vector3 closestPoint = new Vector3(closestXZ.x, 0f, closestXZ.y); float dist = Vector3.Distance(point, closestPoint); if (dist < toClosest) { toClosest = dist; //closest = edge; } } if (toClosest < subEdgeTargetMargin) { continue; } } //If new point is too close to existing one, discard it bool pointIsTooClose = false; foreach (var target in subEdgeTargets) { if (Vector3.Distance(point, target) < subEdgeMinDistance) { pointIsTooClose = true; break; } } if (!pointIsTooClose) { subEdgeTargets.Add(point); pointCount++; } } if (pointCount >= subEdgeTargetCount) { break; } } }