Skip to content

Remove spatVectorCentroids slot from giottoPolygon #342

@jiajic

Description

@jiajic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions