001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math.jni;
006
007import java.io.IOException;
008
009/** TrajectoryUtil JNI. */
010public final class TrajectoryUtilJNI extends WPIMathJNI {
011  /**
012   * Loads a Pathweaver JSON.
013   *
014   * @param path The path to the JSON.
015   * @return A double array with the trajectory states from the JSON.
016   * @throws IOException if the JSON could not be read.
017   */
018  public static native double[] fromPathweaverJson(String path) throws IOException;
019
020  /**
021   * Converts a trajectory into a Pathweaver JSON and saves it.
022   *
023   * @param elements The elements of the trajectory.
024   * @param path The location to save the JSON to.
025   * @throws IOException if the JSON could not be written.
026   */
027  public static native void toPathweaverJson(double[] elements, String path) throws IOException;
028
029  /**
030   * Deserializes a trajectory JSON into a double[] of trajectory elements.
031   *
032   * @param json The JSON containing the serialized trajectory.
033   * @return A double array with the trajectory states.
034   */
035  public static native double[] deserializeTrajectory(String json);
036
037  /**
038   * Serializes the trajectory into a JSON string.
039   *
040   * @param elements The elements of the trajectory.
041   * @return A JSON containing the serialized trajectory.
042   */
043  public static native String serializeTrajectory(double[] elements);
044
045  /** Utility class. */
046  private TrajectoryUtilJNI() {}
047}