Summary
The spatVectorCentroids slot on giottoPolygon is a cache of terra::centroids(). Since terra::centroids() runs in C++ and is O(n) in the number of polygons, it is always fast enough to compute on demand for any reasonable in-memory SpatVector size. The cache buys no meaningful performance.
Problem
Caching centroids adds sync burden across nearly every geometry method:
methods-flip.R, methods-crop.R, methods-rescale.R — must propagate transforms to the cached centroids
methods-extract.R, subset.R — must subset the cached centroids in lockstep
methods-rbind.R, join.R — must combine cached centroids
save_load.R, methods-wrap.R — must serialize/deserialize the cached centroids
slot_accessors.R (setPolygonInfo) — checks for pre-populated slot before deciding whether to generate spatlocs from centroids
Any mismatch between @spatVector and @spatVectorCentroids is a silent correctness bug.
Proposed change
- Remove the
spatVectorCentroids slot from giottoPolygon and packedGiottoPolygon
- Replace all reads of
@spatVectorCentroids with on-demand terra::centroids() calls (already the fallback in methods-centroids.R)
- Simplify
setPolygonInfo(centroids_to_spatlocs = TRUE) to always compute centroids rather than checking the slot
- Strip centroid propagation from all geometry methods
Summary
The
spatVectorCentroidsslot ongiottoPolygonis a cache ofterra::centroids(). Sinceterra::centroids()runs in C++ and is O(n) in the number of polygons, it is always fast enough to compute on demand for any reasonable in-memorySpatVectorsize. The cache buys no meaningful performance.Problem
Caching centroids adds sync burden across nearly every geometry method:
methods-flip.R,methods-crop.R,methods-rescale.R— must propagate transforms to the cached centroidsmethods-extract.R,subset.R— must subset the cached centroids in lockstepmethods-rbind.R,join.R— must combine cached centroidssave_load.R,methods-wrap.R— must serialize/deserialize the cached centroidsslot_accessors.R(setPolygonInfo) — checks for pre-populated slot before deciding whether to generate spatlocs from centroidsAny mismatch between
@spatVectorand@spatVectorCentroidsis a silent correctness bug.Proposed change
spatVectorCentroidsslot fromgiottoPolygonandpackedGiottoPolygon@spatVectorCentroidswith on-demandterra::centroids()calls (already the fallback inmethods-centroids.R)setPolygonInfo(centroids_to_spatlocs = TRUE)to always compute centroids rather than checking the slot