Nothing
# 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 snap_points_to_edges_cpp
#' @title Snap candidate points to their nearest position on given edges
#' @description Given a list of edges and, for each edge, a set of candidate
#' point indices, computes the closest point on the edge (following the same
#' algorithm as the R helpers `nearestPointOnLine`/`nearestPointOnSegment`),
#' discards the candidates whose distance exceeds `tolerance`, and returns the
#' relative position along the edge of the retained snapped points, computed
#' with `proj_vec_line` (i.e. the same quantity as `projectVecLine`).
#' @param edges List of two-column numeric matrices.
#' @param XY `nx2 matrix` Coordinates of the candidate points.
#' @param edge_id `k vector` 1-based edge indices, one per group.
#' @param group_start `k vector` 0-based start offset of each group in `pt_idx`.
#' @param group_end `k vector` 0-based end offset (exclusive) of each group.
#' @param pt_idx `m vector` 1-based row indices into `XY`, grouped by edge.
#' @param tolerance `double` Maximum snapping distance.
#' @noRd
#'
snap_points_to_edges_cpp <- function(edges, XY, edge_id, group_start, group_end, pt_idx, tolerance) {
.Call(`_MetricGraph_snap_points_to_edges_cpp`, edges, XY, edge_id, group_start, group_end, pt_idx, tolerance)
}
#' @noRd
cv_loo_selinv_cpp <- function(precomputed_data, edge_endpoints, Q_list, sigma_e, reciprocal_tau, kappa) {
.Call(`_MetricGraph_cv_loo_selinv_cpp`, precomputed_data, edge_endpoints, Q_list, sigma_e, reciprocal_tau, kappa)
}
directional_edge_precision_triplets_cpp <- function(edge_lengths, stationary_edges, tau, kappa, w) {
.Call(`_MetricGraph_directional_edge_precision_triplets_cpp`, edge_lengths, stationary_edges, tau, kappa, w)
}
directional_ou_setup_numeric_cpp <- function(skeleton, kappa, tau, source_var_by_vertex) {
.Call(`_MetricGraph_directional_ou_setup_numeric_cpp`, skeleton, kappa, tau, source_var_by_vertex)
}
directional_ou_out_tree_lca_index_cpp <- function(parent_edge, depth) {
.Call(`_MetricGraph_directional_ou_out_tree_lca_index_cpp`, parent_edge, depth)
}
directional_ou_covariance_oriented_tree_cpp <- function(E, edge_lengths, tree_orientation, kappa, sigma_stationary, var_tail, logG_tail, signG_tail, enter, exit, depth, out_tree_lca_index, PtE_abs, PtE2_abs, same_point_set) {
.Call(`_MetricGraph_directional_ou_covariance_oriented_tree_cpp`, E, edge_lengths, tree_orientation, kappa, sigma_stationary, var_tail, logG_tail, signG_tail, enter, exit, depth, out_tree_lca_index, PtE_abs, PtE2_abs, same_point_set)
}
#' @name draw_edge_direct_cpp
#' @title C++ direct bridge draw (Method A)
#' @description
#' Same algorithm as the R reference `draw_edge_direct`.
#' Builds S_e, Sigma*_e via the closed-form kernel, then draws
#' S_e b_e + chol(Sigma*_e)^T z. Uses Eigen::LLT and R::norm_rand().
#' @param kappa,tau SPDE parameters.
#' @param b_e Boundary state: length-2 (alpha=1) or length-4 (alpha=2).
#' @param l_e Edge length.
#' @param t_abs Interior locations in absolute coordinates (sorted).
#' @param alpha Smoothness: 1 or 2.
#' @noRd
draw_edge_direct_cpp <- function(kappa, tau, b_e, l_e, t_abs, alpha) {
.Call(`_MetricGraph_draw_edge_direct_cpp`, kappa, tau, b_e, l_e, t_abs, alpha)
}
#' @name draw_edge_kriging_cpp
#' @title C++ kriging-corrected Markov draw (Method B)
#' @description
#' Same algorithm as the R reference `draw_edge_kriging`.
#' Simulates a full Markov path on the edge, then applies the kriging
#' correction to enforce the vertex boundary conditions.
#' Uses a unique-lag cache for (A, chol(Omega)) and R::norm_rand().
#' @param kappa,tau SPDE parameters.
#' @param b_e Boundary state: length-2 (alpha=1) or length-4 (alpha=2).
#' @param l_e Edge length.
#' @param t_abs Interior locations in absolute coordinates (must be sorted).
#' @param alpha Smoothness: 1 or 2.
#' @noRd
draw_edge_kriging_cpp <- function(kappa, tau, b_e, l_e, t_abs, alpha) {
.Call(`_MetricGraph_draw_edge_kriging_cpp`, kappa, tau, b_e, l_e, t_abs, alpha)
}
#' @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)
}
#' @name nearest_edge_cpp
#' @title Nearest edge and snapped coordinates for a set of points
#' @description For every point, finds the edge minimizing the Euclidean
#' distance to the point and returns the closest point on that edge. Ties are
#' resolved towards the smallest edge index, matching \code{which.min()} on the
#' dense distance matrix this replaces.
#'
#' The edges are indexed in a uniform grid built from their bounding boxes, and
#' the search around each point expands ring by ring until no unvisited cell
#' can hold a closer edge, so the cost is proportional to the number of nearby
#' edges rather than to the total number of edges.
#' @param edges List of two-column numeric matrices.
#' @param XY `nx2 matrix` Coordinates of the points.
#' @return A list with the 1-based `index` of the nearest edge, a `2 x n`
#' matrix of snapped `coords` and the corresponding `dist`.
#' @noRd
nearest_edge_cpp <- function(edges, XY) {
.Call(`_MetricGraph_nearest_edge_cpp`, edges, XY)
}
selected_inv_cpp <- function(Q) {
.Call(`_MetricGraph_selected_inv_cpp`, Q)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.