/** If a trajectory has only one node, the player is not displayed. To fix that situation, the node is duplicated with a slightly different location. * Both old and new nodes are linked through a side. * * @param scene */ public static void fixSingleNode(Scene scene) { Trajectory trajectory = scene.getTrajectory(); if (trajectory != null) { if (trajectory.getNodes().Count == 1) { Trajectory.Node node1 = trajectory.getNodes()[0]; trajectory.addNode(node1.getID() + "Dupl", node1.getX() + 1, node1.getY(), node1.getScale()); trajectory.addSide(node1.getID(), node1.getID() + "Dupl", 1); } } }
/** * Ensures that all nodes in a trajectory have a different location. If two nodes are found in the same position, first's x coordinate * is incremented by 1 px. This is important as nodes with equal position makes the trajectory algorithm to crash. * @param scene */ private static void fixNodesWithSameLocation(Scene scene) { Trajectory trajectory = scene.getTrajectory(); if (trajectory != null) { // Iterate through nodes. for (int i = 0; i < trajectory.getNodes().Count; i++) { Trajectory.Node node1 = trajectory.getNodes()[i]; for (int j = 0; j < trajectory.getNodes().Count; j++) { Trajectory.Node node2 = trajectory.getNodes()[j]; if (i != j && node1.getX() == node2.getX() && node1.getY() == node2.getY()) { node1.setValues(node1.getX() + 1, node1.getY(), node1.getScale()); j = 0; } } } } }
/** * Checks pairs of nodes with duplicate ids. One of the nodes is removed. * @param nodes */ private static void fixDuplicateNodes(Scene scene) { Trajectory trajectory = scene.getTrajectory(); if (trajectory != null) { // Iterate through nodes. for (int i = 0; i < trajectory.getNodes().Count; i++) { Trajectory.Node node1 = trajectory.getNodes()[i]; for (int j = 0; j < trajectory.getNodes().Count; j++) { Trajectory.Node node2 = trajectory.getNodes()[j]; if (i != j && node1.getID().Equals(node2.getID())) { trajectory.getNodes().RemoveAt(j); i--; j--; } } } } }