File: testIntersection.js

package info (click to toggle)
jsxgraph 1.5.0%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 24,020 kB
  • sloc: javascript: 76,112; xml: 5,869; java: 1,072; python: 767; php: 181; makefile: 154; cpp: 76; sh: 9
file content (126 lines) | stat: -rw-r--r-- 4,152 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
    Copyright 2008-2023
        Matthias Ehmann,
        Carsten Miller,
        Andreas Walter,
        Alfred Wassermann

    This file is part of JSXGraph.

    JSXGraph is free software dual licensed under the GNU LGPL or MIT License.

    You can redistribute it and/or modify it under the terms of the

      * GNU Lesser General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version
      OR
      * MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT

    JSXGraph is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License and
    the MIT License along with JSXGraph. If not, see <https://www.gnu.org/licenses/>
    and <https://opensource.org/licenses/MIT/>.
 */
describe("Test intersection functions", function () {
    var board;

    document.getElementsByTagName("body")[0].innerHTML =
        '<div id="jxgbox" style="width: 100px; height: 100px;"></div>';
    board = JXG.JSXGraph.initBoard("jxgbox", {
        renderer: "svg",
        axis: false,
        grid: false,
        boundingbox: [-8, 8, 8, -8],
        showCopyright: false,
        showNavigation: false
    });

    it("Intersection curve-circle", function () {
        var A = board.create("point", [0, 4], { visible: false }),
            B = board.create("point", [0, -4], { visible: false }),
            C = board.create("point", [1, 0], { visible: false }),
            el = board.create("ellipse", [A, B, C]),
            circle = board.create(
                "circle",
                [
                    [0, 0],
                    [2, 0]
                ],
                { point2: { color: "red" }, strokeWidth: 1 }
            ),
            ip = [],
            i,
            x = [
                0.9012517057297676, -0.9013129108207755, -0.901326508055587, 0.9012803196247847
            ],
            y = [
                1.7849765412698027, 1.7849451757430674, -1.7849382076228515, -1.7849618776221492
            ];

        for (i = 0; i < 4; i++) {
            ip[i] = board.create("intersection", [circle, el, i], { name: "" + i });
        }

        for (i = 0; i < 4; i++) {
            expect(ip[i].X()).toBeCloseTo(x[i], 5);
            expect(ip[i].Y()).toBeCloseTo(y[i], 5);
        }
    });

    it("Intersection arc-arc", function () {
        var a1 = board.create("arc", [
                [0, 2],
                [-3, 2],
                [3, 2]
            ]),
            a2 = board.create("arc", [
                [0, 0],
                [3, 0],
                [-3, 0]
            ]),
            ip = [],
            i,
            x = [-2.8286194188088936, 2.8286194188088922],
            y = [1.0000000000000016, 0.9999999999999984];

        ip[0] = board.create("intersection", [a1, a2, 0], {
            alwaysIntersect: false
        });
        ip[1] = board.create("intersection", [a1, a2, 1]);
        for (i = 0; i < 2; i++) {
            expect(ip[i].X()).toBeCloseTo(x[i], 14);
            expect(ip[i].Y()).toBeCloseTo(y[i], 14);
        }
    });

    it("Intersection arc-sector", function () {
        var a1 = board.create("sector", [
                [0, 2],
                [-3, 2],
                [3, 2]
            ]),
            a2 = board.create("arc", [
                [0, 0],
                [3, 0],
                [-3, 0]
            ]),
            ip = [],
            i,
            x = [-2.8286194188088936, 2.8286194188088922],
            y = [1.0000000000000016, 0.9999999999999984];

        ip[0] = board.create("intersection", [a1, a2, 0], {
            alwaysIntersect: false
        });
        ip[1] = board.create("intersection", [a1, a2, 1]);
        for (i = 0; i < 2; i++) {
            expect(ip[i].X()).toBeCloseTo(x[i], 14);
            expect(ip[i].Y()).toBeCloseTo(y[i], 14);
        }
    });
});