Plane.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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( one, 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( one, 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( one, zero );
  65. ok( a.normal.equals( one ), "Passed!" );
  66. ok( a.constant == 0, "Passed!" );
  67. });
  68. test( "flip", function() {
  69. var a = new THREE.Plane( one, 0 );
  70. ok( a.normal.equals( one ), "Passed!" );
  71. a.flip();
  72. ok( a.normal.negate().equals( one ), "Passed!" );
  73. });
  74. test( "normalize", function() {
  75. var a = new THREE.Plane( two, 2 );
  76. a.normalize();
  77. ok( a.normal.length() == 1, "Passed!" );
  78. ok( a.normal.equals( one ), "Passed!" );
  79. ok( a.constant == 1, "Passed!" );
  80. });