Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Provides an in browser PDF editor.
18
 *
19
 * @module moodle-assignfeedback_editpdf-editor
20
 */
21
 
22
/**
23
 * Class representing a 2d rect.
24
 *
25
 * @namespace M.assignfeedback_editpdf
26
 * @param int x
27
 * @param int y
28
 * @param int width
29
 * @param int height
30
 * @class rect
31
 */
32
var RECT = function(x, y, width, height) {
33
 
34
    /**
35
     * X coordinate.
36
     * @property x
37
     * @type int
38
     * @public
39
     */
40
    this.x = x;
41
 
42
    /**
43
     * Y coordinate.
44
     * @property y
45
     * @type int
46
     * @public
47
     */
48
    this.y = y;
49
 
50
    /**
51
     * Width
52
     * @property width
53
     * @type int
54
     * @public
55
     */
56
    this.width = width;
57
 
58
    /**
59
     * Height
60
     * @property height
61
     * @type int
62
     * @public
63
     */
64
    this.height = height;
65
 
66
    /**
67
     * Set this rect to represent the smallest possible rectangle containing this list of points.
68
     * @method bounds
69
     * @param M.assignfeedback_editpdf.point[]
70
     * @public
71
     */
72
    this.bound = function(points) {
73
        var minx = 0,
74
            maxx = 0,
75
            miny = 0,
76
            maxy = 0,
77
            i = 0,
78
            point;
79
 
80
        for (i = 0; i < points.length; i++) {
81
            point = points[i];
82
            if (point.x < minx || i === 0) {
83
                minx = point.x;
84
            }
85
            if (point.x > maxx || i === 0) {
86
                maxx = point.x;
87
            }
88
            if (point.y < miny || i === 0) {
89
                miny = point.y;
90
            }
91
            if (point.y > maxy || i === 0) {
92
                maxy = point.y;
93
            }
94
        }
95
        this.x = minx;
96
        this.y = miny;
97
        this.width = maxx - minx;
98
        this.height = maxy - miny;
99
        // Allow chaining.
100
        return this;
101
    };
102
 
103
    /**
104
     * Checks if rect has min width.
105
     * @method has_min_width
106
     * @return bool true if width is more than 5px.
107
     * @public
108
     */
109
    this.has_min_width = function() {
110
        return (this.width >= 5);
111
    };
112
 
113
    /**
114
     * Checks if rect has min height.
115
     * @method has_min_height
116
     * @return bool true if height is more than 5px.
117
     * @public
118
     */
119
    this.has_min_height = function() {
120
        return (this.height >= 5);
121
    };
122
 
123
    /**
124
     * Set min. width of annotation bound.
125
     * @method set_min_width
126
     * @public
127
     */
128
    this.set_min_width = function() {
129
        this.width = 5;
130
    };
131
 
132
    /**
133
     * Set min. height of annotation bound.
134
     * @method set_min_height
135
     * @public
136
     */
137
    this.set_min_height = function() {
138
        this.height = 5;
139
    };
140
};
141
 
142
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
143
M.assignfeedback_editpdf.rect = RECT;