# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @name unique_vector
#' @noRd
#'
NULL

#' @name set_diff
#' @noRd
#'
NULL

#' @name c_basis2
#' @title CB construction
#' @description The SVD-based constraint basis construction for non-overlapping
#' subsets of constraints. Algorithm 1 from the reference.
#' Creating a basis from the matrix A
#' @param A `nxk matrix` must have rank k
#' @param eps_limit `double` used as a limit of small value
#' @return T (n x n) the basis matrix
#' @noRd
#'
c_basis2_old <- function(A, eps_limit = 1e-10) {
    .Call(`_MetricGraph_c_basis2_old`, A, eps_limit)
}

construct_constraint_matrix_old <- function(E, nV, edge_constraint) {
    .Call(`_MetricGraph_construct_constraint_matrix_old`, E, nV, edge_constraint)
}

construct_directional_constraint_matrix_old <- function(E, nV, nE, alpha, V_indegree, V_outdegree) {
    .Call(`_MetricGraph_construct_directional_constraint_matrix_old`, E, nV, nE, alpha, V_indegree, V_outdegree)
}

construct_constraint_matrix <- function(E, nV, edge_constraint) {
    .Call(`_MetricGraph_construct_constraint_matrix`, E, nV, edge_constraint)
}

c_basis2_graph <- function(E, nV, edge_constraint) {
    .Call(`_MetricGraph_c_basis2_graph`, E, nV, edge_constraint)
}

construct_directional_constraint_matrix_fast <- function(E, nV, nE, alpha, V_indegree, V_outdegree, w_out, w_in) {
    .Call(`_MetricGraph_construct_directional_constraint_matrix_fast`, E, nV, nE, alpha, V_indegree, V_outdegree, w_out, w_in)
}

c_basis2_directional_graph <- function(E, nV, nE, alpha, V_indegree, V_outdegree) {
    .Call(`_MetricGraph_c_basis2_directional_graph`, E, nV, nE, alpha, V_indegree, V_outdegree)
}

c_basis2 <- function(A, eps_limit = 1e-10) {
    .Call(`_MetricGraph_c_basis2`, A, eps_limit)
}

#' @name proj_vec
#' @noRd
NULL

#' @name proj_vec2
#' @noRd
NULL

#' @name proj_vec
#' @noRd
NULL

#' @name proj_vec_line
#' @noRd
NULL

#' @name assemble_fem
#' @title Construction of FEM matrices
#' @description Function used to construct FEM matrices on metric graphs.
#' @param E `nx2 matrix` Matrix of edges
#' @param h_e `n vector` Vector of h's
#' @param nV `int` Number of vertices
#' @noRd
#'
assemble_fem <- function(E, h_e, nV, petrov) {
    .Call(`_MetricGraph_assemble_fem`, E, h_e, nV, petrov)
}

#' @name compute_mesh_weights
#' @title Compute the weights of the mesh nodes
#' @description Function used to compute the weights of the mesh nodes on metric graphs.
#' @param E `nx2 matrix` Matrix of edges
#' @param h_e `n vector` Vector of h's
#' @param nV `int` Number of vertices.
#' @noRd
#'
compute_mesh_weights <- function(E, h_e, nV) {
    .Call(`_MetricGraph_compute_mesh_weights`, E, h_e, nV)
}

#' @name projectVecLine
#' @title Projects SpatialPoints into SpatialLines
#' @description Obtain the coordinates of the projection of points into lines.
#' @param lines `nx2 matrix` Matrix of the points of the lines
#' @param points `nx2 matrix` Matrix of the points
#' @param normalized `int` 0 means not normalized, 1 means normalized
#' @noRd
#'
projectVecLine <- function(lines, points, normalized = 0L) {
    .Call(`_MetricGraph_projectVecLine`, lines, points, normalized)
}

#' @name interpolate2
#' @title Finds the point with respect to a distance along the line
#' @description Finds the point with respect to a distance along the line
#' @param lines `nx2 matrix` Matrix of the points of the lines
#' @param pos `k vector` vector of positions.
#' @param normalized `int` 0 means not normalized, 1 means normalized
#' @noRd
#'
interpolate2_aux <- function(lines, pos, normalized = 0L) {
    .Call(`_MetricGraph_interpolate2_aux`, lines, pos, normalized)
}

#' @name compute_length
#' @title Compute length
#' @description Computes the length of a piecewise-linear function whose coordinates are given in a matrix.
#' The function expects coordinates with at least 2 columns (x, y). If more columns are provided,
#' only the first two columns (x, y) are used for the calculation.
#' @param coords nxk matrix Matrix of the points of the lines (k >= 2, typically nx2)
#' @noRd
#'
compute_length <- function(coords) {
    .Call(`_MetricGraph_compute_length`, coords)
}

generate_mesh <- function(n_edges, edge_lengths, n_e, E, ind, continuous) {
    .Call(`_MetricGraph_generate_mesh`, n_edges, edge_lengths, n_e, E, ind, continuous)
}

#' @name PtE_to_mesh_cpp
#' @title Convert PtE for mesh given PtE for graph
#' @description C++ implementation of PtE_to_mesh function
#' @param PtE `nx2 matrix` Matrix with edge indices and positions
#' @param VtE `nx2 matrix` Matrix from VtEfirst()
#' @param mesh_PtE `nx2 matrix` Mesh PtE matrix
#' @param E `nx2 matrix` Graph edge matrix
#' @param mesh_E `nx2 matrix` Mesh edge matrix
#' @param edge_lengths `n vector` Vector of edge lengths
#' @param mesh_h_e `n vector` Vector of mesh edge lengths
#' @param nV `int` Number of vertices
#' @noRd
#'
PtE_to_mesh_cpp <- function(PtE, VtE, mesh_PtE, E, mesh_E, edge_lengths, mesh_h_e, nV) {
    .Call(`_MetricGraph_PtE_to_mesh_cpp`, PtE, VtE, mesh_PtE, E, mesh_E, edge_lengths, mesh_h_e, nV)
}

#' @name compute_PtE_edges_cpp
#' @title Per-edge cumulative relative positions
#' @description Given a list of edges (each a 2-column numeric matrix of
#' vertex coordinates), compute, for every edge, the cumulative arc-length
#' normalized to lie in \[0, 1\]. Returns a list of numeric vectors, one per
#' edge, each starting at 0 and ending at 1.
#'
#' Degenerate (zero-length) edges return a vector of NaN values.
#'
#' @param edges List of two-column numeric matrices.
#' @param longlat Logical. If TRUE, use haversine on (lon, lat) in degrees;
#' otherwise use planar Euclidean distances.
#' @return A list of numeric vectors, the same length as \code{edges}.
#' @noRd
compute_PtE_edges_cpp <- function(edges, longlat) {
    .Call(`_MetricGraph_compute_PtE_edges_cpp`, edges, longlat)
}

#' @name compute_edge_lengths_cpp
#' @title Per-edge total polyline lengths
#' @description Given a list of edges (each a 2-column numeric matrix of
#' vertex coordinates), compute the total polyline length of each edge.
#' Returns a numeric vector of length \code{length(edges)}.
#'
#' @param edges List of two-column numeric matrices.
#' @param longlat Logical. If TRUE, treat columns as (lon, lat) in degrees
#' and return lengths in metres (haversine on a sphere of radius
#' 6371008.8 m). If FALSE, return planar Euclidean lengths in whatever
#' coordinate units the edges happen to be in.
#' @return A numeric vector of edge lengths.
#' @noRd
compute_edge_lengths_cpp <- function(edges, longlat) {
    .Call(`_MetricGraph_compute_edge_lengths_cpp`, edges, longlat)
}

#' @name postprocess_edges_cpp
#' @title Dedupe interior polyline points while preserving endpoints
#' @description Bit-faithful translation of the post-merge "clean edges"
#' \code{lapply} that the metric_graph constructor runs after the
#' vertex-merge step. For each edge, deduplicates rows by exact
#' \code{(x, y)} equality, while forcing the original first row to remain
#' at position 1 and the original last row to be appended at the end.
#'
#' @param edges List of two-column numeric matrices.
#' @return A list of two-column numeric matrices with deduped interior
#' rows. May have fewer rows than the input.
#' @noRd
postprocess_edges_cpp <- function(edges) {
    .Call(`_MetricGraph_postprocess_edges_cpp`, edges)
}

#' @name aeqd_project_cpp
#' @title Closed-form spherical Azimuthal Equidistant projection
#' @description Forward projects (lon, lat) coordinates to local AEQD-style
#' planar coordinates centered on a given (lon0, lat0). Output is in metres
#' on a sphere of radius 6371008.8 m (WGS84 mean Earth radius).
#'
#' Forward formula:
#' \preformatted{
#'   c = acos(sin(lat0)*sin(lat) + cos(lat0)*cos(lat)*cos(lon - lon0))
#'   k = c / sin(c)             (-> 1 as c -> 0)
#'   x = R * k * cos(lat) * sin(lon - lon0)
#'   y = R * k * (cos(lat0)*sin(lat) - sin(lat0)*cos(lat)*cos(lon - lon0))
#' }
#'
#' @param pts Two-column numeric matrix of (lon, lat) coordinates in degrees.
#' @param lon0 Longitude of the projection center, in degrees.
#' @param lat0 Latitude of the projection center, in degrees.
#' @return A two-column numeric matrix of planar (x, y) coordinates in metres.
#' @noRd
aeqd_project_cpp <- function(pts, lon0, lat0) {
    .Call(`_MetricGraph_aeqd_project_cpp`, pts, lon0, lat0)
}

#' @name split_one_edge_cpp
#' @title Inner edge-splitting work for split_edge_batch (one edge)
#' @description Processes a single edge: builds coords_list1 (the first
#' segment of the original edge ending at the first split point), coords_list2
#' (a List of subsequent segments between split points and from the last
#' split to the end of the edge), segment_lengths (a NumericVector of length
#' n_split + 1), and the aux_matrix (an IntegerMatrix of (n_split + 1) x 2
#' giving the new E rows). Each segment carries a PtE attribute renormalized
#' to \[0, 1\].
#' @param edge nx2 matrix: the polyline
#' @param PtE_edge n vector: PtE values at each polyline point
#' @param t_values n_split vector: sorted positions in \[0, 1\] where to split
#' @param edge_len double: original edge length
#' @param E_row IntegerVector(2): current E\[Ei,\] = (start_v, end_v)
#' @param first_new_v int: ID of the first new vertex for this edge
#' @noRd
split_one_edge_cpp <- function(edge, PtE_edge, t_values, edge_len, E_row, first_new_v) {
    .Call(`_MetricGraph_split_one_edge_cpp`, edge, PtE_edge, t_values, edge_len, E_row, first_new_v)
}

#' @name split_edges_batch_cpp
#' @title Batched inner edge-splitting work for split_edge_batch
#' @description Processes all edge groups in one call. Returns a List of
#' per-group results, each matching split_one_edge_cpp's output structure.
#' @param edges_full List: full self$edges, looked up by Ei (1-indexed)
#' @param PtE_full List: precomputed PtE attributes for each edge in edges_full
#' (caller extracts these once to avoid attr() lookups inside C++)
#' @param E_full IntegerMatrix: full self$E
#' @param edge_lens NumericVector: full self$edge_lengths
#' @param edge_ids IntegerVector: which edge each group refers to (1-indexed)
#' @param t_values_list List: per-group t_values
#' @param first_new_vs IntegerVector: ID of the first new vertex for each group
#' @noRd
split_edges_batch_cpp <- function(edges_full, PtE_full, E_full, edge_lens, edge_ids, t_values_list, first_new_vs) {
    .Call(`_MetricGraph_split_edges_batch_cpp`, edges_full, PtE_full, E_full, edge_lens, edge_ids, t_values_list, first_new_vs)
}

selected_inv_cpp <- function(Q) {
    .Call(`_MetricGraph_selected_inv_cpp`, Q)
}

