<packageNotFoundError/error/condition>
Error in `loadNamespace(x)`: there is no package called 'CRiSpData'

test_that("a stroke is found in a very simple network", {
expected <- sf::st_sfc(sf::st_linestring(c(p1, p2, p3)), l3)
test_that("a ring is recognized as a stroke", {
expected <- sf::st_sfc(sf::st_linestring(c(p2, p3, p6, p5, p2)))
test_that("a ring with a branch is recognized as one stroke", {
expected <- sf::st_sfc(sf::st_linestring(c(p1, p2, p3, p6, p5, p2)))
test_that("more strokes are recognized in a ring with multiple branches", {
expected <- sf::st_sfc(sf::st_linestring(c(p1, p2, p3, p6, p5, p2)), l3)
test_that("sf objects can be used in input", {
test_that("sfnetworks objects can be used in input", {
net <- sfnetworks::sfnetwork(nodes = nodes, edges = edges,
test_that("multilinestrings are not supported", {
test_that("proper attributes are returned for a very simple network", {
actual <- stroke(sfc, attributes = TRUE, flow_mode = TRUE)
test_that("proper attributes are returned for a more complex network", {
sfc, angle_threshold = 0, attributes = TRUE, flow_mode = TRUE
test_that("two linesegments are always merged if threshold is zero", {
expected <- sf::st_sfc(sf::st_linestring(c(p5, p2, p3)))
actual <- stroke(sfc, angle_threshold = 0)
test_that("a more complex network with no threshold form a stroke", {
expected <- sf::st_sfc(sf::st_linestring(c(p1, p2, p5, p6)), l5)
test_that("a more complex network with threshold does not form strokes", {
actual <- stroke(sfc, angle_threshold = 150.)
test_that("attributes cannot be returned if not in flow mode", {
expect_error(stroke(sfc, attributes = TRUE, flow_mode = FALSE),
"Stroke attributes can be returned only if `flow_mode = TRUE`)")
test_that("edges can be split if flow_mode is false", {
new_l1 <- sf::st_linestring(c(p1, p2, p5))
expected <- sf::st_sfc(sf::st_linestring(c(p1, p2, p3)),
actual <- stroke(sfc, flow_mode = FALSE)
test_that("edges are not split if flow_mode is true", {
test_that("a ring is recognized as a stroke also in flow_mode", {
test_that("strokes can be formed starting from a given edge", {
new_l1 <- sf::st_linestring(c(p1, p2, p3))
expected <- sf::st_sfc(sf::st_linestring(c(p1, p2, p5, p6)))
actual <- stroke(sfc, flow_mode = FALSE, from_edge = list(3))
test_that("strokes can be formed starting from a given a list of edge ids", {
stroke_1 <- sf::st_linestring(c(p1, p2, p3))
stroke_2 <- sf::st_linestring(c(p1, p2, p5, p6))
actual <- stroke(sfc, flow_mode = FALSE, from_edge = list(1, 3))
test_that("same strokes can be formed when one of the edges is reversed", {
stroke_2 <- sf::st_linestring(c(p6, p5, p2, p1))
actual <- stroke(sfc, flow_mode = FALSE, from_edge = list(1, 2))
test_that("attributes can't be returned if edge is specified", {
expect_error(stroke(sfc, attribute = TRUE, flow_mode = TRUE, from_edge = 3),
"from_edge is not compatible with attributes or flow_mode")
test_that("a ring is recognized when from_edge is specified", {
test_that("flow mode does not break edges on a real dataset", {
strokes <- rcoins::stroke(edges, flow_mode = TRUE)
# find out which of the initial edges are contained in each of the strokes
# NOTE: edges that form self-crossing strokes may be missed by the "contains"
# relationship. However, they are catched by the "overlaps" relationship,
# which is why we run both predicate and merge results
# merge the groups of edges in (multi)linestrings
if (sf::st_geometry_type(union) == "LINESTRING") {
# compare the grouped edges to the strokes: if identical, this means that
# the strokes contain full edges, i.e. flow_mode is respected
# NOTE: element-wise comparison may fail because all "strokes" are
# linestrings, while "edges_merged" includes some multilinestrings in the case
# of self-intersections. We thus check for "topological" equality, by checking
# that for each pair of geometries A and B, A is in B and B is in A. For the
# reasons described above, we use "contains_or_overlaps" to this end.