-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDefaultGCD.java
More file actions
35 lines (25 loc) · 792 Bytes
/
DefaultGCD.java
File metadata and controls
35 lines (25 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bar;
import net.imagej.ops.AbstractOp;
import org.scijava.ItemIO;
import org.scijava.plugin.Attr;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
@Plugin(type = BAR.GCD.class, name = BAR.GCD.NAME, attrs = { @Attr(name = "aliases", value = BAR.GCD.ALIASES) })
public class DefaultGCD extends AbstractOp implements BAR.GCD {
// -- Inputs --
// We want our GCD function to have two inputs. These are declared using @Parameter notation
@Parameter
private double a;
@Parameter
private double b;
// -- Outputs --
@Parameter(type = ItemIO.OUTPUT)
private double result;
@Override
public void run() {
result = computeGCD(a, b);
}
private double computeGCD(final double p1, final double p2) {
return p2 == 0 ? p1 : computeGCD(p2, p1%p2);
}
}