Skip to content

Commit 1d24044

Browse files
committed
Make RealRandomAccess a RandomAccess
1 parent 49cf844 commit 1d24044

File tree

2 files changed

+8
-152
lines changed

2 files changed

+8
-152
lines changed

src/main/java/net/imglib2/RealRandomAccess.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @author Stephan Preibisch
4040
* @author Stephan Saalfeld
4141
*/
42-
public interface RealRandomAccess< T > extends RealLocalizable, RealPositionable, Sampler< T >
42+
public interface RealRandomAccess< T > extends RealLocalizable, RealPositionable, RandomAccess<T>
4343
{
4444
// NB: Ideally, we would utilize covariant inheritance to narrow the return
4545
// type of a single copy() method here, rather than needing separate methods
@@ -168,4 +168,9 @@ default T setPositionAndGet( final RealLocalizable position )
168168
return get();
169169
}
170170

171+
@Override
172+
default long getLongPosition(int d) {
173+
return (long) getDoublePosition(d);
174+
}
175+
171176
}

src/main/java/net/imglib2/RealRandomAccessible.java

Lines changed: 2 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -148,161 +148,12 @@ default RealRandomAccessibleView< T > realView()
148148

149149
@Override
150150
default RandomAccess< T > randomAccess() {
151-
return randomAccess(null);
151+
return realRandomAccess();
152152
}
153153

154154
@Override
155155
default RandomAccess< T > randomAccess(final Interval interval) {
156-
final RealRandomAccess<T> sourceAccess = interval == null ? realRandomAccess() : realRandomAccess(interval);
157-
final int n = numDimensions();
158-
return new RandomAccess<T>() {
159-
160-
@Override
161-
public void localize( final int[] position )
162-
{
163-
for ( int d = 0; d < n; ++d )
164-
position[ d ] = ( int ) Math.round( sourceAccess.getDoublePosition( d ) );
165-
}
166-
167-
@Override
168-
public void localize( final long[] position )
169-
{
170-
for ( int d = 0; d < n; ++d )
171-
position[ d ] = Math.round( sourceAccess.getDoublePosition( d ) );
172-
}
173-
174-
@Override
175-
public int getIntPosition( final int d )
176-
{
177-
return ( int ) Math.round( sourceAccess.getDoublePosition( d ) );
178-
}
179-
180-
@Override
181-
public long getLongPosition( final int d )
182-
{
183-
return Math.round( sourceAccess.getDoublePosition( d ) );
184-
}
185-
186-
@Override
187-
public void localize( final float[] position )
188-
{
189-
sourceAccess.localize( position );
190-
}
191-
192-
@Override
193-
public void localize( final double[] position )
194-
{
195-
sourceAccess.localize( position );
196-
}
197-
198-
@Override
199-
public float getFloatPosition( final int d )
200-
{
201-
return sourceAccess.getFloatPosition( d );
202-
}
203-
204-
@Override
205-
public double getDoublePosition( final int d )
206-
{
207-
return sourceAccess.getDoublePosition( d );
208-
}
209-
210-
@Override
211-
public void fwd( final int d )
212-
{
213-
sourceAccess.fwd( d );
214-
}
215-
216-
@Override
217-
public void bck( final int d )
218-
{
219-
sourceAccess.bck( d );
220-
}
221-
222-
@Override
223-
public void move( final int distance, final int d )
224-
{
225-
sourceAccess.move( distance, d );
226-
}
227-
228-
@Override
229-
public void move( final long distance, final int d )
230-
{
231-
sourceAccess.move( distance, d );
232-
}
233-
234-
@Override
235-
public void move( final Localizable localizable )
236-
{
237-
sourceAccess.move( localizable );
238-
}
239-
240-
@Override
241-
public void move( final int[] distance )
242-
{
243-
sourceAccess.move( distance );
244-
}
245-
246-
@Override
247-
public void move( final long[] distance )
248-
{
249-
sourceAccess.move( distance );
250-
}
251-
252-
@Override
253-
public void setPosition( final Localizable localizable )
254-
{
255-
sourceAccess.setPosition( localizable );
256-
}
257-
258-
@Override
259-
public void setPosition( final int[] position )
260-
{
261-
sourceAccess.setPosition( position );
262-
}
263-
264-
@Override
265-
public void setPosition( final long[] position )
266-
{
267-
sourceAccess.setPosition( position );
268-
}
269-
270-
@Override
271-
public void setPosition( final int position, final int d )
272-
{
273-
sourceAccess.setPosition( position, d );
274-
}
275-
276-
@Override
277-
public void setPosition( final long position, final int d )
278-
{
279-
sourceAccess.setPosition( position, d );
280-
}
281-
282-
@Override
283-
public T get()
284-
{
285-
return sourceAccess.get();
286-
}
287-
288-
@Override
289-
public T getType()
290-
{
291-
return sourceAccess.getType();
292-
}
293-
294-
@Override
295-
public RandomAccess<T> copy()
296-
{
297-
return randomAccess();
298-
}
299-
300-
@Override
301-
public int numDimensions()
302-
{
303-
return n;
304-
}
305-
};
156+
return realRandomAccess(interval);
306157
}
307158

308159
/*

0 commit comments

Comments
 (0)