public override void Accept(ShapeVisitor v)
 {
     if (v is SquareVisitor)
     {
         (v as SquareVisitor).Visit(this);
     }
 }
 public override void Accept(ShapeVisitor v)
 {
     if (v is CircleVisitor)
     {
         (v as CircleVisitor).Visit(this);
     }
 }
 public void Accept(ShapeVisitor a_visitor)
 {
     a_visitor.VisitComposite(this);
     foreach (Shape s in m_shapes)
     {
         s.Accept(a_visitor);
     }
 }
Пример #4
0
 public void Accept(ShapeVisitor a_visitor)
 {
     a_visitor.VisitComposite(this);
     foreach (Shape s in m_shapes)
     {
         s.Accept(a_visitor);
     }
 }
Пример #5
0
        public override OUT Accept <OUT, IN>(ShapeVisitor <OUT, IN> visitor, IN data)
        {
            results.Clear();
            Entity stub = new Entity(Vector2.Zero);
            Matrix rot  = Matrix.CreateRotationZ(this.Entity.Orientation);

            for (int i = 0; i < this.shapes.Count; i++)
            {
                stub.Position    = this.Entity.Position + Vector2.Transform(this.shapes[i].Offset, rot);
                stub.Orientation = this.Entity.Orientation;
                this.shapes[i].Shape.SetStubEntity(stub);
                OUT o = this.shapes[i].Shape.Accept(visitor, data);
                if (o is CollisionData && ((CollisionData)(object)o).IsValid)
                {
                    results.Add(((CollisionData)(object)o));
                }
            }
            if (results.Count == 0)
            {
                // TODO: Ugly codez...
                if (default(OUT) is CollisionData)
                {
                    return((OUT)(object)CollisionData.Empty);
                }
                return(default(OUT));
            }
            CollisionData largest = new CollisionData(float.MinValue);

            for (int i = 0; i < results.Count; i++)
            {
                if (results[i].Interpenetration > largest.Interpenetration)
                {
                    largest = results[i];
                }
            }
            return((OUT)(object)largest);
        }
Пример #6
0
 public override void Accept(ShapeVisitor visitor)
 {
     visitor.Visit(this);
 }
Пример #7
0
 //外界注入具体访问者
 public abstract void Accept(ShapeVisitor visitor);
Пример #8
0
 public AppStructure(ShapeVisitor visitor)
 {
     this._visitor = visitor;
 }
Пример #9
0
 public override OUT Accept <OUT, IN>(ShapeVisitor <OUT, IN> visitor, IN data)
 {
     return(visitor.Visit(this, data));
 }
Пример #10
0
 public void Accept(ShapeVisitor a_visitor)
 {
     a_visitor.VisitCircle(this);
 }
Пример #11
0
 public void Accept(ShapeVisitor a_visitor)
 {
     a_visitor.VisitCircle(this);
 }
Пример #12
0
 public abstract OUT Accept <OUT, IN>(ShapeVisitor <OUT, IN> visitor, IN data);
Пример #13
0
    // Visits all shapes that intersect "target", terminating early if the
    // "visitor" return false (in which case VisitIntersectingShapes returns
    // false as well).  Each shape is visited at most once.
    //
    // This method can also be used to visit all shapes that fully contain
    // "target" (VisitContainingShapes) by simply having the ShapeVisitor
    // function immediately return true when "contains_target" is false.
    public bool VisitIntersectingShapes(S2Cell target, ShapeVisitor visitor)
    {
        var(cellRelation, pos) = Index().LocateCell(target.Id);
        S2ShapeIndex.Enumerator iter_ = new(Index());
        iter_.SetPosition(pos);
        switch (cellRelation)
        {
        case S2ShapeIndex.CellRelation.DISJOINT:
            return(true);

        case S2ShapeIndex.CellRelation.SUBDIVIDED:
        {
            // A shape contains the target cell iff it appears in at least one cell,
            // it contains the center of all cells, and it has no edges in any cell.
            // It is easier to keep track of whether a shape does *not* contain the
            // target cell because boolean values default to false.
            Dictionary <int, bool> shape_not_contains = new();
            for (var max = target.Id.RangeMax();
                 !iter_.Done() && iter_.Id <= max; iter_.MoveNext())
            {
                var cell = iter_.Cell;
                for (int s = 0; s < cell.NumClipped(); ++s)
                {
                    var clipped = cell.Clipped(s);
                    shape_not_contains[clipped.ShapeId] |=
                        clipped.NumEdges > 0 || !clipped.ContainsCenter;
                }
            }
            foreach (var(shape_id, not_contains) in shape_not_contains)
            {
                if (!visitor(Index().Shape(shape_id), !not_contains))
                {
                    return(false);
                }
            }
            return(true);
        }

        case S2ShapeIndex.CellRelation.INDEXED:
        {
            var cell = iter_.Cell;
            for (int s = 0; s < cell.NumClipped(); ++s)
            {
                // The shape contains the target cell iff the shape contains the cell
                // center and none of its edges intersects the (padded) cell interior.
                var  clipped  = cell.Clipped(s);
                bool contains = false;
                if (iter_.Id == target.Id)
                {
                    contains = clipped.NumEdges == 0 && clipped.ContainsCenter;
                }
                else
                {
                    if (!AnyEdgeIntersects(clipped, target))
                    {
                        if (!Contains(iter_.Id, clipped, target.Center()))
                        {
                            continue;          // Disjoint.
                        }
                        contains = true;
                    }
                }
                if (!visitor(Index().Shape(clipped.ShapeId), contains))
                {
                    return(false);
                }
            }
            return(true);
        }
        }

        throw new Exception("(FATAL) Unhandled S2ShapeIndex::CellRelation");
    }
Пример #14
0
 // Finds all polygons in the given "query_index" that completely contain a
 // connected component of the target geometry.  (For example, if the
 // target consists of 10 points, this method finds polygons that contain
 // any of those 10 points.)  For each such polygon, "visitor" is called
 // with the S2Shape of the polygon along with a point of the target
 // geometry that is contained by that polygon.
 //
 // Optionally, any polygon that intersects the target geometry may also be
 // returned.  In other words, this method returns all polygons that
 // contain any connected component of the target, along with an arbitrary
 // subset of the polygons that intersect the target.
 //
 // For example, suppose that "query_index" contains two abutting polygons
 // A and B.  If the target consists of two points "a" contained by A and
 // "b" contained by B, then both A and B are returned.  But if the target
 // consists of the edge "ab", then any subset of {A, B} could be returned
 // (because both polygons intersect the target but neither one contains
 // the edge "ab").
 //
 // If "visitor" returns false, this method terminates early and returns
 // false as well.  Otherwise returns true.
 //
 // NOTE(ericv): This method exists only for the purpose of implementing
 // S2ClosestEdgeQuery::Options::include_interiors() efficiently.  Its API is
 // unlikely to be useful for other purposes.
 //
 // CAVEAT: Containing shapes may be visited more than once.
 public abstract bool VisitContainingShapes(S2ShapeIndex query_index, ShapeVisitor visitor);
Пример #15
0
 public void Accept(ShapeVisitor a_visitor)
 {
     a_visitor.VisitRectangle(this);
 }
Пример #16
0
 public void Accept(ShapeVisitor a_visitor)
 {
     a_visitor.VisitRectangle(this);
 }