Define orientation for each polygon, clockwise or counterclockwise

add_orientation_JamPolygon(
  jp,
  flip_sign = 1,
  include_holes = FALSE,
  include_clockwise = FALSE,
  include_parent = FALSE,
  verbose = FALSE,
  ...
)

Arguments

jp

JamPolygon

flip_sign

integer to indicate whether the orientation should be flipped, inverting the meaning of all returned values. This argument is intended to be used when defining inner and outer borders alongside something like vwline::grid.vwline() which defines border on the left and right, as it travels from point to point. By using flip_sign=-1 it will flip the right and left sides accordingly.

include_holes, include_clockwise, include_parent

logical indicating whether to include additional columns to describe multi-part polygons. The clockwise direction is used to define the inner and outer edge of the border, usually defined as left or right, in relation to the direction the line is drawn. Nested multi-part polygons define interior holes, and are distinguished from adjacent polygons.

  • "polygon_clockwise": 1 clockwise, -1 counter-clockwise

  • "polygon_holes": 1 is a solid polygon, -1 is a hole inside another polygon indicated with "polygon_parent".

  • "polygon_parent": integer index used to indicate the parent polygon for nested multi-part polygons. The index will indicate itself, when the polygon is not nested inside another polygon.

verbose

logical indicating whether to print verbose output.

...

additional arguments are ignored

Value

JamPolygon with column "orientation" added to slot "polygons".

Details

Todo:

  • When polygons are nested, which is intended to create holes inside one larger polygon, the hole should have its orientation flipped so that the border is drawn on the opposite side per its orientation. So the task is to determine whether a polygon is the hole of another polygon.

Examples

df3 <- data.frame(name=c("polygon1", "polygon2"),
   label=c("polygon1", "polygon2"),
   x=I(list(
      list(c(1, 6, 6, 1),
         c(2, 5, 5, 2),
         c(3, 4, 4, 3)),
      list(#c(11, 16, 16, 11),
         c(12, 15, 15, 12),
         c(13, 14, 14, 13))
      )),
   y=I(list(
      list(c(1, 1, 6, 6),
         c(2, 2, 5, 5),
         c(3, 3, 4, 4)),
      list(#c(1, 1, 6, 6),
         c(2, 2, 5, 5),
         c(3, 3, 4, 4))
      )),
   fill=c("gold", "firebrick"))
jp3 <- new("JamPolygon", polygons=df3);
plot(jp3);


add_orientation_JamPolygon(jp3,
   include_holes=TRUE,
   include_clockwise=TRUE,
   include_parent=TRUE)
#> An object of class "JamPolygon"
#> Slot "polygons":
#>       name    label            x            y      fill orientation
#> 1 polygon1 polygon1 c(1, 6, .... c(1, 1, ....      gold    1, -1, 1
#> 2 polygon2 polygon2 c(12, 15.... c(2, 2, .... firebrick       1, -1
#>   polygon_holes polygon_clockwise polygon_parent
#> 1      1, -1, 1           1, 1, 1        1, 1, 1
#> 2         1, -1              1, 1           1, 1
#>