Skip to content

Commit

Permalink
Simplify Baroque Test add ScalaDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
James McClain committed Apr 11, 2016
1 parent 4ca3f65 commit 0c4c522
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
7 changes: 7 additions & 0 deletions raster/src/main/scala/geotrellis/raster/TileFeature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

package geotrellis.raster

/**
* The TileFeature Type. This is used for packaging a CellGrid (a
* Tile or MultibandTile) packaged together with some metadata.
*
* @param tile The CellGrid-derived tile
* @param data The additional metadata
*/
case class TileFeature[+T <: CellGrid,D](tile: T, data: D) {
def cellType: CellType = tile.cellType
def cols: Int = tile.cols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import geotrellis.raster._
import geotrellis.util.MethodExtensions


/**
* The BundleMethods type. This forms the basis for a typeclass that
* allows conforming types to be treated as base spaces with
* sequences of pixels attached at each point.
*/
trait BundleMethods[T] extends MethodExtensions[T] {
def cols: Int
def rows: Int
Expand Down
29 changes: 29 additions & 0 deletions raster/src/main/scala/geotrellis/raster/bundle/Implicits.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2016 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.bundle

import geotrellis.raster._
Expand All @@ -6,12 +22,25 @@ import geotrellis.raster._
object Implicits extends Implicits

trait Implicits {

/**
* An implicit conversion from a SinglebandTileBundleMethods to a
* BundleMethods.
*/
implicit def singlebandBundleMethodsToBundleMethods[D: ? => SinglebandTileBundleMethods](x: D): BundleMethods[D] =
implicitly[SinglebandTileBundleMethods](x).asInstanceOf[BundleMethods[D]]

/**
* An implicit conversion from a MultibandTileBundleMethods to a
* BundleMethods.
*/
implicit def multibandBundleMethodsToBundleMethods[D: ? => MultibandTileBundleMethods](x: D): BundleMethods[D] =
implicitly[MultibandTileBundleMethods](x).asInstanceOf[BundleMethods[D]]

/**
* An implicit conversion from a TileSeqBundleMethods to a
* BundleMethods.
*/
implicit def seqBundleMethodsToBundleMethods[D: ? => TileSeqBundleMethods](x: D): BundleMethods[D] =
implicitly[TileSeqBundleMethods](x).asInstanceOf[BundleMethods[D]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package geotrellis.raster.bundle
import geotrellis.raster._


/**
* Bundle methods for (Singleband) Tiles.
*/
trait SinglebandTileBundleMethods extends BundleMethods[Tile] {

def cols = self.cols
Expand All @@ -28,6 +31,19 @@ trait SinglebandTileBundleMethods extends BundleMethods[Tile] {
def fiber(col: Int, row: Int): Seq[Int] =
List(self.get(col, row))

/**
* A method to mix the present Singleband Tile with another object
* that is a member of the BundleMethods type class.
*
* The function argument is a function from (Int, Int, Seq[Int],
* Seq[Int]) to Seq[Int], where the first two arguments to it are
* the column and row, the last two arguments are the fibers at
* that position in this tile and the other "thing", and output is
* a new fiber.
*
* @param other The other "thing", a member of the BundleMethods type class
* @param fn The mixing function
*/
def mix[D: ? => BundleMethods[D]](other: D, fn: (Int, Int, Seq[Int], Seq[Int]) => Seq[Int]): Tile = {
require(cols == other.cols && rows == other.rows, "Dimensions must match")

Expand Down
16 changes: 1 addition & 15 deletions spark/src/test/scala/geotrellis/spark/io/TileFeatureIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class TileFeatureIOSpec
val deleter = FileLayerDeleter(outputLocalPath)

it("should allow proper writing and reading") {
import java.security.MessageDigest
val md = MessageDigest.getInstance("SHA-256");
val layerId = LayerId("TileFeatureLayer", 0)

try {
Expand All @@ -45,19 +43,7 @@ class TileFeatureIOSpec
.sortWith((a,b) => a.toString.compareTo(b.toString) < 0)

toDisk.zip(fromDisk).map({ case (a,b) =>
md.reset
md.update(a._1.toString.getBytes)
md.update(a._2.tile.toBytes)
md.update(a._2.data.toBytes)
val digestA = md.digest

md.reset
md.update(b._1.toString.getBytes)
md.update(b._2.tile.toBytes)
md.update(b._2.data.toBytes)
val digestB = md.digest

MessageDigest.isEqual(digestA, digestB) should be (true)
a should equal (b)
})
}
finally {
Expand Down

0 comments on commit 0c4c522

Please sign in to comment.