1 /*
  2     Copyright 2008-2024
  3         Matthias Ehmann,
  4         Michael Gerhaeuser,
  5         Carsten Miller,
  6         Bianca Valentin,
  7         Alfred Wassermann,
  8         Peter Wilfahrt
  9 
 10     This file is part of JSXGraph.
 11 
 12     JSXGraph is free software dual licensed under the GNU LGPL or MIT License.
 13 
 14     You can redistribute it and/or modify it under the terms of the
 15 
 16       * GNU Lesser General Public License as published by
 17         the Free Software Foundation, either version 3 of the License, or
 18         (at your option) any later version
 19       OR
 20       * MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT
 21 
 22     JSXGraph is distributed in the hope that it will be useful,
 23     but WITHOUT ANY WARRANTY; without even the implied warranty of
 24     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 25     GNU Lesser General Public License for more details.
 26 
 27     You should have received a copy of the GNU Lesser General Public License and
 28     the MIT License along with JSXGraph. If not, see <https://www.gnu.org/licenses/>
 29     and <https://opensource.org/licenses/MIT/>.
 30  */
 31 
 32 /*global JXG: true, define: true*/
 33 /*jslint nomen: true, plusplus: true*/
 34 
 35 import JXG from "../jxg.js";
 36 import Geometry from "../math/geometry.js";
 37 import Mat from "../math/math.js";
 38 import Statistics from "../math/statistics.js";
 39 import Coords from "../base/coords.js";
 40 import Const from "../base/constants.js";
 41 import Type from "../utils/type.js";
 42 
 43 /**
 44  * @class A circular sector is a subarea of the area enclosed by a circle. It is enclosed by two radii and an arc.
 45  * @pseudo
 46  * @name Sector
 47  * @augments JXG.Curve
 48  * @constructor
 49  * @type JXG.Curve
 50  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
 51  *
 52  * First possibility of input parameters are:
 53  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 A sector is defined by three points: The sector's center <tt>p1</tt>,
 54  * a second point <tt>p2</tt> defining the radius and a third point <tt>p3</tt> defining the angle of the sector. The
 55  * Sector is always drawn counter clockwise from <tt>p2</tt> to <tt>p3</tt>.
 56  * <p>
 57  * In this case, the sector will have an arc as sub-object.
 58  * <p>
 59  * Second possibility of input parameters are:
 60  * @param {JXG.Line_JXG.Line_array,number_array,number_number,function} line, line2, coords1 or direction1, coords2 or direction2, radius The sector is defined by two lines.
 61  * The two legs which define the sector are given by two coordinates arrays which are project initially two the two lines or by two directions (+/- 1).
 62  * The last parameter is the radius of the sector.
 63  * <p>In this case, the sector will <b>not</b> have an arc as sub-object.
 64  *
 65  * @example
 66  * // Create a sector out of three free points
 67  * var p1 = board.create('point', [1.5, 5.0]),
 68  *     p2 = board.create('point', [1.0, 0.5]),
 69  *     p3 = board.create('point', [5.0, 3.0]),
 70  *
 71  *     a = board.create('sector', [p1, p2, p3]);
 72  * </pre><div class="jxgbox" id="JXG49f59123-f013-4681-bfd9-338b89893156" style="width: 300px; height: 300px;"></div>
 73  * <script type="text/javascript">
 74  * (function () {
 75  *   var board = JXG.JSXGraph.initBoard('JXG49f59123-f013-4681-bfd9-338b89893156', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
 76  *     p1 = board.create('point', [1.5, 5.0]),
 77  *     p2 = board.create('point', [1.0, 0.5]),
 78  *     p3 = board.create('point', [5.0, 3.0]),
 79  *
 80  *     a = board.create('sector', [p1, p2, p3]);
 81  * })();
 82  * </script><pre>
 83  *
 84  * @example
 85  * // Create a sector out of two lines, two directions and a radius
 86  * var p1 = board.create('point', [-1, 4]),
 87  *  p2 = board.create('point', [4, 1]),
 88  *  q1 = board.create('point', [-2, -3]),
 89  *  q2 = board.create('point', [4,3]),
 90  *
 91  *  li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
 92  *  li2 = board.create('line', [q1,q2], {lastArrow:true}),
 93  *
 94  *  sec1 = board.create('sector', [li1, li2, [5.5, 0], [4, 3], 3]),
 95  *  sec2 = board.create('sector', [li1, li2, 1, -1, 4]);
 96  *
 97  * </pre><div class="jxgbox" id="JXGbb9e2809-9895-4ff1-adfa-c9c71d50aa53" style="width: 300px; height: 300px;"></div>
 98  * <script type="text/javascript">
 99  * (function () {
100  *   var board = JXG.JSXGraph.initBoard('JXGbb9e2809-9895-4ff1-adfa-c9c71d50aa53', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
101  *     p1 = board.create('point', [-1, 4]),
102  *     p2 = board.create('point', [4, 1]),
103  *     q1 = board.create('point', [-2, -3]),
104  *     q2 = board.create('point', [4,3]),
105  *
106  *     li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
107  *     li2 = board.create('line', [q1,q2], {lastArrow:true}),
108  *
109  *     sec1 = board.create('sector', [li1, li2, [5.5, 0], [4, 3], 3]),
110  *     sec2 = board.create('sector', [li1, li2, 1, -1, 4]);
111  * })();
112  * </script><pre>
113  *
114  * @example
115  * var t = board.create('transform', [2, 1.5], {type: 'scale'});
116  * var s1 = board.create('sector', [[-3.5,-3], [-3.5, -2], [-3.5,-4]], {
117  *                 anglePoint: {visible:true}, center: {visible: true}, radiusPoint: {visible: true},
118  *                 fillColor: 'yellow', strokeColor: 'black'});
119  * var s2 = board.create('curve', [s1, t], {fillColor: 'yellow', strokeColor: 'black'});
120  *
121  * </pre><div id="JXG2e70ee14-6339-11e8-9fb9-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div>
122  * <script type="text/javascript">
123  *     (function() {
124  *         var board = JXG.JSXGraph.initBoard('JXG2e70ee14-6339-11e8-9fb9-901b0e1b8723',
125  *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
126  *     var t = board.create('transform', [2, 1.5], {type: 'scale'});
127  *     var s1 = board.create('sector', [[-3.5,-3], [-3.5, -2], [-3.5,-4]], {
128  *                     anglePoint: {visible:true}, center: {visible: true}, radiusPoint: {visible: true},
129  *                     fillColor: 'yellow', strokeColor: 'black'});
130  *     var s2 = board.create('curve', [s1, t], {fillColor: 'yellow', strokeColor: 'black'});
131  *
132  *     })();
133  *
134  * </script><pre>
135  *
136  * @example
137  * var A = board.create('point', [3, -2]),
138  *     B = board.create('point', [-2, -2]),
139  *     C = board.create('point', [0, 4]);
140  *
141  * var angle = board.create('sector', [B, A, C], {
142  *         strokeWidth: 0,
143  *         arc: {
144  *         	visible: true,
145  *         	strokeWidth: 3,
146  *           lastArrow: {size: 4},
147  *           firstArrow: {size: 4}
148  *         }
149  *       });
150  * //angle.arc.setAttribute({firstArrow: false});
151  * angle.arc.setAttribute({lastArrow: false});
152  *
153  * </pre><div id="JXGca37b99e-1510-49fa-ac9e-efd60e956104" class="jxgbox" style="width: 300px; height: 300px;"></div>
154  * <script type="text/javascript">
155  *     (function() {
156  *         var board = JXG.JSXGraph.initBoard('JXGca37b99e-1510-49fa-ac9e-efd60e956104',
157  *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
158  *     var A = board.create('point', [3, -2]),
159  *         B = board.create('point', [-2, -2]),
160  *         C = board.create('point', [0, 4]);
161  *
162  *     var angle = board.create('sector', [B, A, C], {
163  *             strokeWidth: 0,
164  *             arc: {
165  *             	visible: true,
166  *             	strokeWidth: 3,
167  *               lastArrow: {size: 4},
168  *               firstArrow: {size: 4}
169  *             }
170  *           });
171  *     //angle.arc.setAttribute({firstArrow: false});
172  *     angle.arc.setAttribute({lastArrow: false});
173  *
174  *     })();
175  *
176  * </script><pre>
177  *
178  *
179  */
180 JXG.createSector = function (board, parents, attributes) {
181     var el,
182         attr,
183         i,
184         type = "invalid",
185         s,
186         v,
187         attrPoints = ["center", "radiusPoint", "anglePoint"],
188         points;
189 
190     // Three points?
191     if (
192         parents[0].elementClass === Const.OBJECT_CLASS_LINE &&
193         parents[1].elementClass === Const.OBJECT_CLASS_LINE &&
194         (Type.isArray(parents[2]) || Type.isNumber(parents[2])) &&
195         (Type.isArray(parents[3]) || Type.isNumber(parents[3])) &&
196         (Type.isNumber(parents[4]) || Type.isFunction(parents[4]) || Type.isString(parents[4]))
197     ) {
198         type = "2lines";
199     } else {
200         points = Type.providePoints(board, parents, attributes, "sector", attrPoints);
201         if (points === false) {
202             throw new Error(
203                 "JSXGraph: Can't create Sector with parent types '" +
204                     typeof parents[0] +
205                     "' and '" +
206                     typeof parents[1] +
207                     "' and '" +
208                     typeof parents[2] +
209                     "'."
210             );
211         }
212         type = "3points";
213     }
214 
215     attr = Type.copyAttributes(attributes, board.options, "sector");
216     el = board.create("curve", [[0], [0]], attr);
217     el.type = Const.OBJECT_TYPE_SECTOR;
218     el.elType = "sector";
219 
220     /**
221      * Sets radius if the attribute `radius` has value 'auto'.
222      * Sets a radius between 20 and 50 points, depending on the distance
223      * between the center and the radius point.
224      * This function is used in {@link Angle}.
225      *
226      * @name autoRadius
227      * @memberof Sector.prototype
228      * @function
229      * @returns {Number} returns a radius value in user coordinates.
230      * @private
231      */
232     el.autoRadius = function () {
233         var r1 = 20 / el.board.unitX, // 20px
234             r2 = Infinity,
235             r3 = 50 / el.board.unitX; // 50px
236 
237         if (Type.isPoint(el.center)) {
238             // This does not work for 2-lines sectors / angles
239             r2 = el.center.Dist(el.point2) * 0.3333;
240         }
241 
242         return Math.max(r1, Math.min(r2, r3));
243     };
244 
245     if (type === "2lines") {
246         /**
247          * @ignore
248          */
249         el.Radius = function () {
250             var r = Type.evaluate(parents[4]);
251             if (r === "auto") {
252                 return this.autoRadius();
253             }
254             return r;
255         };
256 
257         el.line1 = board.select(parents[0]);
258         el.line2 = board.select(parents[1]);
259 
260         el.line1.addChild(el);
261         el.line2.addChild(el);
262         el.setParents(parents);
263 
264         el.point1 = { visProp: {} };
265         el.point2 = { visProp: {} };
266         el.point3 = { visProp: {} };
267 
268         /* Intersection point */
269         s = Geometry.meetLineLine(el.line1.stdform, el.line2.stdform, 0, board);
270 
271         if (Type.isArray(parents[2])) {
272             /* project p1 to l1 */
273             if (parents[2].length === 2) {
274                 parents[2] = [1].concat(parents[2]);
275             }
276             /*
277                 v = [0, el.line1.stdform[1], el.line1.stdform[2]];
278                 v = Mat.crossProduct(v, parents[2]);
279                 v = Geometry.meetLineLine(v, el.line1.stdform, 0, board);
280                 */
281             v = Geometry.projectPointToLine(
282                 { coords: { usrCoords: parents[2] } },
283                 el.line1,
284                 board
285             );
286             v = Statistics.subtract(v.usrCoords, s.usrCoords);
287             el.direction1 =
288                 Mat.innerProduct(v, [0, el.line1.stdform[2], -el.line1.stdform[1]], 3) >= 0
289                     ? +1
290                     : -1;
291         } else {
292             el.direction1 = parents[2] >= 0 ? 1 : -1;
293         }
294 
295         if (Type.isArray(parents[3])) {
296             /* project p2 to l2 */
297             if (parents[3].length === 2) {
298                 parents[3] = [1].concat(parents[3]);
299             }
300             /*
301                 v = [0, el.line2.stdform[1], el.line2.stdform[2]];
302                 v = Mat.crossProduct(v, parents[3]);
303                 v = Geometry.meetLineLine(v, el.line2.stdform, 0, board);
304                 */
305             v = Geometry.projectPointToLine(
306                 { coords: { usrCoords: parents[3] } },
307                 el.line2,
308                 board
309             );
310             v = Statistics.subtract(v.usrCoords, s.usrCoords);
311             el.direction2 =
312                 Mat.innerProduct(v, [0, el.line2.stdform[2], -el.line2.stdform[1]], 3) >= 0
313                     ? +1
314                     : -1;
315         } else {
316             el.direction2 = parents[3] >= 0 ? 1 : -1;
317         }
318 
319         el.methodMap = JXG.deepCopy(el.methodMap, {
320             arc: "arc",
321             center: "center",
322             line1: "line1",
323             line2: "line2"
324         });
325 
326         /**
327          * @class
328          * @ignore
329          */
330         el.updateDataArray = function () {
331             var r,
332                 l1,
333                 l2,
334                 A = [0, 0, 0],
335                 B = [0, 0, 0],
336                 C = [0, 0, 0],
337                 ar;
338 
339             l1 = this.line1;
340             l2 = this.line2;
341 
342             // Intersection point of the lines
343             B = Mat.crossProduct(l1.stdform, l2.stdform);
344 
345             if (Math.abs(B[0]) > Mat.eps * Mat.eps) {
346                 B[1] /= B[0];
347                 B[2] /= B[0];
348                 B[0] /= B[0];
349             }
350             // First point
351             r = this.direction1 * this.Radius();
352             A = Statistics.add(B, [0, r * l1.stdform[2], -r * l1.stdform[1]]);
353 
354             // Second point
355             r = this.direction2 * this.Radius();
356             C = Statistics.add(B, [0, r * l2.stdform[2], -r * l2.stdform[1]]);
357 
358             this.point2.coords = new Coords(Const.COORDS_BY_USER, A, el.board);
359             this.point1.coords = new Coords(Const.COORDS_BY_USER, B, el.board);
360             this.point3.coords = new Coords(Const.COORDS_BY_USER, C, el.board);
361 
362             if (
363                 Math.abs(A[0]) < Mat.eps ||
364                 Math.abs(B[0]) < Mat.eps ||
365                 Math.abs(C[0]) < Mat.eps
366             ) {
367                 this.dataX = [NaN];
368                 this.dataY = [NaN];
369                 return;
370             }
371 
372             ar = Geometry.bezierArc(A, B, C, true, 1);
373 
374             this.dataX = ar[0];
375             this.dataY = ar[1];
376 
377             this.bezierDegree = 3;
378         };
379 
380         // Arc does not work yet, since point1, point2 and point3 are
381         // virtual points.
382         //
383         // attr = Type.copyAttributes(attributes, board.options, "arc");
384         // attr = Type.copyAttributes(attr, board.options, "sector", "arc");
385         // attr.withLabel = false;
386         // attr.name += "_arc";
387         // // el.arc = board.create("arc", [el.point1, el.point2, el.point3], attr);
388         // // The arc's radius is always the radius of sector.
389         // // This is important for angles.
390         // el.updateDataArray();
391         // el.arc = board.create("arc", [
392         //     function() {
393         //         return el.point1.coords.usrCoords;
394         //     }, // Center
395         //     function() {
396         //         var d = el.point2.coords.distance(Const.COORDS_BY_USER, el.point1.coords);
397         //         if (d === 0) {
398         //             return [el.point1.coords.usrCoords[1], el.point1.coords.usrCoords[2]];
399         //         }
400         //         return [
401         //             el.point1.coords.usrCoords[1] + el.Radius() * (el.point2.coords.usrCoords[1] - el.point1.coords.usrCoords[1]) / d,
402         //             el.point1.coords.usrCoords[2] + el.Radius() * (el.point2.coords.usrCoords[2] - el.point1.coords.usrCoords[2]) / d
403         //         ];
404         //     },
405         //     function() {
406         //         return el.point3.coords.usrCoords;
407         //     }, // Center
408         // ], attr);
409         // el.addChild(el.arc);
410 
411         // end '2lines'
412     } else if (type === "3points") {
413         /**
414          * Midpoint of the sector.
415          * @memberOf Sector.prototype
416          * @name point1
417          * @type JXG.Point
418          */
419         el.point1 = points[0];
420 
421         /**
422          * This point together with {@link Sector#point1} defines the radius.
423          * @memberOf Sector.prototype
424          * @name point2
425          * @type JXG.Point
426          */
427         el.point2 = points[1];
428 
429         /**
430          * Defines the sector's angle.
431          * @memberOf Sector.prototype
432          * @name point3
433          * @type JXG.Point
434          */
435         el.point3 = points[2];
436 
437         /* Add arc as child to defining points */
438         for (i = 0; i < 3; i++) {
439             if (Type.exists(points[i]._is_new)) {
440                 el.addChild(points[i]);
441                 delete points[i]._is_new;
442             } else {
443                 points[i].addChild(el);
444             }
445         }
446 
447         // useDirection is necessary for circumCircleSectors
448         el.useDirection = attributes.usedirection; // this makes the attribute immutable
449         el.setParents(points);
450 
451         /**
452          * Defines the sectors orientation in case of circumCircleSectors.
453          * @memberOf Sector.prototype
454          * @name point4
455          * @type JXG.Point
456          */
457         if (Type.exists(points[3])) {
458             el.point4 = points[3];
459             el.point4.addChild(el);
460         }
461 
462         el.methodMap = JXG.deepCopy(el.methodMap, {
463             arc: "arc",
464             center: "center",
465             radiuspoint: "radiuspoint",
466             anglepoint: "anglepoint"
467         });
468 
469         /**
470          * @class
471          * @ignore
472          */
473         el.updateDataArray = function () {
474             var ar, det,
475                 p0c, p1c, p2c,
476                 A = this.point2,
477                 B = this.point1,
478                 C = this.point3,
479                 phi,
480                 sgn = 1,
481                 vp_s = this.evalVisProp('selection');
482 
483             if (!A.isReal || !B.isReal || !C.isReal) {
484                 this.dataX = [NaN];
485                 this.dataY = [NaN];
486                 return;
487             }
488 
489             phi = Geometry.rad(A, B, C);
490             if ((vp_s === "minor" && phi > Math.PI) || (vp_s === "major" && phi < Math.PI)) {
491                 sgn = -1;
492             }
493 
494             // This is true for circumCircleSectors. In that case there is
495             // a fourth parent element: [midpoint, point1, point3, point2]
496             if (this.useDirection && Type.exists(this.point4)) {
497                 p0c = this.point2.coords.usrCoords;
498                 p1c = this.point4.coords.usrCoords;
499                 p2c = this.point3.coords.usrCoords;
500                 det =
501                     (p0c[1] - p2c[1]) * (p0c[2] - p1c[2]) -
502                     (p0c[2] - p2c[2]) * (p0c[1] - p1c[1]);
503 
504                 if (det >= 0.0) {
505                     C = this.point2;
506                     A = this.point3;
507                 }
508             }
509 
510             A = A.coords.usrCoords;
511             B = B.coords.usrCoords;
512             C = C.coords.usrCoords;
513 
514             ar = Geometry.bezierArc(A, B, C, true, sgn);
515 
516             this.dataX = ar[0];
517             this.dataY = ar[1];
518             this.bezierDegree = 3;
519         };
520 
521         /**
522          * Returns the radius of the sector.
523          * @memberOf Sector.prototype
524          * @name Radius
525          * @function
526          * @returns {Number} The distance between {@link Sector#point1} and {@link Sector#point2}.
527          */
528         el.Radius = function () {
529             return this.point2.Dist(this.point1);
530         };
531     } // end '3points'
532 
533     el.center = el.point1;
534     el.radiuspoint = el.point2;
535     el.anglepoint = el.point3;
536 
537     attr = Type.copyAttributes(attributes, board.options, "arc");
538     attr = Type.copyAttributes(attr, board.options, "sector", "arc");
539     attr.withLabel = false;
540     // Minor or major arc:
541     attr.selection = el.visProp.selection;
542     attr.name += "_arc";
543 
544     if (type === "2lines") {
545         el.updateDataArray();
546         el.arc = board.create("arc", [
547             function() {
548                 return el.point1.coords.usrCoords;
549             }, // Center
550             function() {
551                 var d = el.point2.coords.distance(Const.COORDS_BY_USER, el.point1.coords);
552                 if (d === 0) {
553                     return [el.point1.coords.usrCoords[1], el.point1.coords.usrCoords[2]];
554                 }
555                 return [
556                     el.point1.coords.usrCoords[1] + el.Radius() * (el.point2.coords.usrCoords[1] - el.point1.coords.usrCoords[1]) / d,
557                     el.point1.coords.usrCoords[2] + el.Radius() * (el.point2.coords.usrCoords[2] - el.point1.coords.usrCoords[2]) / d
558                 ];
559             },
560             function() {
561                 return el.point3.coords.usrCoords;
562             } // Center
563         ], attr);
564     } else {
565         // The arc's radius is always the radius of sector.
566         // This is important for angles.
567         el.arc = board.create("arc", [
568             el.point1, // Center
569             function() {
570                 var d = el.point2.Dist(el.point1);
571                 if (d === 0) {
572                     return [el.point1.X(), el.point1.Y()];
573                 }
574                 return [
575                     el.point1.X() + el.Radius() * (el.point2.X() - el.point1.X()) / d,
576                     el.point1.Y() + el.Radius() * (el.point2.Y() - el.point1.Y()) / d
577                 ];
578             },
579             el.point3
580         ], attr);
581     }
582     el.addChild(el.arc);
583 
584     // Default hasPoint method. Documented in geometry element
585     el.hasPointCurve = function (x, y) {
586         var angle,
587             alpha,
588             beta,
589             prec,
590             type,
591             checkPoint = new Coords(Const.COORDS_BY_SCREEN, [x, y], this.board),
592             r = this.Radius(),
593             dist = this.center.coords.distance(Const.COORDS_BY_USER, checkPoint),
594             has,
595             vp_s = this.evalVisProp('selection');
596 
597         if (Type.isObject(this.evalVisProp('precision'))) {
598             type = this.board._inputDevice;
599             prec = this.evalVisProp('precision.' + type);
600         } else {
601             // 'inherit'
602             prec = this.board.options.precision.hasPoint;
603         }
604         prec /= Math.min(Math.abs(this.board.unitX), Math.abs(this.board.unitY));
605         has = Math.abs(dist - r) < prec;
606         if (has) {
607             angle = Geometry.rad(this.point2, this.center, checkPoint.usrCoords.slice(1));
608             alpha = 0;
609             beta = Geometry.rad(this.point2, this.center, this.point3);
610 
611             if ((vp_s === "minor" && beta > Math.PI) || (vp_s === "major" && beta < Math.PI)) {
612                 alpha = beta;
613                 beta = 2 * Math.PI;
614             }
615 
616             if (angle < alpha || angle > beta) {
617                 has = false;
618             }
619         }
620 
621         return has;
622     };
623 
624     /**
625      * Checks whether (x,y) is within the area defined by the sector.
626      * @memberOf Sector.prototype
627      * @name hasPointSector
628      * @function
629      * @param {Number} x Coordinate in x direction, screen coordinates.
630      * @param {Number} y Coordinate in y direction, screen coordinates.
631      * @returns {Boolean} True if (x,y) is within the sector defined by the arc, False otherwise.
632      */
633     el.hasPointSector = function (x, y) {
634         var angle,
635             checkPoint = new Coords(Const.COORDS_BY_SCREEN, [x, y], this.board),
636             r = this.Radius(),
637             dist = this.point1.coords.distance(Const.COORDS_BY_USER, checkPoint),
638             alpha,
639             beta,
640             has = dist < r,
641             vp_s = this.evalVisProp('selection');
642 
643         if (has) {
644             angle = Geometry.rad(this.radiuspoint, this.center, checkPoint.usrCoords.slice(1));
645             alpha = 0.0;
646             beta = Geometry.rad(this.radiuspoint, this.center, this.anglepoint);
647 
648             if ((vp_s === "minor" && beta > Math.PI) || (vp_s === "major" && beta < Math.PI)) {
649                 alpha = beta;
650                 beta = 2 * Math.PI;
651             }
652             //if (angle > Geometry.rad(this.point2, this.point1, this.point3)) {
653             if (angle < alpha || angle > beta) {
654                 has = false;
655             }
656         }
657         return has;
658     };
659 
660     el.hasPoint = function (x, y) {
661         if (
662             this.evalVisProp('highlightonsector') ||
663             this.evalVisProp('hasinnerpoints')
664         ) {
665             return this.hasPointSector(x, y);
666         }
667 
668         return this.hasPointCurve(x, y);
669     };
670 
671     // documented in GeometryElement
672     el.getTextAnchor = function () {
673         return this.point1.coords;
674     };
675 
676     // documented in GeometryElement
677     // this method is very similar to arc.getLabelAnchor()
678     // there are some additions in the arc version though, mainly concerning
679     // "major" and "minor" arcs. but maybe these methods can be merged.
680     /**
681      * @class
682      * @ignore
683      */
684     el.getLabelAnchor = function () {
685         var coords,
686             vec,
687             vecx,
688             vecy,
689             len,
690             angle = Geometry.rad(this.point2, this.point1, this.point3),
691             dx = 13 / this.board.unitX,
692             dy = 13 / this.board.unitY,
693             p2c = this.point2.coords.usrCoords,
694             pmc = this.point1.coords.usrCoords,
695             bxminusax = p2c[1] - pmc[1],
696             byminusay = p2c[2] - pmc[2],
697             vp_s = this.evalVisProp('selection'),
698             l_vp = this.label ? this.label.visProp : this.visProp.label;
699 
700         // If this is uncommented, the angle label can not be dragged
701         //if (Type.exists(this.label)) {
702         //    this.label.relativeCoords = new Coords(Const.COORDS_BY_SCREEN, [0, 0], this.board);
703         //}
704 
705         if ((vp_s === "minor" && angle > Math.PI) || (vp_s === "major" && angle < Math.PI)) {
706             angle = -(2 * Math.PI - angle);
707         }
708 
709         coords = new Coords(
710             Const.COORDS_BY_USER,
711             [
712                 pmc[1] + Math.cos(angle * 0.5) * bxminusax - Math.sin(angle * 0.5) * byminusay,
713                 pmc[2] + Math.sin(angle * 0.5) * bxminusax + Math.cos(angle * 0.5) * byminusay
714             ],
715             this.board
716         );
717 
718         vecx = coords.usrCoords[1] - pmc[1];
719         vecy = coords.usrCoords[2] - pmc[2];
720 
721         len = Mat.hypot(vecx, vecy);
722         vecx = (vecx * (len + dx)) / len;
723         vecy = (vecy * (len + dy)) / len;
724         vec = [pmc[1] + vecx, pmc[2] + vecy];
725 
726         l_vp.position = Geometry.calcLabelQuadrant(Geometry.rad([1, 0], [0, 0], vec));
727 
728         return new Coords(Const.COORDS_BY_USER, vec, this.board);
729     };
730 
731     /**
732      * Overwrite the Radius method of the sector.
733      * Used in {@link GeometryElement#setAttribute}.
734      * @memberOf Sector.prototype
735      * @name setRadius
736      * @param {Number|Function} value New radius.
737      * @function
738      */
739     el.setRadius = function (val) {
740         var res,
741             e = Type.evaluate(val);
742 
743         if (val === 'auto' || e === 'auto') {
744             res = 'auto';
745         } else if (Type.isNumber(val)) {
746             res = 'number';
747         } else if (Type.isFunction(val) && !Type.isString(e)) {
748             res = 'function';
749         } else {
750             res = 'undefined';
751         }
752         if (res !== 'undefined') {
753             this.visProp.radius = val;
754         }
755 
756         /**
757          * @ignore
758          */
759         el.Radius = function () {
760             var r = Type.evaluate(val);
761             if (r === "auto") {
762                 return this.autoRadius();
763             }
764             return r;
765         };
766     };
767 
768     /**
769      * @deprecated
770      * @ignore
771      */
772     el.getRadius = function () {
773         JXG.deprecated("Sector.getRadius()", "Sector.Radius()");
774         return this.Radius();
775     };
776 
777     /**
778      * Length of the sector's arc or the angle in various units, see {@link Arc#Value}.
779      * @memberOf Sector.prototype
780      * @name Value
781      * @function
782      * @param {String} unit
783      * @returns {Number} The arc length or the angle value in various units.
784      * @see Arc#Value
785      */
786     el.Value = function(unit) {
787         return this.arc.Value(unit);
788     };
789 
790     /**
791      * Arc length.
792      * @memberOf Sector.prototype
793      * @name L
794      * @returns {Number} Length of the sector's arc.
795      * @function
796      * @see Arc#L
797      */
798     el.L = function() {
799         return this.arc.L();
800     };
801 
802     /**
803      * Area of the sector.
804      * @memberOf Sector.prototype
805      * @name Area
806      * @function
807      * @returns {Number} The area of the sector.
808      */
809     el.Area = function () {
810         var r = this.Radius();
811 
812         return 0.5 * r * r * this.Value('radians');
813     };
814 
815     /**
816      * Sector perimeter, i.e. arc length plus 2 * radius.
817      * @memberOf Sector.prototype
818      * @name Perimeter
819      * @function
820      * @returns {Number} Perimeter of sector.
821      */
822     el.Perimeter = function () {
823         return this.L() + 2 * this.Radius();
824     };
825 
826     if (type === "3points") {
827         /**
828          * Moves the sector by the difference of two coordinates.
829          * @memberOf Sector.prototype
830          * @name setPositionDirectly
831          * @function
832          * @param {Number} method The type of coordinates used here. Possible values are {@link JXG.COORDS_BY_USER} and {@link JXG.COORDS_BY_SCREEN}.
833          * @param {Array} coords coordinates in screen/user units
834          * @param {Array} oldcoords previous coordinates in screen/user units
835          * @returns {JXG.Curve} this element
836          * @private
837          */
838         el.setPositionDirectly = function (method, coords, oldcoords) {
839             var dc, t,
840                 c = new Coords(method, coords, this.board),
841                 oldc = new Coords(method, oldcoords, this.board);
842 
843             if (!el.point1.draggable() || !el.point2.draggable() || !el.point3.draggable()) {
844                 return this;
845             }
846 
847             dc = Statistics.subtract(c.usrCoords, oldc.usrCoords);
848             t = this.board.create("transform", dc.slice(1), { type: "translate" });
849             t.applyOnce([el.point1, el.point2, el.point3]);
850 
851             return this;
852         };
853     }
854 
855     el.methodMap = JXG.deepCopy(el.methodMap, {
856         radius: "Radius",
857         Radius: "Radius",
858         getRadius: "Radius",
859         setRadius: "setRadius",
860         Value: "Value",
861         L: "L",
862         Area: "Area",
863         Perimeter: "Perimeter"
864     });
865 
866     return el;
867 };
868 
869 JXG.registerElement("sector", JXG.createSector);
870 
871 /**
872  * @class A circumcircle sector is different from a {@link Sector} mostly in the way the parent elements are interpreted.
873  * At first, the circum center is determined from the three given points. Then the sector is drawn from <tt>p1</tt> through
874  * <tt>p2</tt> to <tt>p3</tt>.
875  * @pseudo
876  * @name CircumcircleSector
877  * @augments Sector
878  * @constructor
879  * @type Sector
880  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
881  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 A circumcircle sector is defined by the circumcircle which is determined
882  * by these three given points. The circumcircle sector is always drawn from <tt>p1</tt> through <tt>p2</tt> to <tt>p3</tt>.
883  * @example
884  * // Create an arc out of three free points
885  * var p1 = board.create('point', [1.5, 5.0]),
886  *     p2 = board.create('point', [1.0, 0.5]),
887  *     p3 = board.create('point', [5.0, 3.0]),
888  *
889  *     a = board.create('circumcirclesector', [p1, p2, p3]);
890  * </pre><div class="jxgbox" id="JXG695cf0d6-6d7a-4d4d-bfc9-34c6aa28cd04" style="width: 300px; height: 300px;"></div>
891  * <script type="text/javascript">
892  * (function () {
893  *   var board = JXG.JSXGraph.initBoard('JXG695cf0d6-6d7a-4d4d-bfc9-34c6aa28cd04', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
894  *     p1 = board.create('point', [1.5, 5.0]),
895  *     p2 = board.create('point', [1.0, 0.5]),
896  *     p3 = board.create('point', [5.0, 3.0]),
897  *
898  *     a = board.create('circumcirclesector', [p1, p2, p3]);
899  * })();
900  * </script><pre>
901  */
902 JXG.createCircumcircleSector = function (board, parents, attributes) {
903     var el, mp, attr, points;
904 
905     points = Type.providePoints(board, parents, attributes, "point");
906     if (points === false) {
907         throw new Error(
908             "JSXGraph: Can't create circumcircle sector with parent types '" +
909                 typeof parents[0] +
910                 "' and '" +
911                 typeof parents[1] +
912                 "' and '" +
913                 typeof parents[2] +
914                 "'."
915         );
916     }
917 
918     mp = board.create("circumcenter", points.slice(0, 3), attr);
919     mp.dump = false;
920 
921     attr = Type.copyAttributes(attributes, board.options, "circumcirclesector");
922     el = board.create("sector", [mp, points[0], points[2], points[1]], attr);
923 
924     el.elType = "circumcirclesector";
925     el.setParents(points);
926 
927     /**
928      * Center of the circumcirclesector
929      * @memberOf CircumcircleSector.prototype
930      * @name center
931      * @type Circumcenter
932      */
933     el.center = mp;
934     el.subs = {
935         center: mp
936     };
937 
938     return el;
939 };
940 
941 JXG.registerElement("circumcirclesector", JXG.createCircumcircleSector);
942 
943 /**
944  * @class A minor sector is a sector of a circle having measure less than or equal to
945  * 180 degrees (pi radians). It is defined by a center, one point that
946  * defines the radius, and a third point that defines the angle of the sector.
947  * @pseudo
948  * @name MinorSector
949  * @augments Curve
950  * @constructor
951  * @type JXG.Curve
952  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
953  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Minor sector is a sector of a circle around p1 having measure less than or equal to
954  * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
955  * @example
956  * // Create sector out of three free points
957  * var p1 = board.create('point', [2.0, 2.0]);
958  * var p2 = board.create('point', [1.0, 0.5]);
959  * var p3 = board.create('point', [3.5, 1.0]);
960  *
961  * var a = board.create('minorsector', [p1, p2, p3]);
962  * </pre><div class="jxgbox" id="JXGaf27ddcc-265f-428f-90dd-d31ace945800" style="width: 300px; height: 300px;"></div>
963  * <script type="text/javascript">
964  * (function () {
965  *   var board = JXG.JSXGraph.initBoard('JXGaf27ddcc-265f-428f-90dd-d31ace945800', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
966  *       p1 = board.create('point', [2.0, 2.0]),
967  *       p2 = board.create('point', [1.0, 0.5]),
968  *       p3 = board.create('point', [3.5, 1.0]),
969  *
970  *       a = board.create('minorsector', [p1, p2, p3]);
971  * })();
972  * </script><pre>
973  *
974  * @example
975  * var A = board.create('point', [3, -2]),
976  *     B = board.create('point', [-2, -2]),
977  *     C = board.create('point', [0, 4]);
978  *
979  * var angle = board.create('minorsector', [B, A, C], {
980  *         strokeWidth: 0,
981  *         arc: {
982  *         	visible: true,
983  *         	strokeWidth: 3,
984  *           lastArrow: {size: 4},
985  *           firstArrow: {size: 4}
986  *         }
987  *       });
988  * //angle.arc.setAttribute({firstArrow: false});
989  * angle.arc.setAttribute({lastArrow: false});
990  *
991  *
992  * </pre><div id="JXGdddf3c8f-4b0c-4268-8171-8fcd30e71f60" class="jxgbox" style="width: 300px; height: 300px;"></div>
993  * <script type="text/javascript">
994  *     (function() {
995  *         var board = JXG.JSXGraph.initBoard('JXGdddf3c8f-4b0c-4268-8171-8fcd30e71f60',
996  *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
997  *     var A = board.create('point', [3, -2]),
998  *         B = board.create('point', [-2, -2]),
999  *         C = board.create('point', [0, 4]);
1000  *
1001  *     var angle = board.create('minorsector', [B, A, C], {
1002  *             strokeWidth: 0,
1003  *             arc: {
1004  *             	visible: true,
1005  *             	strokeWidth: 3,
1006  *               lastArrow: {size: 4},
1007  *               firstArrow: {size: 4}
1008  *             }
1009  *           });
1010  *     //angle.arc.setAttribute({firstArrow: false});
1011  *     angle.arc.setAttribute({lastArrow: false});
1012  *
1013  *
1014  *     })();
1015  *
1016  * </script><pre>
1017  *
1018  */
1019 JXG.createMinorSector = function (board, parents, attributes) {
1020     attributes.selection = "minor";
1021     return JXG.createSector(board, parents, attributes);
1022 };
1023 
1024 JXG.registerElement("minorsector", JXG.createMinorSector);
1025 
1026 /**
1027  * @class A major sector is a sector of a circle having measure greater than or equal to
1028  * 180 degrees (pi radians). It is defined by a center, one point that
1029  * defines the radius, and a third point that defines the angle of the sector.
1030  * @pseudo
1031  * @name MajorSector
1032  * @augments Curve
1033  * @constructor
1034  * @type JXG.Curve
1035  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
1036  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Major sector is a sector of a circle around p1 having measure greater than or equal to
1037  * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
1038  * @example
1039  * // Create an arc out of three free points
1040  * var p1 = board.create('point', [2.0, 2.0]);
1041  * var p2 = board.create('point', [1.0, 0.5]);
1042  * var p3 = board.create('point', [3.5, 1.0]);
1043  *
1044  * var a = board.create('majorsector', [p1, p2, p3]);
1045  * </pre><div class="jxgbox" id="JXG83c6561f-7561-4047-b98d-036248a00932" style="width: 300px; height: 300px;"></div>
1046  * <script type="text/javascript">
1047  * (function () {
1048  *   var board = JXG.JSXGraph.initBoard('JXG83c6561f-7561-4047-b98d-036248a00932', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1049  *       p1 = board.create('point', [2.0, 2.0]),
1050  *       p2 = board.create('point', [1.0, 0.5]),
1051  *       p3 = board.create('point', [3.5, 1.0]),
1052  *
1053  *       a = board.create('majorsector', [p1, p2, p3]);
1054  * })();
1055  * </script><pre>
1056  */
1057 JXG.createMajorSector = function (board, parents, attributes) {
1058     attributes.selection = "major";
1059     return JXG.createSector(board, parents, attributes);
1060 };
1061 
1062 JXG.registerElement("majorsector", JXG.createMajorSector);
1063 
1064 /**
1065  * @class The angle element is used to denote an angle defined by three points. Visually it is just a {@link Sector}
1066  * element with a radius not defined by the parent elements but by an attribute <tt>radius</tt>. As opposed to the sector,
1067  * an angle has two angle points and no radius point.
1068  * Sector is displayed if type=="sector".
1069  * If type=="square", instead of a sector a parallelogram is displayed.
1070  * In case of type=="auto", a square is displayed if the angle is near orthogonal.
1071  * <p>
1072  * If no name is provided the angle label is automatically set to a lower greek letter. If no label should be displayed use
1073  * the attribute <tt>withLabel:false</tt>.
1074  *
1075  * @pseudo
1076  * @name Angle
1077  * @augments Sector
1078  * @constructor
1079  * @type Sector
1080  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
1081  * First possibility of input parameters are:
1082  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 An angle is always drawn counterclockwise from <tt>p1</tt> to
1083  * <tt>p3</tt> around <tt>p2</tt>.
1084  *
1085  * Second possibility of input parameters are:
1086  * @param {JXG.Line_JXG.Line_array|number_array|number} line, line2, coords1 or direction1, coords2 or direction2, radius The angle is defined by two lines.
1087  * The two legs which define the angle are given by two coordinate arrays.
1088  * The points given by these coordinate arrays are projected initially (i.e. only once) onto the two lines.
1089  * The other possibility is to supply directions (+/- 1).
1090  *
1091  * @example
1092  * // Create an angle out of three free points
1093  * var p1 = board.create('point', [5.0, 3.0]),
1094  *     p2 = board.create('point', [1.0, 0.5]),
1095  *     p3 = board.create('point', [1.5, 5.0]),
1096  *
1097  *     a = board.create('angle', [p1, p2, p3]),
1098  *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1099  * </pre><div class="jxgbox" id="JXGa34151f9-bb26-480a-8d6e-9b8cbf789ae5" style="width: 300px; height: 300px;"></div>
1100  * <script type="text/javascript">
1101  * (function () {
1102  *   var board = JXG.JSXGraph.initBoard('JXGa34151f9-bb26-480a-8d6e-9b8cbf789ae5', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1103  *     p1 = board.create('point', [5.0, 3.0]),
1104  *     p2 = board.create('point', [1.0, 0.5]),
1105  *     p3 = board.create('point', [1.5, 5.0]),
1106  *
1107  *     a = board.create('angle', [p1, p2, p3]),
1108  *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1109  * })();
1110  * </script><pre>
1111  *
1112  * @example
1113  * // Create an angle out of two lines and two directions
1114  * var p1 = board.create('point', [-1, 4]),
1115  *  p2 = board.create('point', [4, 1]),
1116  *  q1 = board.create('point', [-2, -3]),
1117  *  q2 = board.create('point', [4,3]),
1118  *
1119  *  li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
1120  *  li2 = board.create('line', [q1,q2], {lastArrow:true}),
1121  *
1122  *  a1 = board.create('angle', [li1, li2, [5.5, 0], [4, 3]], { radius:1 }),
1123  *  a2 = board.create('angle', [li1, li2, 1, -1], { radius:2 });
1124  *
1125  *
1126  * </pre><div class="jxgbox" id="JXG3a667ddd-63dc-4594-b5f1-afac969b371f" style="width: 300px; height: 300px;"></div>
1127  * <script type="text/javascript">
1128  * (function () {
1129  *   var board = JXG.JSXGraph.initBoard('JXG3a667ddd-63dc-4594-b5f1-afac969b371f', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1130  *     p1 = board.create('point', [-1, 4]),
1131  *     p2 = board.create('point', [4, 1]),
1132  *     q1 = board.create('point', [-2, -3]),
1133  *     q2 = board.create('point', [4,3]),
1134  *
1135  *     li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
1136  *     li2 = board.create('line', [q1,q2], {lastArrow:true}),
1137  *
1138  *     a1 = board.create('angle', [li1, li2, [5.5, 0], [4, 3]], { radius:1 }),
1139  *     a2 = board.create('angle', [li1, li2, 1, -1], { radius:2 });
1140  * })();
1141  * </script><pre>
1142  *
1143  *
1144  * @example
1145  * // Display the angle value instead of the name
1146  * var p1 = board.create('point', [0,2]);
1147  * var p2 = board.create('point', [0,0]);
1148  * var p3 = board.create('point', [-2,0.2]);
1149  *
1150  * var a = board.create('angle', [p1, p2, p3], {
1151  * 	 radius: 1,
1152  *   name: function() {
1153  *   	return JXG.Math.Geometry.trueAngle(p1, p2, p3).toFixed(1) + '°';
1154  *   }});
1155  *
1156  * </pre><div id="JXGc813f601-8dd3-4030-9892-25c6d8671512" class="jxgbox" style="width: 300px; height: 300px;"></div>
1157  * <script type="text/javascript">
1158  *     (function() {
1159  *         var board = JXG.JSXGraph.initBoard('JXGc813f601-8dd3-4030-9892-25c6d8671512',
1160  *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
1161  *
1162  *     var p1 = board.create('point', [0,2]);
1163  *     var p2 = board.create('point', [0,0]);
1164  *     var p3 = board.create('point', [-2,0.2]);
1165  *
1166  *     var a = board.create('angle', [p1, p2, p3], {
1167  *     	radius: 1,
1168  *       name: function() {
1169  *       	return JXG.Math.Geometry.trueAngle(p1, p2, p3).toFixed(1) + '°';
1170  *       }});
1171  *
1172  *     })();
1173  *
1174  * </script><pre>
1175  *
1176  *
1177  * @example
1178  * // Apply a transformation to an angle.
1179  * var t = board.create('transform', [2, 1.5], {type: 'scale'});
1180  * var an1 = board.create('angle', [[-4,3.9], [-3, 4], [-3, 3]]);
1181  * var an2 = board.create('curve', [an1, t]);
1182  *
1183  * </pre><div id="JXG4c8d9ed8-6339-11e8-9fb9-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div>
1184  * <script type="text/javascript">
1185  *     (function() {
1186  *         var board = JXG.JSXGraph.initBoard('JXG4c8d9ed8-6339-11e8-9fb9-901b0e1b8723',
1187  *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
1188  *     var t = board.create('transform', [2, 1.5], {type: 'scale'});
1189  *     var an1 = board.create('angle', [[-4,3.9], [-3, 4], [-3, 3]]);
1190  *     var an2 = board.create('curve', [an1, t]);
1191  *
1192  *     })();
1193  *
1194  * </script><pre>
1195  *
1196  */
1197 JXG.createAngle = function (board, parents, attributes) {
1198     var el,
1199         radius, attr, attrsub,
1200         i, points,
1201         type = "invalid";
1202 
1203     // Two lines or three points?
1204     if (
1205         parents[0].elementClass === Const.OBJECT_CLASS_LINE &&
1206         parents[1].elementClass === Const.OBJECT_CLASS_LINE &&
1207         (Type.isArray(parents[2]) || Type.isNumber(parents[2])) &&
1208         (Type.isArray(parents[3]) || Type.isNumber(parents[3]))
1209     ) {
1210         type = "2lines";
1211     } else {
1212         attr = {
1213             name: ''
1214         };
1215         points = Type.providePoints(board, parents, attr, "point");
1216         if (points === false) {
1217             throw new Error(
1218                 "JSXGraph: Can't create angle with parent types '" +
1219                     typeof parents[0] +
1220                     "' and '" +
1221                     typeof parents[1] +
1222                     "' and '" +
1223                     typeof parents[2] +
1224                     "'."
1225             );
1226         }
1227         type = "3points";
1228     }
1229 
1230     attr = Type.copyAttributes(attributes, board.options, "angle");
1231 
1232     //  If empty, create a new name
1233     if (!Type.exists(attr.name) /*|| attr.name === ""*/) {
1234         attr.name = board.generateName({ type: Const.OBJECT_TYPE_ANGLE });
1235     }
1236 
1237     if (Type.exists(attr.radius)) {
1238         radius = attr.radius;
1239     } else {
1240         radius = 0;
1241     }
1242 
1243     board.suspendUpdate(); // Necessary for immediate availability of radius.
1244     if (type === "2lines") {
1245         parents.push(radius);
1246         el = board.create("sector", parents, attr);
1247         /**
1248          * @class
1249          * @ignore
1250          */
1251         el.updateDataArraySector = el.updateDataArray;
1252 
1253         // TODO
1254         /**
1255          * @class
1256          * @ignore
1257          */
1258         el.setAngle = function (val) {};
1259         /**
1260          * @class
1261          * @ignore
1262          */
1263         el.free = function (val) {};
1264     } else {
1265         el = board.create("sector", [points[1], points[0], points[2]], attr);
1266         el.arc.visProp.priv = true;
1267 
1268         /**
1269          * The point defining the radius of the angle element.
1270          * Alias for {@link Sector#radiuspoint}.
1271          * @type JXG.Point
1272          * @name point
1273          * @memberOf Angle.prototype
1274          *
1275          */
1276         el.point = el.point2 = el.radiuspoint = points[0];
1277 
1278         /**
1279          * Helper point for angles of type 'square'.
1280          * @type JXG.Point
1281          * @name pointsquare
1282          * @memberOf Angle.prototype
1283          */
1284         el.pointsquare = el.point3 = el.anglepoint = points[2];
1285 
1286         /**
1287          * @ignore
1288          */
1289         el.Radius = function () {
1290             // Set the angle radius, also @see @link Sector#autoRadius
1291             var r = Type.evaluate(radius);
1292             if (r === "auto") {
1293                 return el.autoRadius();
1294             }
1295             return r;
1296         };
1297 
1298         /**
1299          * @class
1300          * @ignore
1301          */
1302         el.updateDataArraySector = function () {
1303             var A = this.point2,
1304                 B = this.point1,
1305                 C = this.point3,
1306                 r = this.Radius(),
1307                 d = B.Dist(A),
1308                 ar,
1309                 phi,
1310                 sgn = 1,
1311                 vp_s = this.evalVisProp('selection');
1312 
1313             phi = Geometry.rad(A, B, C);
1314             if ((vp_s === "minor" && phi > Math.PI) || (vp_s === "major" && phi < Math.PI)) {
1315                 sgn = -1;
1316             }
1317 
1318             A = A.coords.usrCoords;
1319             B = B.coords.usrCoords;
1320             C = C.coords.usrCoords;
1321 
1322             A = [1, B[1] + ((A[1] - B[1]) * r) / d, B[2] + ((A[2] - B[2]) * r) / d];
1323             C = [1, B[1] + ((C[1] - B[1]) * r) / d, B[2] + ((C[2] - B[2]) * r) / d];
1324 
1325             ar = Geometry.bezierArc(A, B, C, true, sgn);
1326 
1327             this.dataX = ar[0];
1328             this.dataY = ar[1];
1329             this.bezierDegree = 3;
1330         };
1331 
1332         /**
1333          * Set an angle to a prescribed value given in radians.
1334          * This is only possible if the third point of the angle, i.e.
1335          * the anglepoint is a free point.
1336          * Removing the constraint again is done by calling "angle.free()".
1337          *
1338          * Changing the angle requires to call the method "free()":
1339          *
1340          * <pre>
1341          * angle.setAngle(Math.PI / 6);
1342          * // ...
1343          * angle.free().setAngle(Math.PI / 4);
1344          * </pre>
1345          *
1346          * @name setAngle
1347          * @memberof Angle.prototype
1348          * @function
1349          * @param {Number|Function} val Number or Function which returns the size of the angle in Radians
1350          * @returns {Object} Pointer to the angle element..
1351          * @see Angle#free
1352          *
1353          * @example
1354          * var p1, p2, p3, c, a, s;
1355          *
1356          * p1 = board.create('point',[0,0]);
1357          * p2 = board.create('point',[5,0]);
1358          * p3 = board.create('point',[0,5]);
1359          *
1360          * c1 = board.create('circle',[p1, p2]);
1361          *
1362          * a = board.create('angle',[p2, p1, p3], {radius:3});
1363          *
1364          * a.setAngle(function() {
1365          *     return Math.PI / 3;
1366          * });
1367          * board.update();
1368          *
1369          * </pre><div id="JXG987c-394f-11e6-af4a-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div>
1370          * <script type="text/javascript">
1371          *     (function() {
1372          *         var board = JXG.JSXGraph.initBoard('JXG987c-394f-11e6-af4a-901b0e1b8723',
1373          *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
1374          *     var p1, p2, p3, c, a, s;
1375          *
1376          *     p1 = board.create('point',[0,0]);
1377          *     p2 = board.create('point',[5,0]);
1378          *     p3 = board.create('point',[0,5]);
1379          *
1380          *     c1 = board.create('circle',[p1, p2]);
1381          *
1382          *     a = board.create('angle',[p2, p1, p3], {radius: 3});
1383          *
1384          *     a.setAngle(function() {
1385          *         return Math.PI / 3;
1386          *     });
1387          *     board.update();
1388          *
1389          *     })();
1390          *
1391          * </script><pre>
1392          *
1393          * @example
1394          * var p1, p2, p3, c, a, s;
1395          *
1396          * p1 = board.create('point',[0,0]);
1397          * p2 = board.create('point',[5,0]);
1398          * p3 = board.create('point',[0,5]);
1399          *
1400          * c1 = board.create('circle',[p1, p2]);
1401          *
1402          * a = board.create('angle',[p2, p1, p3], {radius:3});
1403          * s = board.create('slider',[[-2,1], [2,1], [0, Math.PI*0.5, 2*Math.PI]]);
1404          *
1405          * a.setAngle(function() {
1406          *     return s.Value();
1407          * });
1408          * board.update();
1409          *
1410          * </pre><div id="JXG99957b1c-394f-11e6-af4a-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div>
1411          * <script type="text/javascript">
1412          *     (function() {
1413          *         var board = JXG.JSXGraph.initBoard('JXG99957b1c-394f-11e6-af4a-901b0e1b8723',
1414          *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
1415          *     var p1, p2, p3, c, a, s;
1416          *
1417          *     p1 = board.create('point',[0,0]);
1418          *     p2 = board.create('point',[5,0]);
1419          *     p3 = board.create('point',[0,5]);
1420          *
1421          *     c1 = board.create('circle',[p1, p2]);
1422          *
1423          *     a = board.create('angle',[p2, p1, p3], {radius: 3});
1424          *     s = board.create('slider',[[-2,1], [2,1], [0, Math.PI*0.5, 2*Math.PI]]);
1425          *
1426          *     a.setAngle(function() {
1427          *         return s.Value();
1428          *     });
1429          *     board.update();
1430          *
1431          *     })();
1432          *
1433          * </script><pre>
1434          *
1435          */
1436         el.setAngle = function (val) {
1437             var t1, t2,
1438                 val2,
1439                 p = this.anglepoint,
1440                 q = this.radiuspoint;
1441 
1442             if (p.draggable()) {
1443                 t1 = this.board.create("transform", [val, this.center], {
1444                     type: "rotate"
1445                 });
1446                 p.addTransform(q, t1);
1447                 // Immediately apply the transformation.
1448                 // This prevents that jumping elements can be watched.
1449                 t1.update();
1450                 p.moveTo(Mat.matVecMult(t1.matrix, q.coords.usrCoords));
1451 
1452                 if (Type.isFunction(val)) {
1453                     /**
1454                      * @ignore
1455                      */
1456                     val2 = function () {
1457                         return Math.PI * 2 - val();
1458                     };
1459                 } else {
1460                     /**
1461                      * @ignore
1462                      */
1463                     val2 = function () {
1464                         return Math.PI * 2 - val;
1465                     };
1466                 }
1467                 t2 = this.board.create("transform", [val2, this.center], {
1468                     type: "rotate"
1469                 });
1470                 p.coords.on("update", function () {
1471                     t2.update();
1472                     q.moveTo(Mat.matVecMult(t2.matrix, p.coords.usrCoords));
1473                 });
1474 
1475                 p.setParents(q);
1476 
1477                 this.hasFixedAngle = true;
1478             }
1479             return this;
1480         };
1481 
1482         /**
1483          * Frees an angle from a prescribed value. This is only relevant if the angle size has been set by
1484          * "setAngle()" previously. The anglepoint is set to a free point.
1485          * @name free
1486          * @function
1487          * @memberof Angle.prototype
1488          * @returns {Object} Pointer to the angle element..
1489          * @see Angle#setAngle
1490          */
1491         el.free = function () {
1492             var p = this.anglepoint;
1493 
1494             if (p.transformations.length > 0) {
1495                 p.transformations.pop();
1496                 p.isDraggable = true;
1497                 p.parents = [];
1498 
1499                 p.coords.off("update");
1500             }
1501 
1502             this.hasFixedAngle = false;
1503 
1504             return this;
1505         };
1506 
1507         el.setParents(points); // Important: This overwrites the parents order in underlying sector
1508     } // end '3points'
1509 
1510     // GEONExT compatible labels.
1511     if (Type.exists(el.visProp.text)) {
1512         el.label.setText(el.evalVisProp('text'));
1513     }
1514 
1515     el.elType = "angle";
1516     el.type = Const.OBJECT_TYPE_ANGLE;
1517     el.subs = {};
1518 
1519     /**
1520      * @class
1521      * @ignore
1522      */
1523     el.updateDataArraySquare = function () {
1524         var A, B, C,
1525             d1, d2, v, l1, l2,
1526             r = this.Radius();
1527 
1528         if (type === "2lines") {
1529             // This is necessary to update this.point1, this.point2, this.point3.
1530             this.updateDataArraySector();
1531         }
1532 
1533         A = this.point2;
1534         B = this.point1;
1535         C = this.point3;
1536 
1537         A = A.coords.usrCoords;
1538         B = B.coords.usrCoords;
1539         C = C.coords.usrCoords;
1540 
1541         d1 = Geometry.distance(A, B, 3);
1542         d2 = Geometry.distance(C, B, 3);
1543 
1544         // In case of type=='2lines' this is redundant, because r == d1 == d2
1545         A = [1, B[1] + ((A[1] - B[1]) * r) / d1, B[2] + ((A[2] - B[2]) * r) / d1];
1546         C = [1, B[1] + ((C[1] - B[1]) * r) / d2, B[2] + ((C[2] - B[2]) * r) / d2];
1547 
1548         v = Mat.crossProduct(C, B);
1549         l1 = [-A[1] * v[1] - A[2] * v[2], A[0] * v[1], A[0] * v[2]];
1550         v = Mat.crossProduct(A, B);
1551         l2 = [-C[1] * v[1] - C[2] * v[2], C[0] * v[1], C[0] * v[2]];
1552 
1553         v = Mat.crossProduct(l1, l2);
1554         v[1] /= v[0];
1555         v[2] /= v[0];
1556 
1557         this.dataX = [B[1], A[1], v[1], C[1], B[1]];
1558         this.dataY = [B[2], A[2], v[2], C[2], B[2]];
1559 
1560         this.bezierDegree = 1;
1561     };
1562 
1563     /**
1564      * @class
1565      * @ignore
1566      */
1567     el.updateDataArrayNone = function () {
1568         this.dataX = [NaN];
1569         this.dataY = [NaN];
1570         this.bezierDegree = 1;
1571     };
1572 
1573     /**
1574      * @class
1575      * @ignore
1576      */
1577     el.updateDataArray = function () {
1578         var type = this.evalVisProp('type'),
1579             deg = Geometry.trueAngle(this.point2, this.point1, this.point3),
1580             vp_s = this.evalVisProp('selection');
1581 
1582         if ((vp_s === "minor" && deg > 180.0) || (vp_s === "major" && deg < 180.0)) {
1583             deg = 360.0 - deg;
1584         }
1585 
1586         if (Math.abs(deg - 90.0) < this.evalVisProp('orthosensitivity') + Mat.eps) {
1587             type = this.evalVisProp('orthotype');
1588         }
1589 
1590         if (type === "none") {
1591             this.updateDataArrayNone();
1592         } else if (type === "square") {
1593             this.updateDataArraySquare();
1594         } else if (type === "sector") {
1595             this.updateDataArraySector();
1596         } else if (type === "sectordot") {
1597             this.updateDataArraySector();
1598             if (!this.dot.visProp.visible) {
1599                 this.dot.setAttribute({ visible: true });
1600             }
1601         }
1602 
1603         if (!this.visProp.visible || (type !== "sectordot" && this.dot.visProp.visible)) {
1604             this.dot.setAttribute({ visible: false });
1605         }
1606     };
1607 
1608     attrsub = Type.copyAttributes(attributes, board.options, "angle", "dot");
1609     /**
1610      * Indicates a right angle. Invisible by default, use <tt>dot.visible: true</tt> to show.
1611      * Though this dot indicates a right angle, it can be visible even if the angle is not a right
1612      * one.
1613      * @type JXG.Point
1614      * @name dot
1615      * @memberOf Angle.prototype
1616      */
1617     el.dot = board.create(
1618         "point",
1619         [
1620             function () {
1621                 var A, B, r, d, a2, co, si, mat, vp_s;
1622 
1623                 if (Type.exists(el.dot) && !el.dot.visProp.visible) {
1624                     return [0, 0];
1625                 }
1626 
1627                 A = el.point2.coords.usrCoords;
1628                 B = el.point1.coords.usrCoords;
1629                 r = el.Radius();
1630                 d = Geometry.distance(A, B, 3);
1631                 a2 = Geometry.rad(el.point2, el.point1, el.point3);
1632 
1633                 vp_s = el.evalVisProp('selection');
1634                 if ((vp_s === "minor" && a2 > Math.PI) || (vp_s === "major" && a2 < Math.PI)) {
1635                     a2 = -(2 * Math.PI - a2);
1636                 }
1637                 a2 *= 0.5;
1638 
1639                 co = Math.cos(a2);
1640                 si = Math.sin(a2);
1641 
1642                 A = [1, B[1] + ((A[1] - B[1]) * r) / d, B[2] + ((A[2] - B[2]) * r) / d];
1643 
1644                 mat = [
1645                     [1, 0, 0],
1646                     [B[1] - 0.5 * B[1] * co + 0.5 * B[2] * si, co * 0.5, -si * 0.5],
1647                     [B[2] - 0.5 * B[1] * si - 0.5 * B[2] * co, si * 0.5, co * 0.5]
1648                 ];
1649                 return Mat.matVecMult(mat, A);
1650             }
1651         ],
1652         attrsub
1653     );
1654 
1655     el.dot.dump = false;
1656     el.subs.dot = el.dot;
1657 
1658     if (type === "2lines") {
1659         for (i = 0; i < 2; i++) {
1660             board.select(parents[i]).addChild(el.dot);
1661         }
1662     } else {
1663         for (i = 0; i < 3; i++) {
1664             board.select(points[i]).addChild(el.dot);
1665         }
1666     }
1667     board.unsuspendUpdate();
1668 
1669     /**
1670      * Returns the value of the angle.
1671      * @memberOf Angle.prototype
1672      * @name Value
1673      * @function
1674      * @param {String} [unit='length'] Unit of the returned values. Possible units are
1675      * <ul>
1676      * <li> 'radians' (default): angle value in radians
1677      * <li> 'degrees': angle value in degrees
1678      * <li> 'semicircle': angle value in radians as a multiple of π, e.g. if the angle is 1.5π, 1.5 will be returned.
1679      * <li> 'circle': angle value in radians as a multiple of 2π
1680      * <li> 'length': length of the arc line of the angle
1681      * </ul>
1682      * It is sufficient to supply the first three characters of the unit, e.g. 'len'.
1683      * @returns {Number} angle value in various units.
1684      * @see Sector#L
1685      * @see Arc#Value
1686      * @example
1687      * var A, B, C, ang,
1688      *     r = 0.5;
1689      * A = board.create("point", [3, 0]);
1690      * B = board.create("point", [0, 0]);
1691      * C = board.create("point", [2, 2]);
1692      * ang = board.create("angle", [A, B, C], {radius: r});
1693      *
1694      * console.log(ang.Value());
1695      * // Output Math.PI * 0.25
1696      *
1697      * console.log(ang.Value('radian'));
1698      * // Output Math.PI * 0.25
1699      *
1700      * console.log(ang.Value('degree');
1701      * // Output 45
1702      *
1703      * console.log(ang.Value('semicircle'));
1704      * // Output 0.25
1705      *
1706      * console.log(ang.Value('circle'));
1707      * // Output 0.125
1708      *
1709      * console.log(ang.Value('length'));
1710      * // Output r * Math.PI * 0.25
1711      *
1712      * console.log(ang.L());
1713      * // Output r * Math.PI * 0.25
1714      *
1715      */
1716     el.Value = function(unit) {
1717         unit = unit || 'radians';
1718         if (unit === '') {
1719             unit = 'radians';
1720         }
1721         return el.arc.Value(unit);
1722     };
1723 
1724     // documented in GeometryElement
1725     /**
1726      * @class
1727      * @ignore
1728      */
1729     el.getLabelAnchor = function () {
1730         var vec,
1731             dx = 12,
1732             A, B, r, d, a2, co, si, mat,
1733             vp_s = el.evalVisProp('selection'),
1734             l_vp = this.label ? this.label.visProp : this.visProp.label;
1735 
1736         // If this is uncommented, the angle label can not be dragged
1737         //if (Type.exists(this.label)) {
1738         //    this.label.relativeCoords = new Coords(Const.COORDS_BY_SCREEN, [0, 0], this.board);
1739         //}
1740 
1741         if (Type.exists(this.label) && Type.exists(this.label.visProp.fontsize)) {
1742             dx = this.label.evalVisProp('fontsize');
1743         }
1744         dx /= this.board.unitX;
1745 
1746         A = el.point2.coords.usrCoords;
1747         B = el.point1.coords.usrCoords;
1748         r = el.Radius();
1749         d = Geometry.distance(A, B, 3);
1750         a2 = Geometry.rad(el.point2, el.point1, el.point3);
1751         if ((vp_s === "minor" && a2 > Math.PI) || (vp_s === "major" && a2 < Math.PI)) {
1752             a2 = -(2 * Math.PI - a2);
1753         }
1754         a2 *= 0.5;
1755         co = Math.cos(a2);
1756         si = Math.sin(a2);
1757 
1758         A = [1, B[1] + ((A[1] - B[1]) * r) / d, B[2] + ((A[2] - B[2]) * r) / d];
1759 
1760         mat = [
1761             [1, 0, 0],
1762             [B[1] - 0.5 * B[1] * co + 0.5 * B[2] * si, co * 0.5, -si * 0.5],
1763             [B[2] - 0.5 * B[1] * si - 0.5 * B[2] * co, si * 0.5, co * 0.5]
1764         ];
1765         vec = Mat.matVecMult(mat, A);
1766         vec[1] /= vec[0];
1767         vec[2] /= vec[0];
1768         vec[0] /= vec[0];
1769 
1770         d = Geometry.distance(vec, B, 3);
1771         vec = [
1772             vec[0],
1773             B[1] + ((vec[1] - B[1]) * (r + dx)) / d,
1774             B[2] + ((vec[2] - B[2]) * (r + dx)) / d
1775         ];
1776 
1777         l_vp.position = Geometry.calcLabelQuadrant(Geometry.rad([1, 0], [0, 0], vec));
1778 
1779         return new Coords(Const.COORDS_BY_USER, vec, this.board);
1780     };
1781 
1782     el.methodMap = Type.deepCopy(el.methodMap, {
1783         setAngle: "setAngle",
1784         Value: "Value",
1785         free: "free"
1786     });
1787 
1788     return el;
1789 };
1790 
1791 JXG.registerElement("angle", JXG.createAngle);
1792 
1793 /**
1794  * @class A non-reflex angle is the acute or obtuse instance of an angle.
1795  * It is defined by a center, one point that
1796  * defines the radius, and a third point that defines the angle of the sector.
1797  * @pseudo
1798  * @name NonReflexAngle
1799  * @augments Angle
1800  * @constructor
1801  * @type Sector
1802  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
1803  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Minor sector is a sector of a circle around p1 having measure less than or equal to
1804  * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
1805  * @example
1806  * // Create a non-reflex angle out of three free points
1807  * var p1 = board.create('point', [5.0, 3.0]),
1808  *     p2 = board.create('point', [1.0, 0.5]),
1809  *     p3 = board.create('point', [1.5, 5.0]),
1810  *
1811  *     a = board.create('nonreflexangle', [p1, p2, p3], {radius: 2}),
1812  *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1813  * </pre><div class="jxgbox" id="JXGd0ab6d6b-63a7-48b2-8749-b02bb5e744f9" style="width: 300px; height: 300px;"></div>
1814  * <script type="text/javascript">
1815  * (function () {
1816  *   var board = JXG.JSXGraph.initBoard('JXGd0ab6d6b-63a7-48b2-8749-b02bb5e744f9', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1817  *     p1 = board.create('point', [5.0, 3.0]),
1818  *     p2 = board.create('point', [1.0, 0.5]),
1819  *     p3 = board.create('point', [1.5, 5.0]),
1820  *
1821  *     a = board.create('nonreflexangle', [p1, p2, p3], {radius: 2}),
1822  *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1823  * })();
1824  * </script><pre>
1825  */
1826 JXG.createNonreflexAngle = function (board, parents, attributes) {
1827     var el;
1828 
1829     attributes.selection = "minor";
1830     attributes = Type.copyAttributes(attributes, board.options, 'nonreflexangle');
1831     el = JXG.createAngle(board, parents, attributes);
1832 
1833     // Documented in createAngle
1834     el.Value = function (unit) {
1835         var rad = Geometry.rad(this.point2, this.point1, this.point3);
1836         unit = unit || 'radians';
1837         if (unit === '') {
1838             unit = 'radians';
1839         }
1840         rad = (rad < Math.PI) ? rad : 2.0 * Math.PI - rad;
1841 
1842         return this.arc.Value(unit, rad);
1843     };
1844     return el;
1845 };
1846 
1847 JXG.registerElement("nonreflexangle", JXG.createNonreflexAngle);
1848 
1849 /**
1850  * @class A reflex angle is the neither acute nor obtuse instance of an angle.
1851  * It is defined by a center, one point that
1852  * defines the radius, and a third point that defines the angle of the sector.
1853  * @pseudo
1854  * @name ReflexAngle
1855  * @augments Angle
1856  * @constructor
1857  * @type Sector
1858  * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
1859  * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Minor sector is a sector of a circle around p1 having measure less than or equal to
1860  * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
1861  * @example
1862  * // Create a non-reflex angle out of three free points
1863  * var p1 = board.create('point', [5.0, 3.0]),
1864  *     p2 = board.create('point', [1.0, 0.5]),
1865  *     p3 = board.create('point', [1.5, 5.0]),
1866  *
1867  *     a = board.create('reflexangle', [p1, p2, p3], {radius: 2}),
1868  *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1869  * </pre><div class="jxgbox" id="JXGf2a577f2-553d-4f9f-a895-2d6d4b8c60e8" style="width: 300px; height: 300px;"></div>
1870  * <script type="text/javascript">
1871  * (function () {
1872  * var board = JXG.JSXGraph.initBoard('JXGf2a577f2-553d-4f9f-a895-2d6d4b8c60e8', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1873  *     p1 = board.create('point', [5.0, 3.0]),
1874  *     p2 = board.create('point', [1.0, 0.5]),
1875  *     p3 = board.create('point', [1.5, 5.0]),
1876  *
1877  *     a = board.create('reflexangle', [p1, p2, p3], {radius: 2}),
1878  *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1879  * })();
1880  * </script><pre>
1881  */
1882 JXG.createReflexAngle = function (board, parents, attributes) {
1883     var el;
1884 
1885     attributes.selection = "major";
1886     attributes = Type.copyAttributes(attributes, board.options, 'reflexangle');
1887     el = JXG.createAngle(board, parents, attributes);
1888 
1889     // Documented in createAngle
1890     el.Value = function (unit) {
1891         var rad = Geometry.rad(this.point2, this.point1, this.point3);
1892         unit = unit || 'radians';
1893         if (unit === '') {
1894             unit = 'radians';
1895         }
1896         rad = (rad >= Math.PI) ? rad : 2.0 * Math.PI - rad;
1897 
1898         return this.arc.Value(unit, rad);
1899     };
1900 
1901     return el;
1902 };
1903 
1904 JXG.registerElement("reflexangle", JXG.createReflexAngle);
1905