Beta

Triangle in a Square

Description
Loading description...
Mathematics
Geometry
Algorithms
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    Reference solution used for random tests is clearly incorrect:

    TriangleFitsInSquare(415339.9863145371, 459659.20499247574, 666405.0066220658, 479755.37244198116)
    
    Test Failed
      Expected: False
      But was:  True
    

    At a = 415339.9863145371 pointing 88 degrees clockwise and b = 459659.20499247574 pointing ~172.43 degrees counter-clockwise, the third side equals c = 666405.0066220658 and the bounding square is around 471795.42395730014, smaller than 479755.37244198116.

    • Madjosz Avatar

      While the issue is valid, your solution seems to have some rounding problems, e.g.

      Assert.IsTrue(Shape.TriangleFitsInSquare(820147.4907294856, 756913.4956441872, 615778.0534322486, 722099.4062361511));
      
    • Voile Avatar

      Yes, because my solution was just brute-forcing all the angles. It wasn't constant time, and there are always gaps between the angles tried.

  • Voile Avatar

    You can assume that the sides represent always a valid triangle.

    One fixed test case is TriangleFitsInSquare(120.378, 340.873, 220.494, 600.698), which violates the triangle equality (and expects true for some reasons).

    There are also cases like TriangleFitsInSquare(101.419, 184.952, 83.533, 454.56) which is a triangle with 0 area.

  • dlcoe Avatar

    This comment has been hidden.

  • smile67 Avatar

    This comment has been hidden.

    • kaaleppi Avatar

      Hi, thank you. Added them. I tried to be lazy with negative test cases, and immediately someone noticed it :D Designing my first kata, as you see.

      Suggestion marked resolved by kaaleppi 9 years ago
    • smile67 Avatar

      Yes, was easy to see - bad world;-)... So thanks and well done:-)!