This repository was archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathPoint.php
94 lines (83 loc) · 1.5 KB
/
Point.php
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
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* Object to represent a point on an elliptic curve
*
* @package Bitcore
*/
class Point implements PointInterface
{
/**
* MUST be a HEX value
*
* @var string
*/
protected $x;
/**
* MUST be a HEX value
*
* @var string
*/
protected $y;
/**
* @param string $x
* @param string $y
*/
public function __construct($x, $y)
{
$this->x = (string) $x;
$this->y = (string) $y;
}
/**
* @return string
*/
public function __toString()
{
if ($this->isInfinity()) {
return self::INFINITY;
}
return sprintf('(%s, %s)', $this->x, $this->y);
}
/**
* @return string
*/
public function getX()
{
return $this->x;
}
/**
* @return string
*/
public function getY()
{
return $this->y;
}
/**
* @return boolean
*/
public function isInfinity()
{
return (self::INFINITY == $this->x || self::INFINITY == $this->y);
}
/**
* @inheritdoc
*/
public function serialize()
{
return serialize(array($this->x, $this->y));
}
/**
* @inheritdoc
*/
public function unserialize($data)
{
list(
$this->x,
$this->y
) = unserialize($data);
}
}