Debian Codegraph @

closure-library/closure/goog/math/line_test.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.math.LineTest');
16 goog.setTestOnly('goog.math.LineTest');
17
18 goog.require('goog.math.Coordinate');
19 goog.require('goog.math.Line');
20 goog.require('goog.testing.jsunit');
21
22 function testEquals() {
23 var input = new goog.math.Line(1, 2, 3, 4);
24
25 assert(input.equals(input));
26 }
27
28 function testClone() {
29 var input = new goog.math.Line(1, 2, 3, 4);
30
31 assertNotEquals('Clone returns a new object', input, input.clone());
32 assertTrue('Contents of clone match original', input.equals(input.clone()));
33 }
34
35 function testGetLength() {
36 var input = new goog.math.Line(0, 0, Math.sqrt(2), Math.sqrt(2));
37 assertRoughlyEquals(input.getSegmentLengthSquared(), 4, 1e-10);
38 assertRoughlyEquals(input.getSegmentLength(), 2, 1e-10);
39 }
40
41 function testGetClosestPoint() {
42 var input = new goog.math.Line(0, 1, 1, 2);
43
44 var point = input.getClosestPoint(0, 3);
45 assertRoughlyEquals(point.x, 1, 1e-10);
46 assertRoughlyEquals(point.y, 2, 1e-10);
47 }
48
49 function testGetClosestSegmentPoint() {
50 var input = new goog.math.Line(0, 1, 2, 3);
51
52 var point = input.getClosestSegmentPoint(4, 4);
53 assertRoughlyEquals(point.x, 2, 1e-10);
54 assertRoughlyEquals(point.y, 3, 1e-10);
55
56 point = input.getClosestSegmentPoint(new goog.math.Coordinate(-1, -10));
57 assertRoughlyEquals(point.x, 0, 1e-10);
58 assertRoughlyEquals(point.y, 1, 1e-10);
59 }