Ad
  • Custom User Avatar

    Needs more tests, and random tests.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Images are broken, wrong(wikipedia was never a commercial) links.
    [I'll fix them, soon]

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    (This last because the Test.expectError() call does not seem to handle errors as stated.)

    This is actually because you didn't read the docs properly and see that Test.expectError expects a function argument. You have to wrap the call into a function.

  • Custom User Avatar

    Input validation does not add to the problem. Please just don't.

  • Custom User Avatar

    Polygons with points in clockwise order are not tested.

  • Default User Avatar

    As with http://www.codewars.com/kata/point-in-polygon-1/

    Polygons like these were not tested:

    var thisPolygon = {'polygon' : [
    		{'moveto' : {'x' : -5, 'y' : -5}},
    		{'lineto' : {'x' : 5, 'y' : -5}},
    		{'lineto' : {'x' : 0, 'y' : 0}},
    		{'lineto' : {'x' : 4, 'y' : 4}},
    		{'lineto' : {'x' : 3, 'y' : 1}},
    		{'lineto' : {'x' : 1, 'y' : 0}},
    		{'lineto' : {'x' : 5, 'y' : 0}},
    		{'lineto' : {'x' : 5, 'y' : 5}},
    		{'lineto' : {'x' : -5, 'y' : 5}},
    		{'lineto' : {'x' : -5, 'y' : -5}},
    ]};
    
    thisPoint = {'x' : 1.01, 'y' : 1};
    Test.assertEquals(pointInPoly(thisPolygon, thisPoint), false, 'Point is outside the polygon');
    
    thisPoint = {'x' : 0.99, 'y' : 1};
    Test.assertEquals(pointInPoly(thisPolygon, thisPoint), true, 'Point is inside the polygon');
    

    And I believe many solutions will fail on convex polygons like that.

  • Default User Avatar
    (This last because the Test.expectError() call does not seem to handle errors as stated.)

    Test.expectError takes a function argument, which it calls and expects an error to occur. You're probably writing something like:

    Test.expectError(somefn(baddata)); // error occurs outside of Test.expectError so it can't handle it
    

    rather than,

    Test.expectError(function () {
      somefn(baddata); // error doesn't occur until Test.expectError calls this function, so it catches it
    });
    

    Note that the first way (the way that didn't work) is equivalent to this:

    var result = somefn(baddata); // error occurs here
    Test.expectError(result); // of course it can't get to this line, it's already halted due to the error
    
  • Default User Avatar

    What's the point of saying a polygon can contain curves, if it can't really contain curves?