Plane.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. console.log( one );
  12. a = new THREE.Plane( one, 0 );
  13. ok( a.normal.x == 1, "Passed!" );
  14. ok( a.normal.y == 1, "Passed!" );
  15. ok( a.normal.z == 1, "Passed!" );
  16. ok( a.constant == 0, "Passed!" );
  17. a = new THREE.Plane( one, 1 );
  18. ok( a.normal.x == 1, "Passed!" );
  19. ok( a.normal.y == 1, "Passed!" );
  20. ok( a.normal.z == 1, "Passed!" );
  21. ok( a.constant == 1, "Passed!" );
  22. });
  23. test( "copy", function() {
  24. var a = new THREE.Plane( new THREE.Vector3( x, y, z ), w );
  25. var b = new THREE.Plane().copy( a );
  26. ok( b.normal.x == x, "Passed!" );
  27. ok( b.normal.y == y, "Passed!" );
  28. ok( b.normal.z == z, "Passed!" );
  29. ok( b.constant == w, "Passed!" );
  30. // ensure that it is a true copy
  31. a.normal.x = 0;
  32. a.normal.y = -1;
  33. a.normal.z = -2;
  34. a.constant = -3;
  35. ok( b.normal.x == x, "Passed!" );
  36. ok( b.normal.y == y, "Passed!" );
  37. ok( b.normal.z == z, "Passed!" );
  38. ok( b.constant == w, "Passed!" );
  39. });
  40. test( "set", function() {
  41. var a = new THREE.Plane();
  42. ok( a.normal.x == 0, "Passed!" );
  43. ok( a.normal.y == 0, "Passed!" );
  44. ok( a.normal.z == 0, "Passed!" );
  45. ok( a.constant == 0, "Passed!" );
  46. var b = a.clone().set( new THREE.Vector3( x, y, z ), w );
  47. ok( b.normal.x == x, "Passed!" );
  48. ok( b.normal.y == y, "Passed!" );
  49. ok( b.normal.z == z, "Passed!" );
  50. ok( b.constant == w, "Passed!" );
  51. });
  52. test( "setComponents", function() {
  53. var a = new THREE.Plane();
  54. ok( a.normal.x == 0, "Passed!" );
  55. ok( a.normal.y == 0, "Passed!" );
  56. ok( a.normal.z == 0, "Passed!" );
  57. ok( a.constant == 0, "Passed!" );
  58. var b = a.clone().setComponents( x, y, z , w );
  59. ok( b.normal.x == x, "Passed!" );
  60. ok( b.normal.y == y, "Passed!" );
  61. ok( b.normal.z == z, "Passed!" );
  62. ok( b.constant == w, "Passed!" );
  63. });
  64. test( "setFromNormalAndCoplanarPoint", function() {
  65. var a = new THREE.Plane().setFromNormalAndCoplanarPoint( one, zero );
  66. ok( a.normal.equals( one ), "Passed!" );
  67. ok( a.constant == 0, "Passed!" );
  68. });
  69. test( "flip", function() {
  70. var a = new THREE.Plane( one, 0 );
  71. ok( a.normal.equals( one ), "Passed!" );
  72. a.flip();
  73. ok( a.normal.negate().equals( one ), "Passed!" );
  74. });
  75. test( "normalize", function() {
  76. var a = new THREE.Plane( two, 2 );
  77. a.normalize();
  78. ok( a.normal.length() == 1, "Passed!" );
  79. ok( a.normal.equals( one ), "Passed!" );
  80. ok( a.constant == 1, "Passed!" );
  81. });
粤ICP备19079148号