Exemplo n.º 1
0
    void Start()
    {
        visualizeController = GetComponent <VisualizerController3D>();

        //Get the random points
        HashSet <Vector2> randomPoints = TestAlgorithmsHelpMethods.GenerateRandomPoints2D(0, halfSquareSize: 6f, numberOfPoints: 25);

        //To MyVector2
        HashSet <MyVector2> randomPoints_2d = new HashSet <MyVector2>(randomPoints.Select(x => x.ToMyVector2()));

        //Hull
        List <Vector3> hullPoints = TestAlgorithmsHelpMethods.GetPointsFromParent(hullConstraintParent);

        List <MyVector2> hullPoints_2d = hullPoints.Select(x => x.ToMyVector2()).ToList();;

        //Holes
        HashSet <List <MyVector2> > allHolePoints_2d = new HashSet <List <MyVector2> >();

        foreach (Transform holeParent in holeConstraintParents)
        {
            List <Vector3> holePoints = TestAlgorithmsHelpMethods.GetPointsFromParent(holeParent);

            if (holePoints != null)
            {
                List <MyVector2> holePoints_2d = holePoints.Select(x => x.ToMyVector2()).ToList();

                allHolePoints_2d.Add(holePoints_2d);
            }
        }


        //Normalize to range 0-1
        //We should use all points, including the constraints because the hole may be outside of the random points
        List <MyVector2> allPoints = new List <MyVector2>();

        allPoints.AddRange(randomPoints_2d);

        allPoints.AddRange(hullPoints_2d);

        foreach (List <MyVector2> hole in allHolePoints_2d)
        {
            allPoints.AddRange(hole);
        }

        Normalizer2 normalizer = new Normalizer2(allPoints);

        HashSet <MyVector2> randomPoints_2d_normalized = normalizer.Normalize(randomPoints_2d);

        List <MyVector2> hullPoints_2d_normalized = normalizer.Normalize(hullPoints_2d);

        HashSet <List <MyVector2> > allHolePoints_2d_normalized = new HashSet <List <MyVector2> >();

        foreach (List <MyVector2> hole in allHolePoints_2d)
        {
            List <MyVector2> hole_normalized = normalizer.Normalize(hole);

            allHolePoints_2d_normalized.Add(hole_normalized);
        }



        StartCoroutine(GenerateConstrainedDelaunayLoop(randomPoints_2d_normalized, hullPoints_2d_normalized, allHolePoints_2d_normalized, shouldRemoveTriangles: true, new HalfEdgeData2(), normalizer));
    }