Exemple #1
0
 public Visitor(IGraph <Node, Edge> graph, Predicate <Node> nodeStartVisitor, Action <Node> nodeFinishVisitor, EdgeVisitor <Node, Edge> edgeVisitor)
 {
     this.graph = graph;
     this.node_start_visitor  = nodeStartVisitor;
     this.node_finish_visitor = nodeFinishVisitor;
     this.edge_visitor        = edgeVisitor;
 }
Exemple #2
0
 public static void Visit <Node, EdgeInfo> (IGraph <Node, EdgeInfo> graph,
                                            Node startNode,
                                            Predicate <Node> nodeStartVisitor,
                                            EdgeVisitor <Node, EdgeInfo> edgeVisitor)
 {
     new Visitor <Node, EdgeInfo> (graph, nodeStartVisitor, edgeVisitor).VisitSubGraphNonRecursive(startNode);
 }
Exemple #3
0
    private void Start()
    {
        DMSphere   sphere1   = new DMSphere();
        DMCylinder cylinder1 = new DMCylinder();
        DMCube     cube1     = new DMCube();
        DMCube     cub2      = new DMCube();

        DMShapeContainer container = new DMShapeContainer();

        container.AddShape(sphere1);
        container.AddShape(cylinder1);
        container.AddShape(cube1);
        container.AddShape(cub2);

        //int count = container.GetShapeCount();  //需求扩展,不符合开闭原则
        //int cubeCount=container.GetCubeCount() //需求扩展,不符合开闭原则

        //符合开闭原则
        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        print("图形数量:" + amountVisitor.amount);

        CubeAmountVisitor cubeAmount = new CubeAmountVisitor();

        container.RunVisitor(cubeAmount);
        print("cube数量:" + cubeAmount.amount);

        EdgeVisitor edgeVisitor = new EdgeVisitor();

        container.RunVisitor(edgeVisitor);
        print("edge数量:" + edgeVisitor.count);
    }
Exemple #4
0
    public List <Intersection> Intersect(IEdge target, IEdge tool)
    {
        EdgeVisitor ic = new EdgeVisitor(this);

        target.OnVisit(ic);
        tool.OnVisit(ic);

        return(ic.Res);
    }
        public static void Visit <Node, EdgeInfo>
        (
            IGraph <Node, EdgeInfo> /*!*/ graph,
            Node startNode,
            Predicate <Node> nodeStartVisitor,
            EdgeVisitor <Node, EdgeInfo> edgeVisitor
        )
        {
            Contract.Requires(graph != null);// Clousot Suggestion
            Visitor <Node, EdgeInfo> dfs = new Visitor <Node, EdgeInfo>(graph, nodeStartVisitor, null, edgeVisitor);

            dfs.VisitSubGraphNonRecursive(startNode);
        }
            public Visitor(IGraph <Node, Edge> /*!*/ graph,
                           //^ [Delayed]
                           Predicate <Node> /*?*/ nodeStartVisitor,
                           //^ [Delayed]
                           Action <Node> /*?*/ nodeFinishVisitor,
                           //^ [Delayed]
                           EdgeVisitor <Node, Edge> /*?*/ edgeVisitor)
            {
                Contract.Requires(graph != null);// Clousot Suggestion

                this.graph             = graph;
                this.nodeStartVisitor  = nodeStartVisitor;
                this.nodeFinishVisitor = nodeFinishVisitor;
                this.edgeVisitor       = edgeVisitor;
            }
Exemple #7
0
    void Start()
    {
        DMShpere   shpere1   = new DMShpere();
        DMCylinder cylinder1 = new DMCylinder();
        DMCube     cube1     = new DMCube();
        DMCube     cube2     = new DMCube();

        DMShapeContainer container = new DMShapeContainer();

        container.AddShape(shpere1);
        container.AddShape(cylinder1);
        container.AddShape(cube1);
        container.AddShape(cube2);

        //int count = container.GetShapeCount();
        //int cubeCount = container.GetCubeCount();
        AmountVisitor amountVisitor = new AmountVisitor();

        container.RunVisitor(amountVisitor);
        int amount = amountVisitor.amount;

        Debug.Log("图形总数:" + amount);

        CubeAmountVisitor cubeAmountVisitor = new CubeAmountVisitor();

        container.RunVisitor(cubeAmountVisitor);
        int cubeAmount = cubeAmountVisitor.amount;

        Debug.Log("Cube总数:" + cubeAmount);


        EdgeVisitor edgeVisitor = new EdgeVisitor();

        container.RunVisitor(edgeVisitor);
        int edgeAmount = edgeVisitor.amount;

        Debug.Log("边总数:" + edgeAmount);
    }
Exemple #8
0
 public Visitor(IGraph <Node, Edge> graph, Predicate <Node> nodeStartVisitor, EdgeVisitor <Node, Edge> edgeVisitor)
     : this(graph, nodeStartVisitor, null, edgeVisitor)
 {
 }
Exemple #9
0
 public static void Visit <Node, EdgeInfo> (IGraph <Node, EdgeInfo> graph,
                                            Predicate <Node> nodeStartVisitor,
                                            EdgeVisitor <Node, EdgeInfo> edgeVisitor)
 {
     new Visitor <Node, EdgeInfo> (graph, nodeStartVisitor, edgeVisitor).VisitAll();
 }