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.

  • Custom User Avatar

    Could somebody subtitle what the defining property of a curve "like this" is? I don't feel like reverse engineering it.

  • 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?

  • Default User Avatar

    Again, I think the data structure add unecessary difficulty.

    I feel like you should have three kata: point in poly (4kyu) bezier curve (5 kyu) and this easy kata (5/6 kyu) wich would use both previous kata. Here you chose to give an introduction to point in polygon but not bezier curve. So this kata is a bit misleading as one can think it is about points in a polygon but it is about bezier curves.

  • Default User Avatar

    Nice kata. I don't get the point of adding lineto and moveto in the polygon description. I think an array of points would suffice.

  • Default User Avatar

    OK, I was doing the latter, and wondering why it was recieveing the error, and then throwing another error. I should probably rewrite this. Thanks!

  • Default User Avatar

    Hi wfleet, the Test.expectError call has worked for me in the past, so if I may ask, did you pass it a function that invokes pointInPoly or did you pass pointInPoly or its result directly? That is, was it like this:

    Test.expectError(function() {                          // does what you want
      pointInPoly(thisPolygon, thisPoint);
    });
    

    or like this:

    Test.expectError(pointInPoly(thisPolygon, thisPoint)); // probably won't do what you want