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

Lazy init Extent and ProjectedExtent Circe codecs #3458

Merged
merged 1 commit into from
Mar 31, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Dependencies update [#3452](https://github.com/locationtech/geotrellis/pull/3452)
- Lazy init circe codecs in the vector module [#3457](https://github.com/locationtech/geotrellis/pull/3457)
- Lazy init Circe codecs in the vector module [#3457](https://github.com/locationtech/geotrellis/pull/3457)
- Lazy init Extent and ProjectedExtent Circe codecs [#3458](https://github.com/locationtech/geotrellis/pull/3457)

## [3.6.1] - 2022-03-12

Expand Down
24 changes: 13 additions & 11 deletions vector/src/main/scala/geotrellis/vector/Extent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ import org.locationtech.jts.{geom => jts}
import cats.syntax.either._
import _root_.io.circe._
import _root_.io.circe.syntax._
import _root_.io.circe.generic.JsonCodec
import _root_.io.circe.generic.semiauto.{deriveEncoder, deriveDecoder}

case class ExtentRangeError(msg:String) extends Exception(msg)
case class ExtentRangeError(msg: String) extends Exception(msg)

object Extent {
implicit lazy val extentEncoder: Encoder[Extent] = deriveEncoder
implicit lazy val extentDecoder: Decoder[Extent] = deriveDecoder

lazy val listEncoder: Encoder[Extent] =
Encoder.instance { extent => List(extent.xmin, extent.ymin, extent.xmax, extent.ymax).asJson }

Expand All @@ -44,7 +47,7 @@ object Extent {
*
* @param s A string of the form "xmin,ymin,xmax,ymax"
*/
def fromString(s:String) = {
def fromString(s: String): Extent = {
val Array(xmin,ymin,xmax,ymax) = s.split(",").map(_.toDouble)
Extent(xmin,ymin,xmax,ymax)
}
Expand All @@ -62,7 +65,6 @@ object Extent {
* @param extent The Extent which is projected
* @param crs The CRS projection of this extent
*/
@JsonCodec
case class ProjectedExtent(extent: Extent, crs: CRS) {
def reproject(dest: CRS): Extent =
extent.reproject(crs, dest)
Expand All @@ -73,8 +75,11 @@ case class ProjectedExtent(extent: Extent, crs: CRS) {

/** ProjectedExtent companion object */
object ProjectedExtent {
implicit def fromTupleA(tup: (Extent, CRS)):ProjectedExtent = ProjectedExtent(tup._1, tup._2)
implicit def fromTupleB(tup: (CRS, Extent)):ProjectedExtent = ProjectedExtent(tup._2, tup._1)
implicit def fromTupleA(tup: (Extent, CRS)): ProjectedExtent = ProjectedExtent(tup._1, tup._2)
implicit def fromTupleB(tup: (CRS, Extent)): ProjectedExtent = ProjectedExtent(tup._2, tup._1)

implicit lazy val projectedExtentEncoder: Encoder[ProjectedExtent] = deriveEncoder
implicit lazy val projectedExtentDecoder: Decoder[ProjectedExtent] = deriveDecoder
}

/** A rectangular region of geographic space
Expand All @@ -84,7 +89,6 @@ object ProjectedExtent {
* @param xmax The maximum x coordinate
* @param ymax The maximum y coordinate
*/
@JsonCodec
case class Extent(
xmin: Double, ymin: Double,
xmax: Double, ymax: Double
Expand Down Expand Up @@ -326,17 +330,15 @@ case class Extent(
*
* @note only returns true given another extent
*/
override
def equals(o: Any): Boolean =
override def equals(o: Any): Boolean =
o match {
case other: Extent =>
xmin == other.xmin && ymin == other.ymin &&
xmax == other.xmax && ymax == other.ymax
case _ => false
}

override
def hashCode(): Int = (xmin, ymin, xmax, ymax).hashCode
override def hashCode(): Int = (xmin, ymin, xmax, ymax).hashCode

override def toString = s"Extent($xmin, $ymin, $xmax, $ymax)"
}