DistanceFF extends FunctionBase3 { @Override public NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3) { try { GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryIndex.PRIMARY); GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryIndex.SECONDARY); if (!v3.isIRI()) { throw new ExprEvalException("Not a IRI: " + FmtUtils.stringForNode(v3.asNode())); } double distance = geometry1.distanceEuclidean(geometry2, v3.asNode().getURI()); return NodeValue.makeDouble(distance); } catch (DatatypeFormatException ex) { throw new ExprEvalException(ex.getMessage(), ex); } catch (FactoryException | MismatchedDimensionException | TransformException ex) { throw new ExprEvalException(ex.getMessage() + ": " + FmtUtils.stringForNode(v1.asNode()) + ", " + FmtUtils.stringForNode(v2.asNode()) + ", " + FmtUtils.stringForNode(v3.asNode()), ex); } }  @Override NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3);  }
@Test public void testExec_metres() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.METRE_URL)); DistanceFF instance = new DistanceFF(); double expResult = 30; double result = instance.exec(v1, v2, v3).getDouble(); assertEquals(expResult, result, 0); }
@Test public void testExec_radians() { NodeValue v1 = NodeValue.makeNode("<http: NodeValue v2 = NodeValue.makeNode("<http: NodeValue v3 = NodeValue.makeNode(NodeFactory.createURI(Unit_URI.RADIAN_URL)); DistanceFF instance = new DistanceFF(); double expResult = 7.2822E-6; double result = instance.exec(v1, v2, v3).getDouble(); assertEquals(expResult, result, 0.0001); }