Пример #1
0
        public static void DivideSideByRect(Rectangle rect, Trajectory original, Trajectory.Side side, Trajectory outputTrajectory)
        {
            var startNode = original.getNodeForId(side.getIDStart());
            var endNode   = original.getNodeForId(side.getIDEnd());

            Math3DFunc scaleFunc = new Math3DFunc(
                new Vector3(startNode.getX(), startNode.getY(), startNode.getScale()),
                new Vector3(endNode.getX(), endNode.getY(), endNode.getScale()));
            Math3DFunc lengthFunc = new Math3DFunc(
                new Vector3(startNode.getX(), startNode.getY(), 0),
                new Vector3(endNode.getX(), endNode.getY(), side.getLength()));

            var startInside = outputTrajectory.getNodeForId(side.getIDStart()) == null;
            var endInside   = outputTrajectory.getNodeForId(side.getIDEnd()) == null;

            if (startInside && endInside)
            {
                return;
            }

            Vector2 start = LineHandler.nodeToVector2(startNode),
                    end   = LineHandler.nodeToVector2(endNode);

            Vector2[] intersections;
            if (LineRectangleIntersections(rect, start, end, out intersections))
            {
                if (!startInside)
                {
                    var cs   = ClosestPoint(start, intersections);
                    var csId = createRandomNodeId(cs.x, cs.y);
                    outputTrajectory.addNode(csId, (int)cs.x, (int)cs.y, scaleFunc.getZ(cs.x, cs.y));
                    outputTrajectory.addSide(side.getIDStart(), csId, (int)lengthFunc.getZ(cs.x, cs.y));
                }
                if (!endInside)
                {
                    var ce   = ClosestPoint(end, intersections);
                    var ceId = createRandomNodeId(ce.x, ce.y);
                    outputTrajectory.addNode(ceId, (int)ce.x, (int)ce.y, scaleFunc.getZ(ce.x, ce.y));
                    outputTrajectory.addSide(side.getIDEnd(), ceId, (int)(side.getLength() - lengthFunc.getZ(ce.x, ce.y)));
                }
            }
            else
            {
                outputTrajectory.addSide(side.getIDStart(), side.getIDEnd(), (int)side.getLength());
            }
        }
Пример #2
0
 public NodeDataControl getStart()
 {
     foreach (NodeDataControl ndc in trajectoryDataControl.getNodes())
     {
         if (ndc.getID().Equals(side.getIDStart()))
         {
             return(ndc);
         }
     }
     return(null);
 }