Skip to content

Commit

Permalink
Dry code
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Apr 29, 2022
1 parent 5ef8031 commit 4cb6b6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Azavea
* Copyright 2022 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,26 +19,16 @@ package com.azavea.hiveless.spatial.index
import com.azavea.hiveless.HUDF
import com.azavea.hiveless.spatial._
import com.azavea.hiveless.implicits.tupler._
import com.azavea.hiveless.serializers.HDeserializer.Errors.ProductDeserializationError
import geotrellis.vector._
import shapeless._

class ST_Contains extends HUDF[(ST_Contains.Arg, ST_Contains.Arg), Boolean] {
def function = ST_Contains.function
}

object ST_Contains {
// We could use Either[Extent, Geometry], but Either has no safe fall back CNil
// which may lead to derivation error messages rather than parsing
type Arg = Extent :+: Geometry :+: CNil

def parseGeometry(a: Arg): Option[Geometry] = a.select[Geometry].orElse(a.select[Extent].map(_.toPolygon()))

private def parseGeometryUnsafe(a: Arg, aname: String): Geometry =
parseGeometry(a).getOrElse(throw ProductDeserializationError[ST_Contains, Arg](aname))
type Arg = ST_Intersects.Arg

def function(left: Arg, right: Arg): Boolean = {
val (l, r) = (parseGeometryUnsafe(left, "first"), parseGeometryUnsafe(right, "second"))
val (l, r) = (ST_Intersects.parseGeometryUnsafe(left, "first"), ST_Intersects.parseGeometryUnsafe(right, "second"))

l.contains(r)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ST_Intersects {

def parseGeometry(a: Arg): Option[Geometry] = a.select[Geometry].orElse(a.select[Extent].map(_.toPolygon()))

private def parseGeometryUnsafe(a: Arg, aname: String): Geometry =
def parseGeometryUnsafe(a: Arg, aname: String): Geometry =
parseGeometry(a).getOrElse(throw ProductDeserializationError[ST_Intersects, Arg](aname))

def function(left: Arg, right: Arg): Boolean = {
Expand Down

0 comments on commit 4cb6b6d

Please sign in to comment.