Skip to content

Conversation

@acardona
Copy link
Contributor

Two fixes for ImgMath:

  1. A critical issue, that appears only in scripting languages that fail to find the 2-argument constructor of many functions, and instead use the varargs argument with 2 arguments. The Util.wrapMap was not ready to work with less than 3 arguments.
  2. A minor issue: lack of two static functions in ImgMath: img (to wrap a RandomAccessibleInterval) and number (to wrap a number). These two enable convenient operations like e.g. copying and image into another, and filling an image with a number.

…terval.

Useful for e.g. copying an image into another, or filling an image with a number:

compute(img(source)).into(target)
compute(number(255)).into(target)
…e array

was 2, the first operation was being duplicated.
While this wouldn't be an issue in java, it shows in scripting languages
that fail to use the 2-arg constructor and instead use the varags one.
@tpietzsch
Copy link
Member

Looks fine to me.

I'm not familiar with the context here, but would it make sense to make
VarargsFunction.wrapMap() actual vararg, i.e., take Object... obs instead of Object[] obs?

@acardona
Copy link
Contributor Author

Thanks for looking at the code changes.

The VarargsFunction.wrapMap() has to take an Object[], because it is invoked by ABinaryFunction which itself takes a varargs, which within the code block appears as an Object[]. Otherwise, it would be passing an Object[][]. So all is fine as is, and works correctly, which is the most important.

@tpietzsch tpietzsch merged commit b4b2c1a into master Nov 15, 2018
@tpietzsch
Copy link
Member

👍

@acardona acardona deleted the imgmath-fixes branch November 16, 2018 02:19
@tpietzsch
Copy link
Member

The VarargsFunction.wrapMap() has to take an Object[], because it is invoked by ABinaryFunction which itself takes a varargs, which within the code block appears as an Object[]. Otherwise, it would be passing an Object[][]. So all is fine as is, and works correctly, which is the most important.

Hmm, actually, did you try that???

	private static void ao( final Object... i ) {
		System.out.println( Arrays.toString( i ) );
	}

	private static void bo( final Object... i ) {
		ao( i );
	}

	public static void main( final String[] args ) {
		ao( "x", 1, 2 );
		bo( "x", 1, 2 );
	}

prints

[x, 1, 2]
[x, 1, 2]

So it looks like Object... varargs will not be re-wrapped as Object[][]

@acardona
Copy link
Contributor Author

acardona commented Nov 16, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants