Class CurveUtil

java.lang.Object
org.boxutil.util.CurveUtil

public final class CurveUtil extends Object
  • Method Details

    • getPointsConvexHull

      public static List<org.lwjgl.util.vector.Vector2f> getPointsConvexHull(org.lwjgl.util.vector.Vector2f... points)
    • getCurveConvexHull

      public static List<org.lwjgl.util.vector.Vector2f> getCurveConvexHull(NodeData curveStart, NodeData curveEnd)
    • isPointWithinCurveConvexHull

      public static boolean isPointWithinCurveConvexHull(org.lwjgl.util.vector.Vector2f point, List<org.lwjgl.util.vector.Vector2f> hull)
    • getCurveAABB

      public static org.lwjgl.util.vector.Vector2f[] getCurveAABB(NodeData curveStart, NodeData curveEnd)
      Returns:
      Vector2f[] = {BL, TR}
    • getCurveLength

      public static float getCurveLength(NodeData curveStart, NodeData curveEnd, int step)
    • aligningNodeSegmentBased

      public static com.fs.starfarer.api.util.Pair<NodeData[],float[]> aligningNodeSegmentBased(NodeData curveStart, NodeData curveEnd, org.lwjgl.util.vector.Vector2f segmentStart, org.lwjgl.util.vector.Vector2f segmentEnd, @Nullable com.fs.starfarer.api.util.Pair<NodeData[],float[]> result)
      Returns:
      float[] = {cos, sin, offsetX, offsetY, segmentLength}
    • aligningNode

      public static com.fs.starfarer.api.util.Pair<NodeData[],float[]> aligningNode(NodeData curveStart, NodeData curveEnd, @Nullable com.fs.starfarer.api.util.Pair<NodeData[],float[]> result)
      Returns:
      float[] = {cos, sin, offsetX, offsetY, segmentLength}
    • aligningNodeSegmentBased

      public static com.fs.starfarer.api.util.Pair<NodeData[],float[]> aligningNodeSegmentBased(NodeData curveStart, NodeData curveEnd, com.fs.starfarer.api.combat.BoundsAPI.SegmentAPI segment, @Nullable com.fs.starfarer.api.util.Pair<NodeData[],float[]> result)
      Returns:
      float[] = {cos, sin, offsetX, offsetY, segmentLength}
    • getCurveCircleFitting

      public static com.fs.starfarer.api.util.Pair<NodeData,float[]> getCurveCircleFitting(float angle, float radius, @Nullable com.fs.starfarer.api.util.Pair<NodeData,float[]> result)
      Parameters:
      angle - angle value recommend to [0, 180] for rough, [0, 90] for more accurate fitting.
      Returns:
      NodeData is the end point of curve, use left tangent; float[] = {cos, sin, tangentLength};

      For the start point of curve: location = {radius, 0.0f}, tangentRight = {0.0f, tangentLength}.

    • getProjectivePointOnCurve

      public static org.lwjgl.util.vector.Vector4f getProjectivePointOnCurve(NodeData curveStart, NodeData curveEnd, org.lwjgl.util.vector.Vector2f point, int stepFirstSearch, int stepPerSearch, float thresholdSquared)
      Parameters:
      stepFirstSearch - minimum step is 3, first searched points is stepPerSearch + 1.
      stepPerSearch - minimum step is 3, each round searched points is stepPerSearch + 1.
      thresholdSquared - search accuracy, lower is accurate but slower.
      Returns:
      {loc.xy, t, distanceSquared}
    • getIntersectionCurveSegment

      public static List<org.lwjgl.util.vector.Vector3f> getIntersectionCurveSegment(NodeData curveStart, NodeData curveEnd, org.lwjgl.util.vector.Vector2f segmentStart, org.lwjgl.util.vector.Vector2f segmentEnd)
      Returns:
      {loc.xy, t}, empty list when no intersection.
    • getIntersectionCurveSegment

      public static List<org.lwjgl.util.vector.Vector3f> getIntersectionCurveSegment(NodeData curveStart, NodeData curveEnd, com.fs.starfarer.api.combat.BoundsAPI.SegmentAPI segment)
      Returns:
      {loc.xy, t}, empty list when no intersection.
    • getNearestIntersectionCurveSegment

      @Nullable public static org.lwjgl.util.vector.Vector3f getNearestIntersectionCurveSegment(NodeData curveStart, NodeData curveEnd, org.lwjgl.util.vector.Vector2f segmentStart, org.lwjgl.util.vector.Vector2f segmentEnd)
      Returns:
      {loc.xy, t}, null when no intersection.
    • getNearestIntersectionCurveSegment

      @Nullable public static org.lwjgl.util.vector.Vector3f getNearestIntersectionCurveSegment(NodeData curveStart, NodeData curveEnd, com.fs.starfarer.api.combat.BoundsAPI.SegmentAPI segment)
      Returns:
      {loc.xy, t}, null when no intersection.
    • getIntersectionCurveCurve

      public static List<org.lwjgl.util.vector.Vector3f> getIntersectionCurveCurve(NodeData curveStartSRC, NodeData curveEndSRC, NodeData curveStartDST, NodeData curveEndDST, float similarityThresholdSquared, float searchThresholdSquared, float mergeThresholdSquared, float splitFactorEachRound)
      Parameters:
      similarityThresholdSquared - check two curves is similar then return p0 of start curve.
      searchThresholdSquared - search accuracy, lower is accurate but slower.
      mergeThresholdSquared - merge curve intersection points with distance less than this threshold.
      splitFactorEachRound - range must be (0.0, 1.0).
      Returns:
      {loc.xy, t}, t is average value from two curves, empty list when no intersection.
    • getNearestIntersectionCurveCurve

      @Nullable public static org.lwjgl.util.vector.Vector3f getNearestIntersectionCurveCurve(NodeData curveStartSRC, NodeData curveEndSRC, NodeData curveStartDST, NodeData curveEndDST, float similarityThresholdSquared, float searchThresholdSquared, float mergeThresholdSquared, float splitFactorEachRound)
      Parameters:
      similarityThresholdSquared - check two curves is similar then return p0 of start curve.
      searchThresholdSquared - search accuracy, lower is accurate but slower.
      mergeThresholdSquared - merge curve intersection points with distance less than this threshold.
      Returns:
      {loc.xy, t}, t is average value from two curves, null when no intersection.
    • getPointOnCurve

      public static org.lwjgl.util.vector.Vector2f getPointOnCurve(NodeData left, NodeData right, float factor)
    • getCurveDerivative

      public static org.lwjgl.util.vector.Vector2f getCurveDerivative(NodeData left, NodeData right, float factor)
    • curveSplit

      public static NodeData[] curveSplit(NodeData left, NodeData right, float factor)
      Pick a node between two nodeList.
      Returns:
      {start, mid, end}
    • curveSplitControlPointOnly

      public static NodeData[] curveSplitControlPointOnly(NodeData left, NodeData right, float factor)
      Parameters:
      left - for result, color/emissive color/width/mix factor all use it.
      Returns:
      {start, mid, end}
    • spawnDirectBeam

      public static com.fs.starfarer.api.util.Pair<org.lwjgl.util.vector.Vector3f,org.lwjgl.util.vector.Matrix2f> spawnDirectBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, org.lwjgl.util.vector.Vector2f start, org.lwjgl.util.vector.Vector2f end, float maxCheckRangeOffset, CurveUtil.DealtController dealtController)
      Returns:
      Vector3f returns absolute location the end of beam and distance squared, returns null when no intersection;

      Matrix2f is the rotation matrix of beam.

    • spawnDirectBeam

      public static com.fs.starfarer.api.util.Pair<TrailEntity,org.lwjgl.util.vector.Vector3f> spawnDirectBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, org.lwjgl.util.vector.Vector2f start, org.lwjgl.util.vector.Vector2f end, com.fs.starfarer.api.combat.CombatEntityAPI source, float damageAmount, com.fs.starfarer.api.combat.DamageType damageType, float empDamageAmount, boolean dealsSoftFlux, com.fs.starfarer.api.graphics.SpriteAPI core, Color coreColor, com.fs.starfarer.api.graphics.SpriteAPI fringe, Color fringeColor, float width, float textureSpeed, float fadeIn, float full, float fadeOut, com.fs.starfarer.api.combat.CombatEngineLayers layer)
      Returns:
      TrailEntity has been submitted and added to rendering manager;

      Vector3f is the end location and distance squared of beam, returns null when no damaging.

    • spawnCurveBeam

      public static com.fs.starfarer.api.util.Pair<NodeData[],org.lwjgl.util.vector.Vector3f> spawnCurveBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, @Nullable org.lwjgl.util.vector.Vector3f startOffset, NodeData start, NodeData end, float maxCheckRange, CurveUtil.DealtController dealtController, int stepFirstSearch, int stepPerSearch, float thresholdSquared, float similarityThresholdSquared, float searchThresholdSquared, float mergeThresholdSquared, float splitFactorEachRound, @Nullable NodeData resultEndNode, boolean returnsAlignedNode, @Nullable org.lwjgl.util.vector.Matrix3f transformResult)
      Parameters:
      startOffset - {loc.xy, angle}.

      if set to null: all calculating will be based node data;

      if set to not null: curve must be aligned to (0, 0) to positive x-axis, angle value must be [0, 360].

      stepFirstSearch - for entity that without shield or bounds. Minimum step is 2, first searched points is stepPerSearch + 1.
      stepPerSearch - for entity that without shield or bounds. Minimum step is 2, each round searched points is stepPerSearch + 1.
      thresholdSquared - for entity that without shield or bounds. Search accuracy, lower is accurate but slower.
      similarityThresholdSquared - for shield of ship. Check two curves is similar then return p0 of start curve.
      searchThresholdSquared - for shield of ship. Search accuracy, lower is accurate but slower.
      mergeThresholdSquared - for shield of ship. Merge curve intersection points with distance less than this threshold.
      resultEndNode - for set the end node.
      transformResult - for turn the result aligned nodes to absolute coordinate.
      Returns:
      NodeData[] = {start, end};

      Vector3f is the end location and t of curve, returns null when no damaging.

    • spawnCurveBeam

      public static com.fs.starfarer.api.util.Pair<NodeData[],org.lwjgl.util.vector.Vector3f> spawnCurveBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, @Nullable org.lwjgl.util.vector.Vector3f startOffset, NodeData start, NodeData end, float maxCheckRange, CurveUtil.DealtController dealtController, @Nullable NodeData resultEndNode, boolean returnsAlignedNode, @Nullable org.lwjgl.util.vector.Matrix3f transformResult)
      Parameters:
      resultEndNode - for set the end node.
      transformResult - for turn the result aligned nodes to absolute coordinate.
      Returns:
      NodeData[] = {start, end};

      Vector3f is the end location and t of curve, returns null when no damaging.

    • spawnCurveBeam

      public static com.fs.starfarer.api.util.Pair<SegmentEntity,org.lwjgl.util.vector.Vector3f> spawnCurveBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, @Nullable org.lwjgl.util.vector.Vector3f startOffset, NodeData start, NodeData end, float maxCheckRange, CurveUtil.DealtController dealtController, int stepFirstSearch, int stepPerSearch, float thresholdSquared, float similarityThresholdSquared, float searchThresholdSquared, float mergeThresholdSquared, float splitFactorEachRound)
      Parameters:
      startOffset - {loc.xy, angle}.

      if set to null: all calculating will be based node data;

      if set to not null: curve must be aligned to (0, 0) to positive x-axis, angle value must be [0, 360].

      stepFirstSearch - for entity that without shield or bounds. Minimum step is 2, first searched points is stepPerSearch + 1.
      stepPerSearch - for entity that without shield or bounds. Minimum step is 2, each round searched points is stepPerSearch + 1.
      thresholdSquared - for entity that without shield or bounds. Search accuracy, lower is accurate but slower.
      similarityThresholdSquared - for shield of ship. Check two curves is similar then return p0 of start curve.
      searchThresholdSquared - for shield of ship. Search accuracy, lower is accurate but slower.
      mergeThresholdSquared - for shield of ship. Merge curve intersection points with distance less than this threshold.
      Returns:
      SegmentEntity is without submit or add to rendering manager;

      Vector3f is the end location and t of curve, returns null when no damaging.

    • spawnCurveBeam

      public static com.fs.starfarer.api.util.Pair<SegmentEntity,org.lwjgl.util.vector.Vector3f> spawnCurveBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, @Nullable org.lwjgl.util.vector.Vector3f startOffset, NodeData start, NodeData end, float maxCheckRange, CurveUtil.DealtController dealtController)
      Parameters:
      startOffset - {loc.xy, angle}.

      if set to null: all calculating will be based node data;

      if set to not null: curve must be aligned to (0, 0) to positive x-axis, angle value must be [0, 360].

      Returns:
      SegmentEntity is without submit or add to rendering manager; Vector3f is the end location and t of curve, returns null when no damaging.
    • spawnCurveBeam

      public static com.fs.starfarer.api.util.Pair<SegmentEntity,org.lwjgl.util.vector.Vector3f> spawnCurveBeam(com.fs.starfarer.api.combat.CombatEngineAPI engine, @Nullable org.lwjgl.util.vector.Vector3f startOffset, NodeData start, NodeData end, com.fs.starfarer.api.combat.CombatEntityAPI source, float damageAmount, com.fs.starfarer.api.combat.DamageType damageType, float empDamageAmount, boolean dealsSoftFlux, com.fs.starfarer.api.graphics.SpriteAPI core, Color coreColor, com.fs.starfarer.api.graphics.SpriteAPI fringe, Color fringeColor, float width, float textureSpeed, float fadeIn, float full, float fadeOut, com.fs.starfarer.api.combat.CombatEngineLayers layer)
      Parameters:
      startOffset - {loc.xy, angle}.

      if set to null: all calculating will be based node data;

      if set to not null: curve must be aligned to (0, 0) to positive x-axis, angle value must be [0, 360].

      Returns:
      SegmentEntity has been submitted and added to rendering manager; Vector3f is the end location and t of curve, returns null when no damaging.