Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialize Grid for Int and Long #3428

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Disambiguate withBufferTileFocalMethods implicit preserving bin compatibility [#3422](https://github.com/locationtech/geotrellis/pull/3422)
- Specialize Grid for Int and Long [#3428](https://github.com/locationtech/geotrellis/pull/3428)

## [3.6.0] - 2021-04-30

Expand Down
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[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](
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a specialized trait is enough!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... That's really good to know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val extent: Extent,
val cellwidth: Double,
val cellheight: Double,
val cols: N,
val rows: N
) extends Grid[N] with Serializable {
) extends GridIntegral[N] {
Copy link
Member Author

@pomadchin pomadchin Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trait Grid[N] extends 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)
}