20 import static ca.uqac.lif.cep.Connector.INPUT;
21 import static ca.uqac.lif.cep.Connector.LEFT;
22 import static ca.uqac.lif.cep.Connector.OUTPUT;
23 import static ca.uqac.lif.cep.Connector.RIGHT;
24 import static ca.uqac.lif.cep.Connector.connect;
25 import ca.uqac.lif.cep.Pullable;
26 import ca.uqac.lif.cep.functions.BinaryFunction;
27 import ca.uqac.lif.cep.functions.ApplyFunction;
28 import ca.uqac.lif.cep.tmf.Fork;
29 import ca.uqac.lif.cep.tmf.QueueSource;
30 import ca.uqac.lif.cep.tmf.Trim;
65 public static class Point
70 public Point(
float x,
float y)
84 public static class Distance
extends BinaryFunction<Point,Point,Float>
88 super(Point.class, Point.class, Float.class);
92 public Float getValue(Point p1, Point p2)
94 return (
float) Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
101 public static void main(String[] args)
104 QueueSource point_source =
new QueueSource(1);
108 Fork fork =
new Fork(2);
109 connect(point_source, OUTPUT, fork, INPUT);
114 ApplyFunction distance_proc =
new ApplyFunction(
new Distance());
115 connect(fork, LEFT, distance_proc, LEFT);
118 Trim trim =
new Trim(1);
119 connect(fork, RIGHT, trim, INPUT);
124 connect(trim, OUTPUT, distance_proc, RIGHT);
127 Pullable p = distance_proc.getPullableOutput(OUTPUT);
128 for (
int i = 0; i < 10; i++)
130 float d = (Float) p.pull();
131 System.out.println(d);
static Object [] getListOfPoints()
Creates a dummy array of points.
Calculate the Euclidean distance of each two successive points in an input trace of (x...