import CentroidsWithTorusCorrection from 'Artistoo/src/stats/CentroidsWithTorusCorrection.js'
public class | source

CentroidsWithTorusCorrection

Extends:

Stat → CentroidsWithTorusCorrection

This Stat computes the centroid of a cell when grid has a torus.

!!! Assumption: cell pixels never extend for more than half the size of the grid. If this assumption does not hold, centroids may be computed wrongly.

See also Centroids for a version without torus correction.

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:[true,true],
	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.CentroidsWithTorusCorrection ) 

Member Summary

Public Members
public

The model to compute centroids on.

public set

The set model method of class CentroidsWithTorusCorrection.

Method Summary

Public Methods
public

This method computes the centroids of all cells on the grid.

public

This method computes the centroid of a specific cell with id = <cellid>.

Inherited Summary

From class Stat
public set

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

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

public M: GridBasedModel source

The model to compute centroids on.

Override:

Stat#M

public set model(M: GridBasedModel) source

The set model method of class CentroidsWithTorusCorrection.

Override:

Stat#model

Public Methods

public compute(): CellObject source

This method computes the centroids of all cells on the grid.

Override:

Stat#compute

Return:

CellObject

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

public computeCentroidOfCell(cellid: CellId, cellpixels: CellArrayObject): ArrayCoordinate source

This method computes the centroid of a specific cell with id = <cellid>. The cellpixels object is given as an argument so that it only has to be requested once for all cells together.

Params:

NameTypeAttributeDescription
cellid CellId

ID number of the cell to get centroid of.

cellpixels CellArrayObject

object produced by PixelsByCell, where keys are the cellids of all non-background cells on the grid, and the corresponding value is an array of the pixels belonging to that cell specified by their ArrayCoordinate.

Return:

ArrayCoordinate

the centroid of the current cell.