-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55f2763
commit b2e69f1
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Nether\Common\Units; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
use Nether\Common; | ||
|
||
use Exception; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class Vec3 | ||
implements | ||
Common\Interfaces\PropertyInfoPackage, | ||
Common\Interfaces\ToArray, | ||
Common\Interfaces\ToJSON { | ||
|
||
#[Common\Meta\PropertyListable] | ||
public int|float | ||
$X; | ||
|
||
#[Common\Meta\PropertyListable] | ||
public int|float | ||
$Y; | ||
|
||
#[Common\Meta\PropertyListable] | ||
public int|float | ||
$Z; | ||
|
||
use | ||
Common\Package\PropertyInfoPackage, | ||
Common\Package\ToArray, | ||
Common\Package\ToJSON; | ||
|
||
//////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////// | ||
|
||
public function | ||
__Construct(int|float $X=0, int|float $Y=0, int|float $Z=0) { | ||
|
||
$this->X = $X; | ||
$this->Y = $Y; | ||
$this->Z = $Z; | ||
|
||
return; | ||
} | ||
|
||
public function | ||
__Get(string $Key): | ||
mixed { | ||
|
||
return match($Key) { | ||
default => throw new Exception(sprintf( | ||
'%s is not a thing on %s', | ||
$Key, $this::class | ||
)) | ||
}; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////// | ||
//////////////////////////////////////////////////////////////// | ||
|
||
public function | ||
ClampX(int|float $Min, int|float $Max): | ||
static { | ||
|
||
$this->X = Common\Math::Clamp($this->X, $Min, $Max); | ||
|
||
return $this; | ||
} | ||
|
||
public function | ||
ClampY(int|float $Min, int|float $Max): | ||
static { | ||
|
||
$this->Y = Common\Math::Clamp($this->Y, $Min, $Max); | ||
|
||
return $this; | ||
} | ||
|
||
public function | ||
ClampZ(int|float $Min, int|float $Max): | ||
static { | ||
|
||
$this->Z = Common\Math::Clamp($this->Z, $Min, $Max); | ||
|
||
return $this; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// CONTEXT SWEETENER API /////////////////////////////////////// | ||
|
||
// these methods exist purely to give the code creating vectors context | ||
// what they are doing. | ||
|
||
|
||
static public function | ||
Coord(int|float $X=0, int|float $Y=0, int|float $Z=0): | ||
static { | ||
|
||
return new static($X, $Y, $Z); | ||
} | ||
|
||
}; |