Skip to content

Commit

Permalink
feat: convHull()
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Oct 26, 2024
1 parent cea82c0 commit e553a5a
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Imports:
methods,
reticulate (>= 1.25),
stats,
terra (>= 1.7-39)
terra (>= 1.7-41)
Suggests:
Biobase,
chihaya,
Expand Down Expand Up @@ -109,6 +109,7 @@ Collate:
'methods-affine.R'
'methods-centroids.R'
'methods-coerce.R'
'methods-convHull.R'
'methods-copy.R'
'methods-crop.R'
'methods-dims.R'
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ exportMethods(as.terra)
exportMethods(calculateOverlap)
exportMethods(centroids)
exportMethods(colnames)
exportMethods(convHull)
exportMethods(copy)
exportMethods(createGiottoPoints)
exportMethods(createGiottoPolygon)
Expand All @@ -335,6 +336,8 @@ exportMethods(flip)
exportMethods(hist)
exportMethods(instructions)
exportMethods(intersect)
exportMethods(minCircle)
exportMethods(minRect)
exportMethods(ncol)
exportMethods(nrow)
exportMethods(objName)
Expand Down Expand Up @@ -389,12 +392,15 @@ importMethodsFrom(terra,as.data.frame)
importMethodsFrom(terra,as.points)
importMethodsFrom(terra,as.polygons)
importMethodsFrom(terra,centroids)
importMethodsFrom(terra,convHull)
importMethodsFrom(terra,crop)
importMethodsFrom(terra,density)
importMethodsFrom(terra,ext)
importMethodsFrom(terra,flip)
importMethodsFrom(terra,hist)
importMethodsFrom(terra,intersect)
importMethodsFrom(terra,minCircle)
importMethodsFrom(terra,minRect)
importMethodsFrom(terra,ncol)
importMethodsFrom(terra,nrow)
importMethodsFrom(terra,plot)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## breaking changes
- stop exporting deprecated internal accessors
- terra requirement raised to 1.7.41 for `minCircle()`

## bug fixes
- fix `dimnames()` for some subobjects
Expand Down Expand Up @@ -34,6 +35,7 @@
- `splitGiotto()` for splitting a Giotto object into a list of Giotto objects based on a cell metadata column
- `as.list()` method for `giotto` to dump the data as a list of subobjects
- `XY()` and `XY<-()` for accessing and setting coordinate values of subobjects as `matrix`
- terra `convHull()`, `minRect()`, `minCircle()` for Giotto spatial vector classes


# GiottoClass 0.3.5 (2024/08/28)
Expand Down
73 changes: 73 additions & 0 deletions R/methods-convHull.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# docs ----------------------------------------------------------- #
#' @title Convex hull, minimal bounding rotated rectangle, and minimal bounding circle
#' @name convHull
#' @description Get the convex hull, the minimal bounding rotated rectangle,
#' or minimal bounding circle of a Giotto spatial object or terra SpatVector
#' @param x any of giotto image, giottoPolygon, giottoPoints, spatLocsObj, SpatVector
#' @param by character (variable name), to get a new geometry for groups of input geometries
#' @param \dots additional parameters to pass
#' @examples
#' sl <- GiottoData::loadSubObjectMini("spatLocsObj")
#' gpoints <- GiottoData::loadSubObjectMini("giottoPoints")
#'
#' h <- convHull(sl)
#' plot(h)
#'
#' r <- minRect(sl)
#' plot(r)
#'
#' circ <- minCircle(gpoints, by = "feat_ID")
#' plot(circ, border = rainbow(100))
#'
#' @returns SpatVector
NULL
# ---------------------------------------------------------------- #

#' @rdname convHull
#' @usage
#' ## S4 method for signatures 'spatLocsObj', 'giottoPolygon', 'giottoPoints'
#' convHull(x, by = "")
#' @export
setMethod("convHull", signature("spatLocsObj"), function(x, by = "") {
convHull(x = as.points(x), by = by)
})
#' @rdname convHull
#' @usage NULL
#' @export
setMethod("convHull", signature("giottoSpatial"), function(x, by = "") {
convHull(x[], by = by)
})


#' @rdname convHull
#' @usage
#' ## S4 method for signatures 'spatLocsObj', 'giottoPolygon', 'giottoPoints'
#' minRect(x, by = "")
#' @export
setMethod("minRect", signature("spatLocsObj"), function(x, by = "") {
minRect(x = as.points(x), by = by)
})
#' @rdname convHull
#' @usage NULL
#' @export
setMethod("minRect", signature("giottoSpatial"), function(x, by = "") {
minRect(x[], by = by)
})


#' @rdname convHull
#' @usage
#' ## S4 method for signatures 'spatLocsObj', 'giottoPolygon', 'giottoPoints'
#' minCircle(x, by = "")
#' @export
setMethod("minCircle", signature("spatLocsObj"), function(x, by = "") {
minCircle(x = as.points(x), by = by)
})
#' @rdname convHull
#' @usage NULL
#' @export
setMethod("minCircle", signature("giottoSpatial"), function(x, by = "") {
minCircle(x[], by = by)
})


2 changes: 1 addition & 1 deletion R/package_imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @importMethodsFrom terra rescale
#' @importMethodsFrom Matrix t
#' @importMethodsFrom terra t
#' @importMethodsFrom terra ext ext<-
#' @importMethodsFrom terra ext ext<- convHull minCircle minRect
#' @importMethodsFrom terra plot
#' @importMethodsFrom terra wrap
#' @importMethodsFrom terra zoom
Expand Down
49 changes: 49 additions & 0 deletions man/convHull.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e553a5a

Please sign in to comment.