Exemple #1
0
 public void Reset()
 {
     AlphaCut   = default(double);
     ActiveEdge = default(TEdge);
     Case       = IntersectionCase.NotIntersecting;
     ActiveLine = default(BoundaryLine);
 }
Exemple #2
0
        bool FindIntersection(Edge <T> edge, BoundaryLine line)
        {
            state.ActiveEdge = edge;
            bool foundIntersection;

            if (isFirstIntersection)
            {
                foundIntersection = LineIntersect.FindFirst(edge, line, ref state.Case, out state.AlphaCut);
            }
            else
            {
                foundIntersection = LineIntersect.Find(edge, line, ref state.Case, out state.AlphaCut);
            }
            return(foundIntersection);
        }
Exemple #3
0
 public void CutOut(IDMesh <T> mesh, Boundary <T> boundary)
 {
     this.boundaryLines = BoundaryLineEnumerator.GetEnumerator(BoundaryLine.Copy(boundary.BoundaryLines));
     Initialize(mesh, boundary);
     CutOut();
 }
Exemple #4
0
 public MeshCell <T> GetFirst(BoundaryLine boundaryLine)
 {
     insideCells.SetFirstCell((Vector)boundaryLine.Start);
     return(insideCells.GetFirstCell());
 }
    // MAP DRAWING PROCESS
    // List of BoundaryLines
    // Pick any BoundaryLine and ask it if it still needs to be included
    // BoundaryLine knows if needs inclusion by the number of factions claiming each of its points
    // If neither point claimed, skip it and tell it not to be included
    // Pick faction claimed and draw the whole border
    public void Draw()
    {
        foreach (BoundaryPoint resetPoint in _boundaryPoints.Values)
        {
            resetPoint.ResetDraw();
        }

        bool stillDrawing = true;

        while (stillDrawing) // Run passes through the points till they've been drawn for all factions
        {
            stillDrawing = false;
            foreach (BoundaryPoint drawPoint in _boundaryPoints.Values)
            {
                // Keep going till we find a point where factions still need to be drawn
                if (drawPoint.FactionsToDraw.Count == 0)
                {
                    continue;
                }

                // Find any cross-faction border lines for the point
                List <BoundaryLine> linesWithPoint = _lineReference[drawPoint];
                Faction             currentFaction = Faction.None;
                BoundaryLine        firstNextLine  = null;

                foreach (BoundaryLine l in linesWithPoint)
                {
                    if (firstNextLine != null)
                    {
                        break;
                    }

                    List <Faction> commonFactions = l.CommonFactions();
                    if (commonFactions.Count < 2)
                    {
                        continue;                             // Needs to be a border line
                    }
                    // Make sure that faction that still needs to be drawn is part of the border
                    foreach (Faction f in drawPoint.FactionsToDraw)
                    {
                        if (commonFactions.Contains(f))
                        {
                            currentFaction = f;
                            firstNextLine  = l;
                            break;
                        }
                    }
                }

                stillDrawing = true;
                // We got a live one! Time to start a new blob.
                List <BoundaryPoint> blobPoints = new List <BoundaryPoint>();

                BoundaryPoint currentPoint = drawPoint;
                BoundaryPoint nextPoint    = null;
                if (drawPoint == firstNextLine.A)
                {
                    nextPoint = firstNextLine.B;
                }
                else
                {
                    nextPoint = firstNextLine.A;
                }
                BoundaryLine lastLine = firstNextLine;

                // Add till we get back to original point
                while (!blobPoints.Contains(currentPoint))
                {
                    blobPoints.Add(currentPoint);
                    currentPoint = nextPoint;
                    nextPoint    = null;

                    // Find the next point
                    linesWithPoint = _lineReference[currentPoint];
                    linesWithPoint.Remove(lastLine); // Don't go backward!

                    BoundaryLine nextLine = null;
                    foreach (BoundaryLine l in linesWithPoint)
                    {
                        if (nextLine != null)
                        {
                            break;
                        }

                        List <Faction> commonFactions = l.CommonFactions();
                        if (commonFactions.Count > 1 && commonFactions.Contains(currentFaction))
                        {
                            nextLine = l;
                        }
                    }

                    if (currentPoint == nextLine.A)
                    {
                        nextPoint = nextLine.B;
                    }
                    else
                    {
                        nextPoint = nextLine.A;
                    }
                    lastLine = nextLine;
                }

                foreach (BoundaryPoint p in blobPoints)
                {
                    p.MarkDrawn(currentFaction);
                }

                _blobs.Add(blobPoints);

                for (int i = 0; i < blobPoints.Count; i++)
                {
                    int nextI = i + 1;
                    if (nextI == blobPoints.Count)
                    {
                        nextI = 0;
                    }
                    GameObject go         = new GameObject("Line");
                    GizmoLine  lineToDraw = go.AddComponent <GizmoLine>();
                    lineToDraw.A      = blobPoints[i].Point;
                    lineToDraw.B      = blobPoints[nextI].Point;
                    lineToDraw.drawMe = true;
                }
                Debug.Log("BLOB DONE: " + blobPoints.Count);
                return;
            }
        }
    }