Hi guys, I know I am stupid and I can't figure out is this java code can be translate into Sail Expression?

int count = 0, i = 0;

do
{
  int next = (i + 1) % n;
  if (doIntersect(polygon[i], polygon[next], p, extreme))
     {
  if (orientation(polygon[i], p, polygon[next]) == 0)
  return onSegment(polygon[i], p, polygon[next]);

  count++;
     }
  i = next;
} while (i != 0);

return (count & 1) == 1 ? true : false;

-------------------------------------------------------------------------------

The function doIntersect and function orientation is the function will return you boolean value, and polygon[] is a list that stored point object.

I try to translate this code into Sail Expression but I really don't know how to write do while logic in Appian, and I can't use plug-in java function. 

I know I already ask some similiar function about java code transalte into Sail Expression...Can anyone please help me?

  Discussion posts and replies are publicly visible

Parents
  • I think it might help to think less about translating Java to SAIL and more about what the core problem is and how to solve it. SAIL is a functional language which is very different than Java. It looks like the problem you are trying to solve is trying to figure out if any lines intersect. There are SAIL functions such as reduce() which you can utilize but you can also use a forLoop as before to go through each item in the list and compare items to those before and after. Looking at the docs https://docs.appian.com/suite/help/18.4/fnc_looping_a_foreach.html a!forEach() has values such as fv!index to know the index of the list as well as fv!isLast to know when you're comparing something with the last item in the list. For loops can definitely be a performance issue, but depending on the problem there may be ways to solve it without using a loop such as using set functions like wherecontains(). The more you think of the problem in Java, the harder it will be to solve in SAIL.

Reply
  • I think it might help to think less about translating Java to SAIL and more about what the core problem is and how to solve it. SAIL is a functional language which is very different than Java. It looks like the problem you are trying to solve is trying to figure out if any lines intersect. There are SAIL functions such as reduce() which you can utilize but you can also use a forLoop as before to go through each item in the list and compare items to those before and after. Looking at the docs https://docs.appian.com/suite/help/18.4/fnc_looping_a_foreach.html a!forEach() has values such as fv!index to know the index of the list as well as fv!isLast to know when you're comparing something with the last item in the list. For loops can definitely be a performance issue, but depending on the problem there may be ways to solve it without using a loop such as using set functions like wherecontains(). The more you think of the problem in Java, the harder it will be to solve in SAIL.

Children
No Data