Hoa central
Boundfloat.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Realdom;
38 
39 use Hoa\Math;
40 
49 class Boundfloat extends RealdomFloat implements IRealdom\Interval
50 {
56  const NAME = 'boundfloat';
57 
63  protected $_arguments = [
64  'Constfloat lower' => PHP_FLOAT_MIN,
65  'Constfloat upper' => PHP_FLOAT_MAX
66  ];
67 
68 
69 
75  protected function construct()
76  {
77  $lower = $this['lower']->getConstantValue();
78  $upper = $this['upper']->getConstantValue();
79 
80  if ($lower > $upper) {
81  throw new Exception\InvalidArgument(
82  '$lower must be strictly lower than $upper; given %d and %d.',
83  0,
84  [$lower, $upper]
85  );
86  }
87  }
88 
95  protected function _predicate($q)
96  {
97  return
98  parent::_predicate($q) &&
99  $q >= $this['lower']->getConstantValue() &&
100  $q <= $this['upper']->getConstantValue();
101  }
102 
109  protected function _sample(Math\Sampler $sampler)
110  {
111  return $sampler->getFloat(
112  $this['lower']->sample($sampler),
113  $this['upper']->sample($sampler)
114  );
115  }
116 
122  public function getLowerBound()
123  {
124  return $this['lower']->getConstantValue();
125  }
126 
132  public function getUpperBound()
133  {
134  return $this['upper']->getConstantValue();
135  }
136 
143  public function reduceRightTo($value)
144  {
145  $lower = $this['lower']->getConstantValue();
146  $upper = min($this['upper']->getConstantValue(), $value);
147 
148  if ($lower > $upper) {
149  return false;
150  }
151 
152  $this['upper'] = new Constinteger($value);
153 
154  return true;
155  }
156 
163  public function reduceLeftTo($value)
164  {
165  $lower = max($this['lower']->getConstantValue(), $value);
166  $upper = $this['upper']->getConstantValue();
167 
168  if ($lower > $upper) {
169  return false;
170  }
171 
172  $this['lower'] = new Constinteger($value);
173 
174  return true;
175  }
176 }
sample(Math\Sampler $sampler=null)
Definition: Realdom.php:686
_sample(Math\Sampler $sampler)
Definition: Boundfloat.php:109