Ad
  • Custom User Avatar

    An identical kata has been approved already, so this one should be unpublished.

  • Default User Avatar

    Thank you! :)

  • Default User Avatar

    Alright, obviously I did not read the test code properly. Good work!

  • Default User Avatar

    I did it using polar coordinate system. Each vertex has increasing angle (from 0 to 2PI-0.02 at last point) and not zero distance from (0,0). So, it can't intersect itself.

  • Default User Avatar

    Ok, but how do you ensure that your randomly created polygon meets these criteria?

  • Default User Avatar

    "Your task is to determine the area of a polygon that does not intersect itself and has no holes. You are given the coordinates of its vertices in the double[n][2] array. Coodinates will describe a polygon in counterclockwise order. The input is always valid."

    Wiki: In geometry, a simple polygon is a polygon that does not intersect itself and has no holes.

  • Default User Avatar

    I don't see, how you can fix 2. and 3. with the description ;-)

  • Default User Avatar

    1 So, is it not enough? If algorithm can calculate single random test what is the point for more tests?
    2 & 3. It is poor task description, I think. My fault, thank you.
    4 Done.

  • Default User Avatar

    Removed the test, thank you.

  • Default User Avatar
    1. You only have one "random" test with 50 random values.
    2. What about self-intersecting polygons? How is the area calculated then? Consider e.g. [[0,0],[1,1],[1,0],[0,1]]. The standard approach will lead to an area of 0 here, but one would say that the area is 0.5.
    3. What about overlapping polygons? How is the area calculated then? Consider e.g. [[0,0],[0,1],[1,1],[0,1],[0,0],[0,1],[1,1],[0,1]]. The standard approach will lead to an area of 2 here, but one would have no idea what the area of this polygon is since it depends on your definition of "interior".
    4. As Voile stated, the null test case should either be mentioned or removed. You also do not pass invalid arrays to the method, where the inner dimension is unequal to 2. So either you only give valid inputs or you demand checking on validity.
  • Custom User Avatar

    Null handling is not specified anywhere and only appears in the tests, and frankly it's pointless since it doesn't add anything to the task.