Hoa central
Natural.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Realdom;
38 
39 use Hoa\Math;
40 
49 class Natural
50  extends Integer
51  implements IRealdom\Nonconvex,
53 {
59  const NAME = 'natural';
60 
66  protected $_arguments = [
67  'Constinteger start' => 0,
68  'Constinteger step' => 1
69  ];
70 
76  protected $_discredited = [];
77 
78 
79 
85  public function reset()
86  {
87  $this->setValue(null);
88  $this->_discredited = [];
89 
90  return;
91  }
92 
99  protected function _predicate($q)
100  {
101  $q -= $this['start']->getConstantValue();
102 
103  return 0 === $q % $this['step']->getConstantValue();
104  }
105 
112  protected function _sample(Math\Sampler $sampler)
113  {
114  $sampled = $this->getValue();
115 
116  do {
117  if (null === $sampled) {
118  $sampled = $this['start']->getConstantValue();
119  } else {
120  $sampled += $this['step']->getConstantValue();
121  }
122  } while (true === in_array($sampled, $this->_discredited));
123 
124  return $sampled;
125  }
126 
133  public function discredit($value)
134  {
135  if (true === in_array($value, $this->_discredited) ||
136  false === $this->predicate($value)) {
137  return $this;
138  }
139 
140  $this->_discredited[] = $value;
141 
142  return $this;
143  }
144 
150  public function getSize()
151  {
152  return PHP_INT_MAX;
153  }
154 }
setValue($sampled)
Definition: Realdom.php:577
_sample(Math\Sampler $sampler)
Definition: Natural.php:112