| 1 | /*\r |
| 2 | * L.Point represents a point with x and y coordinates.\r |
| 3 | */\r |
| 4 | \r |
| 5 | L.Point = function(/*Number*/ x, /*Number*/ y, /*Boolean*/ round) {\r |
| 6 | this.x = (round ? Math.round(x) : x);\r |
| 7 | this.y = (round ? Math.round(y) : y);\r |
| 8 | };\r |
| 9 | \r |
| 10 | L.Point.prototype = {\r |
| 11 | add: function(point) {\r |
| 12 | return this.clone()._add(point);\r |
| 13 | },\r |
| 14 | \r |
| 15 | _add: function(point) {\r |
| 16 | this.x += point.x;\r |
| 17 | this.y += point.y;\r |
| 18 | return this; \r |
| 19 | },\r |
| 20 | \r |
| 21 | subtract: function(point) {\r |
| 22 | return this.clone()._subtract(point);\r |
| 23 | },\r |
| 24 | \r |
| 25 | // destructive subtract (faster)\r |
| 26 | _subtract: function(point) {\r |
| 27 | this.x -= point.x;\r |
| 28 | this.y -= point.y;\r |
| 29 | return this;\r |
| 30 | },\r |
| 31 | \r |
| 32 | divideBy: function(num, round) {\r |
| 33 | return new L.Point(this.x/num, this.y/num, round);\r |
| 34 | },\r |
| 35 | \r |
| 36 | multiplyBy: function(num) {\r |
| 37 | return new L.Point(this.x * num, this.y * num);\r |
| 38 | },\r |
| 39 | \r |
| 40 | distanceTo: function(point) {\r |
| 41 | var x = point.x - this.x,\r |
| 42 | y = point.y - this.y;\r |
| 43 | return Math.sqrt(x*x + y*y);\r |
| 44 | },\r |
| 45 | \r |
| 46 | round: function() {\r |
| 47 | return this.clone()._round();\r |
| 48 | },\r |
| 49 | \r |
| 50 | // destructive round\r |
| 51 | _round: function() {\r |
| 52 | this.x = Math.round(this.x);\r |
| 53 | this.y = Math.round(this.y);\r |
| 54 | return this;\r |
| 55 | },\r |
| 56 | \r |
| 57 | clone: function() {\r |
| 58 | return new L.Point(this.x, this.y);\r |
| 59 | },\r |
| 60 | \r |
| 61 | toString: function() {\r |
| 62 | return 'Point(' + \r |
| 63 | L.Util.formatNum(this.x) + ', ' + \r |
| 64 | L.Util.formatNum(this.y) + ')'; \r |
| 65 | }\r |
| 66 | }; |