
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(s2)
> 
> u = s2_union(
+    "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
+    "POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
+    s2_options(snap = s2_snap_level(30))
+ )
> s2_area(u, radius = 1)
[1] 0.05284581
> s2_area("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", radius = 1) +
+ s2_area("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))", radius = 1) -
+ s2_area("POLYGON ((5 5, 10 5, 10 15, 5 10, 5 5))", radius = 1)
[1] 0.04910511
> s2_area("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", radius = 1)
[1] 0.03038216
> s2_area("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))", radius = 1)
[1] 0.03002974
> s2_area("POLYGON ((5 5, 10 5, 10 15, 5 10, 5 5))", radius = 1)
[1] 0.01130679
> 
> df = s2_difference(
+    "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
+    "POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
+    s2_options(snap = s2_snap_level(30))
+ )
> s2_area(df, radius = 1) -
+   (s2_area("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", radius = 1) -
+     s2_area("POLYGON ((5 5, 10 5, 10 15, 5 10, 5 5))", radius = 1))
[1] 0.003740703
> 
> proc.time()
   user  system elapsed 
  0.436   1.276   0.215 
