@@ -22,11 +22,14 @@ import org.locationtech.jts.{geom => jts}
2222import cats .syntax .either ._
2323import _root_ .io .circe ._
2424import _root_ .io .circe .syntax ._
25- import _root_ .io .circe .generic .JsonCodec
25+ import _root_ .io .circe .generic .semiauto .{ deriveEncoder , deriveDecoder }
2626
27- case class ExtentRangeError (msg: String ) extends Exception (msg)
27+ case class ExtentRangeError (msg : String ) extends Exception (msg)
2828
2929object Extent {
30+ implicit lazy val extentEncoder : Encoder [Extent ] = deriveEncoder
31+ implicit lazy val extentDecoder : Decoder [Extent ] = deriveDecoder
32+
3033 lazy val listEncoder : Encoder [Extent ] =
3134 Encoder .instance { extent => List (extent.xmin, extent.ymin, extent.xmax, extent.ymax).asJson }
3235
@@ -44,7 +47,7 @@ object Extent {
4447 *
4548 * @param s A string of the form "xmin,ymin,xmax,ymax"
4649 */
47- def fromString (s: String ) = {
50+ def fromString (s : String ): Extent = {
4851 val Array (xmin,ymin,xmax,ymax) = s.split(" ," ).map(_.toDouble)
4952 Extent (xmin,ymin,xmax,ymax)
5053 }
@@ -62,7 +65,6 @@ object Extent {
6265 * @param extent The Extent which is projected
6366 * @param crs The CRS projection of this extent
6467 */
65- @ JsonCodec
6668case class ProjectedExtent (extent : Extent , crs : CRS ) {
6769 def reproject (dest : CRS ): Extent =
6870 extent.reproject(crs, dest)
@@ -73,8 +75,11 @@ case class ProjectedExtent(extent: Extent, crs: CRS) {
7375
7476/** ProjectedExtent companion object */
7577object ProjectedExtent {
76- implicit def fromTupleA (tup : (Extent , CRS )): ProjectedExtent = ProjectedExtent (tup._1, tup._2)
77- implicit def fromTupleB (tup : (CRS , Extent )): ProjectedExtent = ProjectedExtent (tup._2, tup._1)
78+ implicit def fromTupleA (tup : (Extent , CRS )): ProjectedExtent = ProjectedExtent (tup._1, tup._2)
79+ implicit def fromTupleB (tup : (CRS , Extent )): ProjectedExtent = ProjectedExtent (tup._2, tup._1)
80+
81+ implicit lazy val projectedExtentEncoder : Encoder [ProjectedExtent ] = deriveEncoder
82+ implicit lazy val projectedExtentDecoder : Decoder [ProjectedExtent ] = deriveDecoder
7883}
7984
8085/** A rectangular region of geographic space
@@ -84,7 +89,6 @@ object ProjectedExtent {
8489 * @param xmax The maximum x coordinate
8590 * @param ymax The maximum y coordinate
8691 */
87- @ JsonCodec
8892case class Extent (
8993 xmin : Double , ymin : Double ,
9094 xmax : Double , ymax : Double
@@ -326,17 +330,15 @@ case class Extent(
326330 *
327331 * @note only returns true given another extent
328332 */
329- override
330- def equals (o : Any ): Boolean =
333+ override def equals (o : Any ): Boolean =
331334 o match {
332335 case other : Extent =>
333336 xmin == other.xmin && ymin == other.ymin &&
334337 xmax == other.xmax && ymax == other.ymax
335338 case _ => false
336339 }
337340
338- override
339- def hashCode (): Int = (xmin, ymin, xmax, ymax).hashCode
341+ override def hashCode (): Int = (xmin, ymin, xmax, ymax).hashCode
340342
341343 override def toString = s " Extent( $xmin, $ymin, $xmax, $ymax) "
342344}
0 commit comments