main.com.enniovisco.space.Grid.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webmonitor Show documentation
Show all versions of webmonitor Show documentation
A formal approach to monitoring web pages as spatio-temporal traces.
The newest version!
package com.enniovisco.space
import io.github.moonlightsuite.moonlight.core.space.*
import io.github.moonlightsuite.moonlight.space.*
class Grid(val rows: Int, val columns: Int) {
/**
* The spatial model built for the current grid
*/
val model = generateModel(rows, columns)
/**
* The 1-d size of the grid
* @return [rows] x [columns]
*/
val size = model.size()
private fun generateModel(rows: Int, columns: Int) =
RegularGridModel(rows, columns, 1)
/**
* from 1-d location to (X,Y) pairs
*/
fun toXY(location: Int): Pair {
val coords = model.toCoordinates(location)
return Pair(coords[0], coords[1])
}
/**
* from (X,Y) pairs to 1-d location
*/
fun toNode(xyCoords: Pair): Int {
return model.fromCoordinates(xyCoords.first, xyCoords.second)
}
/**
* It calculates the proper distance, given a spatial model
*
* @return a DoubleDistance object, meaningful in the given Spatial Model
*/
fun distance(max: Int = size): DistanceStructure {
val isParallel = true
val baseline = 0
return IntManhattanDistanceStructure(isParallel, baseline, max, model)
}
}