コード例 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="graph"></param>
 /// <param name="settings"></param>
 public SteinerFinder(HeGraphSim graph, SteinerFinderSettings settings = null)
 {
     _graph = graph;
     _graph.Compact();
     _settings = settings ?? new SteinerFinderSettings();
     SetTerminalStatus();
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        void CollapseEdges()
        {
            var    hedges = _graph.Halfedges;
            double dmin   = _settings.MinLength;

            dmin *= dmin;

            for (int i = 0; i < hedges.Count; i += 2)
            {
                var he0 = hedges[i];
                var he1 = hedges[i + 1];

                var v0 = he0.Start;
                var v1 = he1.Start;

                if (v0 == v1)
                {
                    he0.Remove(); // remove if self loop
                }
                else if (he0.IsAtDegree2 && !v0.IsTerminal)
                {
                    _graph.CollapseEdge(he0); // collapse degree 2
                }
                else if (he1.IsAtDegree2 && !v1.IsTerminal)
                {
                    _graph.CollapseEdge(he1); // collapse degree 2
                }
                else
                {
                    var p0 = v0.Position;
                    var p1 = v1.Position;

                    // collapse short edges
                    if (p0.SquareDistanceTo(p1) < dmin)
                    {
                        if (v0.IsTerminal)
                        {
                            if (!v1.IsTerminal)
                            {
                                _graph.CollapseEdge(he1);
                            }
                        }
                        else if (v1.IsTerminal)
                        {
                            if (!v0.IsTerminal)
                            {
                                _graph.CollapseEdge(he0);
                            }
                        }
                        else
                        {
                            _graph.CollapseEdge(he0);
                        }
                    }
                }
            }

            /*
             * // cleanup any multi-edges created during collapse
             * hedges.RemoveMultiEdges();
             */

            _graph.Compact();
        }