/
EuclideanDistance.java
48 lines (40 loc) · 1.39 KB
/
EuclideanDistance.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
BeepBeep, an event stream processor
Copyright (C) 2008-2018 Sylvain Hallé
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package customprocessors;
import ca.uqac.lif.cep.*;
import java.util.Queue;
public class EuclideanDistance extends SynchronousProcessor
{
public static final EuclideanDistance instance =
new EuclideanDistance();
EuclideanDistance()
{
super(2, 1);
}
public boolean compute(Object[] inputs, Queue<Object[]> outputs)
{
Point p1 = (Point) inputs[0];
Point p2 = (Point) inputs[1];
double distance = Math.sqrt(Math.pow(p2.x - p1.x, 2)
+ Math.pow(p2.y - p1.y, 2));
outputs.add(new Object[] {distance});
return true;
}
@Override
public Processor duplicate(boolean with_state)
{
return this;
}
}