From 89e645a0cd2950da0c4754c543fcd316305bcaa3 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 4 May 2020 22:40:35 +0200 Subject: [PATCH] impl. helper functions for easier use --- Math/Matrix/Matrix.php | 17 +++++++++++++++++ Math/Matrix/Vector.php | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 991a5d650..677817059 100644 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -79,6 +79,23 @@ class Matrix implements \ArrayAccess, \Iterator } } + /** + * Create matrix from array + * + * @param array $matrix Matrix array + * + * @return self + * + * @since 1.0.0 + */ + public static function fromArray(array $matrix) : self + { + $m = new self(); + $m->setMatrix($matrix); + + return $m; + } + /** * Set value. * diff --git a/Math/Matrix/Vector.php b/Math/Matrix/Vector.php index bc6b125a9..61c3dbc31 100644 --- a/Math/Matrix/Vector.php +++ b/Math/Matrix/Vector.php @@ -24,6 +24,23 @@ namespace phpOMS\Math\Matrix; */ final class Vector extends Matrix { + /** + * Create vector from array + * + * @param array $vector Matrix array + * + * @return self + * + * @since 1.0.0 + */ + public static function fromArray(array $vector) : Vector + { + $v = new self(); + $v->setMatrixV($vector); + + return $v; + } + /** * Set vector value *