Skip to content

Commit

Permalink
Moved widening bit math into companion of WideIntNoData.
Browse files Browse the repository at this point in the history
Signed-off-by: Simeon H.K. fitch <fitch@astraea.io>
  • Loading branch information
metasim committed Apr 28, 2017
1 parent 64a76a9 commit c7bdf73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions raster/src/main/scala/geotrellis/raster/CellType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ case object UByteConstantNoDataCellType
extends UByteCells with ConstantNoData
case class UByteUserDefinedNoDataCellType(noDataValue: Byte)
extends UByteCells with UserDefinedNoData[Byte] {
override def widenedNoData(implicit ev: Numeric[Byte]) = WideIntNoData(noDataValue & 0xFF)
override def widenedNoData(implicit ev: Numeric[Byte]) = WideIntNoData(noDataValue)
}

case object ShortCellType
Expand All @@ -367,7 +367,7 @@ case object UShortConstantNoDataCellType
extends UShortCells with ConstantNoData
case class UShortUserDefinedNoDataCellType(noDataValue: Short)
extends UShortCells with UserDefinedNoData[Short] {
override def widenedNoData(implicit ev: Numeric[Short]) = WideIntNoData(noDataValue & 0xFFFF)
override def widenedNoData(implicit ev: Numeric[Short]) = WideIntNoData(noDataValue)
}

case object IntCellType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sealed trait UserDefinedNoDataEncoding extends CellTypeEncoding { self ⇒
val number = text.replace(name, "")

if(isFloatingPoint) Try(number.toDouble).map(WideDoubleNoData).toOption
else Try(number.toInt).map(WideIntNoData).toOption
else Try(number.toInt).map(WideIntNoData.apply).toOption
}
else None
}
Expand All @@ -100,6 +100,10 @@ sealed trait WidenedNoData {
case class WideIntNoData(asInt: Int) extends WidenedNoData {
def asDouble = asInt.toDouble
}
object WideIntNoData {
def apply(thinned: Byte) = new WideIntNoData(thinned & 0xFF)
def apply(thinned: Short) = new WideIntNoData(thinned & 0xFFFF)
}

/** NoData stored as a Double */
case class WideDoubleNoData(asDouble: Double) extends WidenedNoData {
Expand Down

0 comments on commit c7bdf73

Please sign in to comment.