Skip to content

Commit

Permalink
Make Grid a Specialized trait
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Oct 19, 2021
1 parent 2036d36 commit 6bff649
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/CellGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import spire.math.Integral
/**
* A grid composed of cells with specific value types
*/
abstract class CellGrid[N: Integral] extends Grid[N] {
abstract class CellGrid[N: Integral] extends GridIntegral[N] {
def cellType: CellType
}
9 changes: 3 additions & 6 deletions raster/src/main/scala/geotrellis/raster/Grid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

package geotrellis.raster

import spire.math.Integral
import spire.implicits._

abstract class Grid[@specialized(Int, Long) N: Integral] extends Serializable {
trait Grid[@specialized(Int, Long) N] extends Serializable {
def cols: N
def rows: N
def size: N = cols * rows
def dimensions: Dimensions[N] = Dimensions(cols, rows)
def size: N
def dimensions: Dimensions[N]
}
4 changes: 2 additions & 2 deletions raster/src/main/scala/geotrellis/raster/GridExtent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import spire.implicits._
* The constructor will throw [[java.lang.IllegalArgumentException]] if the provided extent and cell size do not match the
* provided cols and rows (dimensions).
*/
class GridExtent[@specialized(Int, Long) N: Integral](
class GridExtent[N: Integral](
val extent: Extent,
val cellwidth: Double,
val cellheight: Double,
val cols: N,
val rows: N
) extends Grid[N] with Serializable {
) extends GridIntegral[N] with Serializable {
import GridExtent._

if (cols <= 0) throw GeoAttrsError(s"invalid cols: $cols")
Expand Down
25 changes: 25 additions & 0 deletions raster/src/main/scala/geotrellis/raster/GridIntegral.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2021 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geotrellis.raster

import spire.math.Integral
import spire.implicits._

abstract class GridIntegral[N: Integral] extends Grid[N] {
def size: N = cols * rows
def dimensions: Dimensions[N] = Dimensions(cols, rows)
}

0 comments on commit 6bff649

Please sign in to comment.