Exemple #1
0
    /// <summary>
    /// Chooses a split polygon by scoring the polygon choices.
    ///
    /// This algorithm is approximately O(N**2), so it's likely to take a while.
    ///
    /// This method runs as a coroutine so should be run until completion.
    /// </summary>
    /// <param name="polygons">The polygons to choose from</param>
    /// <param name="result">The resulting split polygon, along with classifications for other polygons in relation.</param>
    /// <returns></returns>
    private static IEnumerator ChooseSplitPolygonBestChoice(List <Polygon> polygons, ChooseSplitPolygonResult result)
    {
        int bestChoiceScore = int.MaxValue;

        foreach (var p1 in polygons)
        {
            if (p1.Used)
            {
                continue;
            }

            ChooseSplitPolygonResult potentialResult = new ChooseSplitPolygonResult(p1);
            potentialResult.Classify(polygons);

            int frontfaces = potentialResult.Front.Count - 1; // -1 because p1 is included.
            int backfaces  = potentialResult.Back.Count;
            int splits     = potentialResult.Spanning.Count;

            int score = Math.Abs(frontfaces - backfaces) + (splits * 8);

            if (score < bestChoiceScore)
            {
                bestChoiceScore = score;
                result.Assign(potentialResult);
            }

            yield return(null);
        }
    }
Exemple #2
0
    /// <summary>
    /// Chooses a split polygon at random (non-deterministic). Also classifies
    /// the rest of the polygons by whether they are in front, behind, spanning, or coincident.
    ///
    /// This runs as a coroutine, however, this specific version only iterates once.
    /// </summary>
    /// <param name="polygons">The polygons to choose from</param>
    /// <param name="result">The resulting polygons and polygon classification</param>
    /// <returns></returns>
    private static IEnumerator ChooseSplitPolygonRandom(List <Polygon> polygons, ChooseSplitPolygonResult result)
    {
        int index = Random.Range(0, polygons.Count);

        result.Assign(new ChooseSplitPolygonResult(polygons[index]));
        result.Classify(polygons);
        yield return(null);
    }