Plane.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @author bhouston / http://exocortex.com
  3. */
  4. module( "Plane" );
  5. test( "constructor", function() {
  6. var a = new THREE.Plane();
  7. ok( a.normal.x == 0, "Passed!" );
  8. ok( a.normal.y == 0, "Passed!" );
  9. ok( a.normal.z == 0, "Passed!" );
  10. ok( a.constant == 0, "Passed!" );
  11. a = new THREE.Plane( one3, 0 );
  12. ok( a.normal.x == 1, "Passed!" );
  13. ok( a.normal.y == 1, "Passed!" );
  14. ok( a.normal.z == 1, "Passed!" );
  15. ok( a.constant == 0, "Passed!" );
  16. a = new THREE.Plane( one3, 1 );
  17. ok( a.normal.x == 1, "Passed!" );
  18. ok( a.normal.y == 1, "Passed!" );
  19. ok( a.normal.z == 1, "Passed!" );
  20. ok( a.constant == 1, "Passed!" );
  21. });
  22. test( "copy", function() {
  23. var a = new THREE.Plane( new THREE.Vector3( x, y, z ), w );
  24. var b = new THREE.Plane().copy( a );
  25. ok( b.normal.x == x, "Passed!" );
  26. ok( b.normal.y == y, "Passed!" );
  27. ok( b.normal.z == z, "Passed!" );
  28. ok( b.constant == w, "Passed!" );
  29. // ensure that it is a true copy
  30. a.normal.x = 0;
  31. a.normal.y = -1;
  32. a.normal.z = -2;
  33. a.constant = -3;
  34. ok( b.normal.x == x, "Passed!" );
  35. ok( b.normal.y == y, "Passed!" );
  36. ok( b.normal.z == z, "Passed!" );
  37. ok( b.constant == w, "Passed!" );
  38. });
  39. test( "set", function() {
  40. var a = new THREE.Plane();
  41. ok( a.normal.x == 0, "Passed!" );
  42. ok( a.normal.y == 0, "Passed!" );
  43. ok( a.normal.z == 0, "Passed!" );
  44. ok( a.constant == 0, "Passed!" );
  45. var b = a.clone().set( new THREE.Vector3( x, y, z ), w );
  46. ok( b.normal.x == x, "Passed!" );
  47. ok( b.normal.y == y, "Passed!" );
  48. ok( b.normal.z == z, "Passed!" );
  49. ok( b.constant == w, "Passed!" );
  50. });
  51. test( "setComponents", function() {
  52. var a = new THREE.Plane();
  53. ok( a.normal.x == 0, "Passed!" );
  54. ok( a.normal.y == 0, "Passed!" );
  55. ok( a.normal.z == 0, "Passed!" );
  56. ok( a.constant == 0, "Passed!" );
  57. var b = a.clone().setComponents( x, y, z , w );
  58. ok( b.normal.x == x, "Passed!" );
  59. ok( b.normal.y == y, "Passed!" );
  60. ok( b.normal.z == z, "Passed!" );
  61. ok( b.constant == w, "Passed!" );
  62. });
  63. test( "setFromNormalAndCoplanarPoint", function() {
  64. var a = new THREE.Plane().setFromNormalAndCoplanarPoint( one3, zero3 );
  65. ok( a.normal.equals( one3 ), "Passed!" );
  66. ok( a.constant == 0, "Passed!" );
  67. });
  68. test( "normalize", function() {
  69. var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), 2 );
  70. a.normalize();
  71. ok( a.normal.length() == 1, "Passed!" );
  72. ok( a.normal.equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" );
  73. ok( a.constant == 1, "Passed!" );
  74. });