WebDriverPoint.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // Copyright 2004-present Facebook. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. namespace Facebook\WebDriver;
  16. /**
  17. * Represent a point.
  18. */
  19. class WebDriverPoint
  20. {
  21. private $x;
  22. private $y;
  23. public function __construct($x, $y)
  24. {
  25. $this->x = $x;
  26. $this->y = $y;
  27. }
  28. /**
  29. * Get the x-coordinate.
  30. *
  31. * @return int The x-coordinate of the point.
  32. */
  33. public function getX()
  34. {
  35. return $this->x;
  36. }
  37. /**
  38. * Get the y-coordinate.
  39. *
  40. * @return int The y-coordinate of the point.
  41. */
  42. public function getY()
  43. {
  44. return $this->y;
  45. }
  46. /**
  47. * Set the point to a new position.
  48. *
  49. * @param int $new_x
  50. * @param int $new_y
  51. * @return WebDriverPoint The same instance with updated coordinates.
  52. */
  53. public function move($new_x, $new_y)
  54. {
  55. $this->x = $new_x;
  56. $this->y = $new_y;
  57. return $this;
  58. }
  59. /**
  60. * Move the current by offsets.
  61. *
  62. * @param int $x_offset
  63. * @param int $y_offset
  64. * @return WebDriverPoint The same instance with updated coordinates.
  65. */
  66. public function moveBy($x_offset, $y_offset)
  67. {
  68. $this->x += $x_offset;
  69. $this->y += $y_offset;
  70. return $this;
  71. }
  72. /**
  73. * Check whether the given point is the same as the instance.
  74. *
  75. * @param WebDriverPoint $point The point to be compared with.
  76. * @return bool Whether the x and y coordinates are the same as the instance.
  77. */
  78. public function equals(WebDriverPoint $point)
  79. {
  80. return $this->x === $point->getX() &&
  81. $this->y === $point->getY();
  82. }
  83. }