Esempio n. 1
0
        private static void ClearMentions(Util.Set <IParse> mentions, IParse nounPhrase)
        {
            Util.Span nounPhraseSpan = nounPhrase.Span;

            //loop backwards through the set so that we can remove from the end forwards
            for (int currentMention = mentions.Count - 1; currentMention > -1; currentMention--)
            {
                if (mentions[currentMention].Span.Contains(nounPhraseSpan))
                {
                    mentions.Remove(mentions[currentMention]);
                }
            }
        }
Esempio n. 2
0
    /// Input format: each two vectors represents a segment from the beginning.
    /// Considering all triangles are filled and non-triangle structure is always empty.
    /// Extract the outlines (may have holes) and return the outline.
    /// Points in each edge is arranged where their left-side is filled.
    /// Notice edges are not in order, but two points in each edge has its order.
    public static List <Vector2> ExtractEdge(this List <Vector2> src)
    {
        var adj = new Dictionary <Vector2, List <Vector2> >();

        for (int i = 0; i < src.Count; i += 2)
        {
            adj.GetOrDefault(src[i]).Add(src[i + 1]);
            adj.GetOrDefault(src[i + 1]).Add(src[i]);
        }

        // Sort the adjacent edges.
        foreach (var x in adj)
        {
            var curVert = x.Key;
            var adjList = x.Value;
            int Compare(Vector2 va, Vector2 vb)
            {
                Vector2 da = curVert.To(va);
                Vector2 db = curVert.To(vb);
                float   aa = Mathf.Atan2(da.y, da.x);
                float   ba = Mathf.Atan2(db.y, db.x);

                return(aa <ba ? -1 : aa> ba ? 1 : 0);
            }

            adjList.Sort(Compare);
        }

        // output size should not exceeded input size.
        var rest = new Util.Set <Edge>(src.Count);

        foreach (var vert in src.Distinct().ToList())
        {
            var adx = adj[vert];
            for (int i = 0; i < adx.Count; i++)
            {
                var from = adx[i];
                var to   = adx[(i + 1).ModSys(adx.Count)];

                // Exclude the edge if triangle edges are arranged clockwise.
                if (new Triangle(vert, from, to).area <= 0)
                {
                    continue;
                }

                // Edges can either appear for 1 or 2 times.
                // Because an edge can only be owned by 1 or 2 triangles.
                // Use this to extract outlines, including outlines inside.
                var edge = new Edge(from, to);

                // take up about 200ms time when src.Length == 60000.
                if (rest.Contains(edge))
                {
                    rest.Remove(edge);
                }
                else
                {
                    rest.Add(edge);
                }
            }
        }

        var res = new List <Vector2>();

        rest.Foreach((i) => { res.Add(i.a); res.Add(i.b); });
        return(res);
    }