Permalink
Browse files

dale - exceptOrthant in Ops

  • Loading branch information...
Sciss committed Jun 17, 2012
1 parent e75cd7c commit 6cd374023956de041421b2179d7e55f6e5a36db6
@@ -57,6 +57,8 @@ object DistanceMeasure {
def approximate( thresh: M ) : Ops[ M, D ]
def orthant( idx: Int ) : Ops[ M, D ]
+
+ def exceptOrthant( idx: Int ) : Ops[ M, D ]
}
}
/**
@@ -85,17 +85,6 @@ object IntDistanceMeasure2D {
}
}
-// private final class SouthWest( underlying: Impl ) extends Impl {
-// def distance( a: Point, b: Point ) =
-// if( b.x <= a.x && b.y >= a.y ) underlying.distance( a, b ) else Long.MaxValue
-//
-// def minDistance( p: Point, q: HyperCube ) =
-// if( p.x >= q.left && p.y <= q.bottom ) underlying.minDistance( p, q ) else Long.MaxValue
-//
-// def maxDistance( p: Point, q: HyperCube ) =
-// if( q.right <= p.x && q.top >= p.y ) underlying.maxDistance( p, q ) else Long.MaxValue
-// }
-
private final class Quadrant( underlying: DistanceMeasure[ Long, TwoDim ], idx: Int )
extends Impl {
private val right = idx == 0 || idx == 3
@@ -134,6 +123,44 @@ object IntDistanceMeasure2D {
}
}
+ private final class ExceptQuadrant( underlying: DistanceMeasure[ Long, TwoDim ], idx: Int )
+ extends Impl {
+ private val right = idx == 0 || idx == 3
+ private val bottom = idx >= 2
+
+ override def toString = underlying.toString + ".exceptQuadrant(" + idx + ")"
+
+ def distance( a: PointLike, b: PointLike ) : Long = {
+ if( (if( right ) b.x <= a.x else b.x >= a.x) ||
+ (if( bottom ) b.y <= a.y else b.y >= a.y) ) {
+
+ underlying.distance( a, b )
+ } else Long.MaxValue
+ }
+
+ def minDistance( p: PointLike, q: HyperCube ) : Long = {
+ val qe = q.extent
+ val qem1 = qe - 1
+
+ if( (if( right ) (q.cx - qe) <= p.x else (q.cx + qem1) >= p.x) ||
+ (if( bottom ) (q.cy - qe) <= p.y else (q.cy + qem1) >= p.y) ) {
+
+ underlying.minDistance( p, q )
+ } else Long.MaxValue
+ }
+
+ def maxDistance( p: PointLike, q: HyperCube ) : Long = {
+ val qe = q.extent
+ val qem1 = qe - 1
+
+ if( (if( right ) (q.cx + qem1) <= p.x else (q.cx - qe) >= p.x) ||
+ (if( bottom ) (q.cy + qem1) <= p.y else (q.cy - qe) >= p.y) ) {
+
+ underlying.maxDistance( p, q )
+ } else Long.MaxValue
+ }
+ }
+
private sealed trait ChebyshevLike extends Impl {
protected def apply( dx: Long, dy: Long ) : Long
@@ -234,5 +261,9 @@ object IntDistanceMeasure2D {
require( idx >= 0 && idx < 4, "Quadrant index out of range (" + idx + ")" )
new Quadrant( this, idx )
}
+ final def exceptOrthant( idx: Int ) : M = {
+ require( idx >= 0 && idx < 4, "Quadrant index out of range (" + idx + ")" )
+ new ExceptQuadrant( this, idx )
+ }
}
}
@@ -107,6 +107,8 @@ object IntDistanceMeasure3D {
private val bottom = (idx & 2) != 0
private val back = (idx & 4) != 0
+ override def toString = underlying.toString + ".quadrant(" + idx + ")"
+
def distance( a: PointLike, b: PointLike ) : M = {
if( (if( right ) b.x >= a.x else b.x <= a.x) &&
(if( bottom ) b.y >= a.y else b.y <= a.y) &&
@@ -147,6 +149,57 @@ object IntDistanceMeasure3D {
private final class LongOrthant( protected val underlying: DistanceMeasure[ Long, ThreeDim ], protected val idx: Int )
extends OrthantLike[ Long ] with LongImpl
+ private sealed trait ExceptOrthantLike[ @specialized( Long ) M ]
+ extends DistanceMeasure[ M, ThreeDim ] {
+ protected def underlying: DistanceMeasure[ M, ThreeDim ]
+ protected def idx: Int
+
+ private val right = (idx & 1) != 0
+ private val bottom = (idx & 2) != 0
+ private val back = (idx & 4) != 0
+
+ override def toString = underlying.toString + ".exceptQuadrant(" + idx + ")"
+
+ def distance( a: PointLike, b: PointLike ) : M = {
+ if( (if( right ) b.x <= a.x else b.x >= a.x) ||
+ (if( bottom ) b.y <= a.y else b.y >= a.y) ||
+ (if( back ) b.z <= a.z else b.z >= a.z) ) {
+
+ underlying.distance( a, b )
+ } else maxValue
+ }
+
+ def minDistance( p: PointLike, q: HyperCube ) : M = {
+ val qe = q.extent
+ val qem1 = qe - 1
+
+ if( (if( right ) (q.cx - qe) <= p.x else (q.cx + qem1) >= p.x) ||
+ (if( bottom ) (q.cy - qe) <= p.y else (q.cy + qem1) >= p.y) ||
+ (if( back ) (q.cz - qe) <= p.z else (q.cz + qem1) >= p.z) ) {
+
+ underlying.minDistance( p, q )
+ } else maxValue
+ }
+
+ def maxDistance( p: PointLike, q: HyperCube ) : M = {
+ val qe = q.extent
+ val qem1 = qe - 1
+
+ if( (if( right ) (q.cx + qem1) <= p.x else (q.cx - qe) >= p.x) ||
+ (if( bottom ) (q.cy + qem1) <= p.y else (q.cy - qe) >= p.y) ||
+ (if( back ) (q.cz + qem1) <= p.z else (q.cz - qe) >= p.z) ) {
+
+ underlying.maxDistance( p, q )
+ } else maxValue
+ }
+ }
+
+ private final class SqrExceptOrthant( protected val underlying: DistanceMeasure[ BigInt, ThreeDim ], protected val idx: Int )
+ extends OrthantLike[ BigInt ] with SqrImpl
+
+ private final class LongExceptOrthant( protected val underlying: DistanceMeasure[ Long, ThreeDim ], protected val idx: Int )
+ extends OrthantLike[ Long ] with LongImpl
+
private object ChebyshevXY extends ChebyshevXYLike {
override def toString = "IntDistanceMeasure3D.chebyshevXY"
protected def apply( dx: Long, dy: Long ) : Long = math.max( dx, dy )
@@ -270,6 +323,10 @@ object IntDistanceMeasure3D {
require( idx >= 0 && idx < 8, "Orthant index out of range (" + idx + ")" )
new SqrOrthant( this, idx )
}
+ final def exceptOrthant( idx: Int ) : MS = {
+ require( idx >= 0 && idx < 8, "Orthant index out of range (" + idx + ")" )
+ new SqrExceptOrthant( this, idx )
+ }
}
private sealed trait LongImpl extends Impl[ Long ] {
@@ -287,5 +344,9 @@ object IntDistanceMeasure3D {
require( idx >= 0 && idx < 8, "Orthant index out of range (" + idx + ")" )
new LongOrthant( this, idx )
}
+ final def exceptOrthant( idx: Int ) : ML = {
+ require( idx >= 0 && idx < 8, "Orthant index out of range (" + idx + ")" )
+ new LongExceptOrthant( this, idx )
+ }
}
}
@@ -368,11 +368,15 @@ extends JPanel( new BorderLayout() ) {
recalcDistMeasure()
}
- combo( ("All Orthants" +: Seq.tabulate( numOrthants )( i => (i + 1).toString )): _* ) { i =>
- if( i > 0 ) {
- distFilter = _.orthant( i - 1 )
+ combo( ("All Orthants" +: Seq.tabulate( numOrthants << 1 )( i => if( i < numOrthants ) (i + 1).toString else "Except " + (i + 1 - numOrthants) )): _* ) { i =>
+ val j = i - 1
+ val k = j - numOrthants
+ distFilter = if( k >= 0 ) {
+ _.exceptOrthant( k )
+ } else if( j >= 0 ) {
+ _.orthant( j )
} else {
- distFilter = identity
+ identity
}
recalcDistMeasure()
}

0 comments on commit 6cd3740

Please sign in to comment.