public void Contains_Success() { Vector2 foci = new Vector2(.5f, .5f); Add(0, 0); Add(1, 0); Add(1, 1); Add(0, 1); Calculate(); Assert.IsTrue(polygon.Contains( foci )); }
private void Update() { if (polygon.Contains(point.position)) { line.SetColors(Color.red, Color.red); } else { line.SetColors(Color.white, Color.white); } }
private static List <MapNode> FindCandidatesInSquare( Grid grid, Vector2 plannerLocation, Vector2 plannerToClosestEnemyCorrectLength, Vector2 closestEnemyToDirection ) { Vector2 closestEnemyToDirectionNormalized = closestEnemyToDirection.normalized; Vector2 closestEnemyToDirectionCorrectLength = closestEnemyToDirectionNormalized * plannerToClosestEnemyCorrectLength.magnitude; List <Vector2> candidateBoundsPoints = new List <Vector2>(); Vector2 plannerAtDirection = plannerLocation + closestEnemyToDirectionCorrectLength; Vector2 enemyLocation = plannerLocation + plannerToClosestEnemyCorrectLength; Vector2 enemyAtDirection = enemyLocation + closestEnemyToDirectionCorrectLength; candidateBoundsPoints.Add(plannerLocation); candidateBoundsPoints.Add(plannerAtDirection); candidateBoundsPoints.Add(enemyLocation); candidateBoundsPoints.Add(enemyAtDirection); ConvexPolygon candidateBounds = new ConvexPolygon(candidateBoundsPoints); float minXOrientedSquare = candidateBoundsPoints.Min(v => v.x); float minYOrientedSquare = candidateBoundsPoints.Min(v => v.y); float maxXOrientedSquare = candidateBoundsPoints.Max(v => v.x); float maxYOrientedSquare = candidateBoundsPoints.Max(v => v.y); Point startPoint = grid.WorldCoordToNode( new Vector2(minXOrientedSquare, minYOrientedSquare) ); Point endPoint = grid.WorldCoordToNode( new Vector2(maxXOrientedSquare, maxYOrientedSquare) ); List <MapNode> candidates = new List <MapNode>(); for (int x = startPoint.x; x < endPoint.x; x++) { for (int y = startPoint.y; y < endPoint.y; y++) { Point currentPoint = new Point(x, y); Vector3 candidateLocation = grid.NodeToWorldCoord( currentPoint ); if (candidateBounds.Contains( candidateLocation.To2D() )) { candidates.Add( grid.GetMapNodeAt( currentPoint ) ); } } } return(candidates); }