import Centroids from 'Artistoo/src/stats/Centroids.js'
public class

# Centroids

#### Extends:

Stat → Centroids

This Stat computes the centroid of a cell. When the cell resides on a torus, the centroid may be well outside the cell, and other stats may be preferable (e.g. CentroidsWithTorusCorrection).

#### Example:

let CPM = require( "path/to/build" )

// Make a CPM, seed two cells, run a little, and get their centroids
let C = new CPM.CPM( [100,100], {
T:20,
torus:[false,false],
J:[[0,20],[20,10]],
V:[0,200],
LAMBDA_V:[0,2]
} )
let gm = new CPM.GridManipulator( C )
gm.seedCell(1)
gm.seedCell(1)
for( let t = 0; t < 100; t++ ){ C.timeStep() }

C.getStat( CPM.Centroids ) 

## Member Summary

 Public Members public The model to compute centroids on. public set model(M: GridBasedModel) The set model method of class CentroidsWithTorusCorrection.

## Method Summary

 Public Methods public Compute centroids for all cells on the grid. public computeCentroidOfCell(cellid: CellId, cellpixels: CellArrayObject): ArrayCoordinate This method computes the centroid of a specific cell.

## Inherited Summary

 From class Stat public set model(M: GridBasedModel) Every stat is linked to a specific model. public The model to compute the stat on. public Configuration object for the stat, which should not change its value but may be used for logging and debugging options. public abstract compute() The compute method of the base Stat class throws an error, enforcing that you have to implement this method when you build a new stat class extending this base class.

## Public Members

### publicM: GridBasedModel source

The model to compute centroids on.

Stat#M

### publicsetmodel(M: GridBasedModel) source

The set model method of class CentroidsWithTorusCorrection.

Stat#model

## Public Methods

### publiccompute(): CellObject source

Compute centroids for all cells on the grid.

Stat#compute

#### Return:

 CellObject with an ArrayCoordinate of the centroid for each cell on the grid (see computeCentroidOfCell).

### publiccomputeCentroidOfCell(cellid: CellId, cellpixels: CellArrayObject): ArrayCoordinate source

This method computes the centroid of a specific cell.

#### Params:

 Name Type Attribute Description cellid CellId the unique cell id of the cell to get centroid of. cellpixels CellArrayObject object produced by PixelsByCell, with keys for each cellid and as corresponding value the pixel coordinates of their pixels.

#### Return:

 ArrayCoordinate coordinate of the centroid.