Moved math parts to own repo
This commit is contained in:
parent
b35e0551d2
commit
e157591db3
3
.gitignore
vendored
Normal file → Executable file
3
.gitignore
vendored
Normal file → Executable file
@ -1,3 +1,6 @@
|
|||||||
build
|
build
|
||||||
docs
|
docs
|
||||||
libgzutil.a
|
libgzutil.a
|
||||||
|
.clangd
|
||||||
|
.vimspector.json
|
||||||
|
__pycache__
|
||||||
|
2
PKGBUILD
Normal file → Executable file
2
PKGBUILD
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
# Maintainer: Matthias Quintern <matthiasqui@protonmail.com>
|
# Maintainer: Matthias Quintern <matthiasqui@protonmail.com>
|
||||||
pkgname=gz-cpp-util
|
pkgname=gz-cpp-util
|
||||||
pkgver=1.1
|
pkgver=1.2
|
||||||
pkgrel=0
|
pkgrel=0
|
||||||
pkgdesc="Utility library for c++"
|
pkgdesc="Utility library for c++"
|
||||||
arch=('any')
|
arch=('any')
|
||||||
|
3
README.md
Normal file → Executable file
3
README.md
Normal file → Executable file
@ -3,7 +3,6 @@ cpp-20 utility library for my projects
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Extensive logger using variadic templates to log almost anything
|
- Extensive logger using variadic templates to log almost anything
|
||||||
- vecX and matMxN vector and matrix classes
|
|
||||||
- Some containers like a thread safe queue and a ringbuffer
|
- Some containers like a thread safe queue and a ringbuffer
|
||||||
- Regex that works with std::string_view
|
- Regex that works with std::string_view
|
||||||
- Type conversion utility (from string to int/float/uint/bool)
|
- Type conversion utility (from string to int/float/uint/bool)
|
||||||
@ -34,6 +33,8 @@ Install doxygen and run `make docs`, then open `docs/html/index.html`.
|
|||||||
|
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
### 2022-09-17
|
||||||
|
- Moved math part to its own repository/library [here](https://github.com/MatthiasQuintern/gzm)
|
||||||
### 2022-09-10
|
### 2022-09-10
|
||||||
- Added matrices to math lib
|
- Added matrices to math lib
|
||||||
- Improved logger
|
- Improved logger
|
||||||
|
@ -1,946 +0,0 @@
|
|||||||
#!/bin/python3
|
|
||||||
"""
|
|
||||||
A python script to generate a c++ vector and matrix library for mathematics.
|
|
||||||
Should work with vectors/matrix up to a length of 9.
|
|
||||||
|
|
||||||
The script generates a header (and source) for each container (vector/matrix).
|
|
||||||
There are overloads for each container which allow convenient usage.
|
|
||||||
Eg multiplication with matrix rules is as easy as: (example)
|
|
||||||
mat3x2 = mat3x3 * mat3x2
|
|
||||||
n = rvec4 * vec4
|
|
||||||
To be accurate, there is a differentiation between row and column vector, they are basically the same but each has a separate class which differ only for the matrix multiplication overloads.
|
|
||||||
|
|
||||||
To help compile times, the templated definitions of most methods is in the source file (by default).
|
|
||||||
That means that all templates must be explictly instantiated beforehand. The instantiations are in the tpp file included by the cpp files.
|
|
||||||
Specify the needed types by adding them to templateInstantiationIntTypes and templateInstantiationFloatTypes respectively (the differentiation is needed for the modulo operator).
|
|
||||||
|
|
||||||
All that makes the generated library is not memory efficient, but very fast and convenient.
|
|
||||||
|
|
||||||
AS OF NOW, THIS SOFTWARE IS NEARLY UNTESTED AND BOUND TO CONTAIN LOTS OF BUGS.
|
|
||||||
|
|
||||||
Copyright © 2022 Matthias Quintern.
|
|
||||||
This software comes with no warranty.
|
|
||||||
This software is licensed under the GPL3
|
|
||||||
"""
|
|
||||||
|
|
||||||
from os import path, mkdir
|
|
||||||
#
|
|
||||||
# SETTINGS
|
|
||||||
#
|
|
||||||
# generate up to MAX_N (-> vecN, matNxN)
|
|
||||||
MAX_N = 4
|
|
||||||
letters_ = {
|
|
||||||
2: [ "x", "y" ],
|
|
||||||
3: [ "x", "y", "z" ],
|
|
||||||
4: [ "x", "y", "z", "w"],
|
|
||||||
}
|
|
||||||
directory = "math"
|
|
||||||
#
|
|
||||||
# \t or x-spaces
|
|
||||||
tab = "\t"
|
|
||||||
# float, double, long double...
|
|
||||||
float_type = "float"
|
|
||||||
# string or None
|
|
||||||
namespace = "gz"
|
|
||||||
typeShorts = {
|
|
||||||
"float": "f",
|
|
||||||
"double": "d",
|
|
||||||
"int": "i",
|
|
||||||
"unsigned int": "u",
|
|
||||||
}
|
|
||||||
include_static_asserts = True
|
|
||||||
include_template_instantiations = True
|
|
||||||
templateInstantiationIntTypes = [ # these must be usable with %
|
|
||||||
# "uint8_t"
|
|
||||||
"uint8_t", "uint16_t", "uint32_t", "uint64_t",
|
|
||||||
"int8_t", "int16_t", "int32_t", "int64_t",
|
|
||||||
]
|
|
||||||
templateInstantiationFloatTypes = [
|
|
||||||
# "float",
|
|
||||||
"float", "double", "long double"
|
|
||||||
]
|
|
||||||
templateInstantiationTypes = templateInstantiationFloatTypes + templateInstantiationIntTypes
|
|
||||||
|
|
||||||
|
|
||||||
headerIncludes = [ "\"concepts.hpp\"", "\"../container/iterator.hpp\"" ]
|
|
||||||
sourceIncludes = ["<cmath>", "<algorithm>", "<cstdint>"]
|
|
||||||
|
|
||||||
|
|
||||||
# shorthands
|
|
||||||
Number_N = ("Number", "N")
|
|
||||||
Class_T = [("Number", "T")]
|
|
||||||
constexpr = "constexpr"
|
|
||||||
inline = "inline"
|
|
||||||
|
|
||||||
|
|
||||||
def template(t:list[tuple[str, str]]):
|
|
||||||
if len(t) == 0:
|
|
||||||
return ""
|
|
||||||
s = "template<"
|
|
||||||
for temp in t:
|
|
||||||
s += temp[0] + " " + temp[1] + ", "
|
|
||||||
return s.removesuffix(", ") + ">\n"
|
|
||||||
|
|
||||||
|
|
||||||
class Member:
|
|
||||||
def __init__(self, class_:str, name:str, c_temp:list=[], m_temp:list=[], prefixes:list=[], ret_type:str="", args:str="", init:str="", const=False, body:list=[], comment:str=""):
|
|
||||||
"""
|
|
||||||
:param class: class name
|
|
||||||
:param name: member name
|
|
||||||
:param c_temp: list of templates of the class
|
|
||||||
:param m_temp: list of templates of the member
|
|
||||||
:param prefixes: things like constexpr, inline...
|
|
||||||
:param ret_type: return type of the member
|
|
||||||
:param args: arguments of the member
|
|
||||||
:param init: initializion of the member
|
|
||||||
:param const: True if the method does not change the object
|
|
||||||
:param body: method body
|
|
||||||
:param comment: a single-line docstring
|
|
||||||
|
|
||||||
template<c_temp>
|
|
||||||
class class {
|
|
||||||
comment
|
|
||||||
template<m_temp>
|
|
||||||
prefixes ret_type name(args) const : init {
|
|
||||||
body
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
self.class_ = class_
|
|
||||||
self.name = name
|
|
||||||
self.prefixes = prefixes
|
|
||||||
self.c_temp = c_temp
|
|
||||||
self.m_temp = m_temp
|
|
||||||
self.ret_type = ""
|
|
||||||
if ret_type: self.ret_type = ret_type + " "
|
|
||||||
self.args = args
|
|
||||||
self.init = ""
|
|
||||||
if init: self.init = f"\n{tab} : {init} "
|
|
||||||
self.const = ""
|
|
||||||
if const: self.const = " const"
|
|
||||||
self.body = body
|
|
||||||
self.comment = ""
|
|
||||||
if comment: self.comment = "/// " + comment + "\n"
|
|
||||||
|
|
||||||
def getArgsAsList(self):
|
|
||||||
args = []
|
|
||||||
const = False
|
|
||||||
arglist = self.args.split(", ")
|
|
||||||
for i in range(len(arglist)):
|
|
||||||
if "const" in arglist[i]:
|
|
||||||
arglist[i] = arglist[i].replace("const ", "")
|
|
||||||
const = True
|
|
||||||
args.append(arglist[i].split(" "))
|
|
||||||
if const:
|
|
||||||
args[-1][0] = "const " + args[-1][0]
|
|
||||||
return args
|
|
||||||
|
|
||||||
def defintionH(self, depth:int=0):
|
|
||||||
"""
|
|
||||||
Return the defition to be used in a header
|
|
||||||
"""
|
|
||||||
s = ""
|
|
||||||
s += self.comment
|
|
||||||
s += template(self.m_temp)
|
|
||||||
for p in self.prefixes:
|
|
||||||
s += p + " "
|
|
||||||
s += self.ret_type + self.name + f"({self.args}){self.const};\n"
|
|
||||||
return transformString(s, depth)
|
|
||||||
|
|
||||||
def source(self, depth:int=0):
|
|
||||||
"""
|
|
||||||
Return the defition + declarations for a source file
|
|
||||||
"""
|
|
||||||
s = ""
|
|
||||||
class_ = self.class_
|
|
||||||
s += template(self.c_temp)
|
|
||||||
if len(self.c_temp) > 0:
|
|
||||||
class_ = self.class_ + "<"
|
|
||||||
for t in self.c_temp:
|
|
||||||
class_ += f"{t[1]}, "
|
|
||||||
class_ = class_.removesuffix(", ") + ">"
|
|
||||||
|
|
||||||
s += template(self.m_temp)
|
|
||||||
for p in self.prefixes:
|
|
||||||
s += p + " "
|
|
||||||
s += f"{self.ret_type}{class_}::{self.name}({self.args}){self.const}{self.init}"
|
|
||||||
if self.body:
|
|
||||||
s += " {\n"
|
|
||||||
body = ""
|
|
||||||
for l in self.body: body += l + "\n"
|
|
||||||
s += transformString(body, depth)
|
|
||||||
s += "}\n"
|
|
||||||
else:
|
|
||||||
s += "{}"
|
|
||||||
return transformString(s, depth)
|
|
||||||
|
|
||||||
def header(self, depth:int=0):
|
|
||||||
"""
|
|
||||||
Return the defition + declarations for a header file
|
|
||||||
"""
|
|
||||||
s = ""
|
|
||||||
s += self.comment
|
|
||||||
s += template(self.m_temp)
|
|
||||||
for p in self.prefixes:
|
|
||||||
s += p + " "
|
|
||||||
s += f"{self.ret_type}{self.name}({self.args}){self.const}{self.init}"
|
|
||||||
if self.body:
|
|
||||||
s += " {\n"
|
|
||||||
body = ""
|
|
||||||
for l in self.body: body += l + "\n"
|
|
||||||
s += transformString(body, depth+1)
|
|
||||||
s += "}\n"
|
|
||||||
else:
|
|
||||||
s += "{}\n"
|
|
||||||
return transformString(s, depth)
|
|
||||||
|
|
||||||
def isConstructor(self):
|
|
||||||
return self.class_ == self.name
|
|
||||||
|
|
||||||
def templateInstantiations(self):
|
|
||||||
"""
|
|
||||||
generate instantiations for all templates
|
|
||||||
right now only works with Number concepts
|
|
||||||
temp<Number T>
|
|
||||||
temp<Number N>
|
|
||||||
void Class<T>::operator+(class<N>) {
|
|
||||||
->
|
|
||||||
temp<> void Class<float>::operator+(class<float>)
|
|
||||||
...
|
|
||||||
"""
|
|
||||||
if len(self.m_temp) == 0:
|
|
||||||
return ""
|
|
||||||
class_ = self.class_
|
|
||||||
if len(self.c_temp) > 0:
|
|
||||||
class_ = self.class_ + "<"
|
|
||||||
for t in self.c_temp:
|
|
||||||
class_ += f"{t[1]}, "
|
|
||||||
class_ = class_.removesuffix(", ") + ">"
|
|
||||||
|
|
||||||
arglist = self.getArgsAsList()
|
|
||||||
args = ""
|
|
||||||
for arg in arglist:
|
|
||||||
args += arg[0] + ", "
|
|
||||||
args = args.removesuffix(", ")
|
|
||||||
name = self.name.removesuffix(" ")
|
|
||||||
if len(self.m_temp) > 0:
|
|
||||||
name += " <"
|
|
||||||
for type_ in self.m_temp:
|
|
||||||
name += type_[1] + ", "
|
|
||||||
name = name.removesuffix(", ") + ">"
|
|
||||||
|
|
||||||
method = f"{self.ret_type}{class_}::{name}({args}){self.const}"
|
|
||||||
instantiations = []
|
|
||||||
if len(self.c_temp) > 0 or len(self.m_temp) > 0:
|
|
||||||
if "%" in method: types = templateInstantiationIntTypes
|
|
||||||
else: types = templateInstantiationTypes
|
|
||||||
getTemplateInsts(method, instantiations, self.c_temp + self.m_temp, types, 0)
|
|
||||||
s = ""
|
|
||||||
for spec in instantiations:
|
|
||||||
s += spec + "\n"
|
|
||||||
return s + "\n";
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# HELPERS
|
|
||||||
#
|
|
||||||
def classname(row, col, template=""):
|
|
||||||
name = ""
|
|
||||||
if template and col == 1 and row == 1:
|
|
||||||
return template
|
|
||||||
elif col == 1:
|
|
||||||
name = "vec" + str(row)
|
|
||||||
elif row == 1:
|
|
||||||
name = "rvec" + str(col)
|
|
||||||
else:
|
|
||||||
name = "mat" + str(row) + "x" + str(col);
|
|
||||||
if template:
|
|
||||||
name += "<" + template + ">"
|
|
||||||
return name
|
|
||||||
|
|
||||||
|
|
||||||
def concept(row, col, template=""):
|
|
||||||
name = ""
|
|
||||||
if template and col == 1 and row == 1:
|
|
||||||
return template
|
|
||||||
elif col == 1:
|
|
||||||
name = "ColumnVector" + str(row)
|
|
||||||
elif row == 1:
|
|
||||||
name = "RowVector" + str(col)
|
|
||||||
else:
|
|
||||||
name = "Mat" + str(row) + "x" + str(col);
|
|
||||||
if template:
|
|
||||||
name += "<" + template + ">"
|
|
||||||
return name
|
|
||||||
|
|
||||||
|
|
||||||
def classnameFromConcept(concept:str):
|
|
||||||
name = ""
|
|
||||||
number = ""
|
|
||||||
if concept.startswith("ColumnVector"):
|
|
||||||
name = "vec"
|
|
||||||
number = concept.removeprefix("ColumnVector")
|
|
||||||
elif concept.startswith("RowVector"):
|
|
||||||
name = "rvec"
|
|
||||||
number = concept.removeprefix("RowVector")
|
|
||||||
elif concept.startswith("Mat"):
|
|
||||||
name = "mat"
|
|
||||||
number = concept.removeprefix("Mat")
|
|
||||||
return name + number
|
|
||||||
|
|
||||||
|
|
||||||
def varname(r, c, rows, cols):
|
|
||||||
"""Get the name of the variable in row r and column c"""
|
|
||||||
if rows == 1:
|
|
||||||
if cols in letters_.keys():
|
|
||||||
return letters_[cols][c]
|
|
||||||
else:
|
|
||||||
return f"x{r+1}"
|
|
||||||
elif cols == 1:
|
|
||||||
if rows in letters_.keys():
|
|
||||||
return letters_[rows][r]
|
|
||||||
else:
|
|
||||||
return f"x{c+1}"
|
|
||||||
else:
|
|
||||||
return f"x{r+1}_{c+1}"
|
|
||||||
|
|
||||||
|
|
||||||
def varnameI(i, rows, cols):
|
|
||||||
"""Get the name of the ith variable"""
|
|
||||||
if rows == 1:
|
|
||||||
if cols in letters_.keys():
|
|
||||||
return letters_[cols][i%cols]
|
|
||||||
else:
|
|
||||||
return f"x{i+1}"
|
|
||||||
elif cols == 1:
|
|
||||||
if rows in letters_.keys():
|
|
||||||
return letters_[rows][i%rows]
|
|
||||||
else:
|
|
||||||
return f"x{i+1}"
|
|
||||||
else:
|
|
||||||
return f"x{i%rows+1}_{i%cols+1}"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def genstring(row: int, col: int, template: str, sep=", "):
|
|
||||||
"""
|
|
||||||
Generate a string from a template for each vector component
|
|
||||||
eg genstring(3, "@ + ") -> x + y + z
|
|
||||||
@C -> varname(1, c, 1, col)
|
|
||||||
@R -> varname(r, 1, row, 1)
|
|
||||||
@ -> varname(r, c, row, col)
|
|
||||||
@c -> c
|
|
||||||
@r -> r
|
|
||||||
|
|
||||||
"""
|
|
||||||
s = ""
|
|
||||||
for r in range(row):
|
|
||||||
for c in range(col):
|
|
||||||
s += template.replace("@r", str(r)).replace("@c", str(c)).replace("@R", varname(r, c, row, 1)).replace("@C", varname(r, c, 1, col)).replace("@", varname(r, c, row, col)) + sep
|
|
||||||
|
|
||||||
s.removesuffix(sep)
|
|
||||||
return s[0:len(s)-len(sep)]
|
|
||||||
|
|
||||||
|
|
||||||
def transformString(s: str, depth: int):
|
|
||||||
"""Add tabs after all but the last line break and before the first char"""
|
|
||||||
return depth * tab + s.replace("\n", "\n" + depth * tab, s.count("\n") - 1)
|
|
||||||
|
|
||||||
|
|
||||||
def getPossiblities(i, a, depth=0):
|
|
||||||
"""
|
|
||||||
get all possibilites to get i by addition of numbers lower than i
|
|
||||||
eg i=3 -> 3, 2+1, 1+2, 1+1+1
|
|
||||||
"""
|
|
||||||
if i == 0:
|
|
||||||
return
|
|
||||||
if i == 1:
|
|
||||||
a.append(str(1))
|
|
||||||
return
|
|
||||||
for j in range(1, i):
|
|
||||||
b = []
|
|
||||||
# print("\t" * depth + "gp: i="+str(i)+" j="+str(j))
|
|
||||||
getPossiblities(i-j, b, depth+1)
|
|
||||||
|
|
||||||
for poss in b:
|
|
||||||
# print("\t"*depth + f"{i}-{j} returned", b)
|
|
||||||
a.append(str(j) + poss)
|
|
||||||
a.append(str(i))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# GENERATORS
|
|
||||||
#
|
|
||||||
def genConstructors(row, col):
|
|
||||||
constructors = []
|
|
||||||
class_ = classname(row, col)
|
|
||||||
|
|
||||||
# default
|
|
||||||
constructors.append(Member(class_, class_, c_temp=Class_T, prefixes=[constexpr], init=genstring(row, col, "@(0)"), comment="Default constructor"))
|
|
||||||
|
|
||||||
# from single scalar
|
|
||||||
constructors.append(Member(class_, class_, c_temp=Class_T, prefixes=[constexpr], m_temp=[["Number", "N"]], args="const N n", init=genstring(row, col, "@(static_cast<T>(n))"), comment="Create from scalar, all components will have value n"))
|
|
||||||
|
|
||||||
# generate a constructor for every possible vector initialization
|
|
||||||
if row == 1 or col == 1:
|
|
||||||
rows_or_cols = max(row, col) # vec and rvec share same variable names
|
|
||||||
size = max(row, col)
|
|
||||||
a = []
|
|
||||||
getPossiblities(size, a)
|
|
||||||
for possiblity in a:
|
|
||||||
n_count = 1 # counts how many numbers appear
|
|
||||||
v_count = 1 # counts how many vectors appear
|
|
||||||
i = 0 # index the member variable to initialize
|
|
||||||
comment = "Create from "
|
|
||||||
templates = []
|
|
||||||
args = ""
|
|
||||||
init = ""
|
|
||||||
|
|
||||||
for nstr in possiblity:
|
|
||||||
n = int(nstr)
|
|
||||||
if n == 1: # if number
|
|
||||||
comment += "n "
|
|
||||||
templates.append(("Number", f"N{n_count}"))
|
|
||||||
args += f"N{n_count} n{n_count}, "
|
|
||||||
init += varnameI(i, row, col) + f"(static_cast<T>(n{n_count})), "
|
|
||||||
n_count += 1
|
|
||||||
i += 1
|
|
||||||
else: # if vector
|
|
||||||
comment += f"vec{n} "
|
|
||||||
args += f"const V{v_count}& v{v_count}, "
|
|
||||||
templates.append((f"Vector{rows_or_cols}", f"V{v_count}"))
|
|
||||||
for j in range(n):
|
|
||||||
init += varnameI(i, rows_or_cols, 1) + "(static_cast<T>(v" + str(v_count) + "." + varnameI(j, rows_or_cols, 1) + ")), "
|
|
||||||
i += 1
|
|
||||||
v_count += 1
|
|
||||||
args = args.removesuffix(", ")
|
|
||||||
init = init.removesuffix(", ")
|
|
||||||
constructors.append(Member(class_, class_, c_temp=Class_T, m_temp=templates, prefixes=[constexpr], args=args, init=init, comment=comment))
|
|
||||||
# constructor for all matrices
|
|
||||||
else:
|
|
||||||
# from scalar
|
|
||||||
constructors.append(Member(class_, class_, c_temp=Class_T, m_temp=[ t.split(" ") for t in genstring(row, col, f"Number N@r_@c").split(", ")], prefixes=[constexpr],
|
|
||||||
args=genstring(row, col, "const N@r_@c @"), init=genstring(row, col, "@(static_cast<T>(@))"), comment="Create from scalars"))
|
|
||||||
|
|
||||||
# from row vec
|
|
||||||
constructors.append(Member(class_, class_, c_temp=Class_T, m_temp=[ t.split(" ") for t in genstring(row, 1, f"RowVector{col} V@r").split(", ")], prefixes=[constexpr],
|
|
||||||
args=genstring(row, 1, "const V@r& v@r"), init=genstring(row, col, "@(static_cast<T>(v@r.@C))"), comment="Create from row vectors"))
|
|
||||||
|
|
||||||
# from col vec
|
|
||||||
constructors.append(Member(class_, class_, c_temp=Class_T, m_temp=[ t. split(" ") for t in genstring(1, col, f"ColumnVector{row} V@c").split(", ")], prefixes=[constexpr],
|
|
||||||
args=genstring(1, col, "const V@c& v@c"), init=genstring(row, col, "@(static_cast<T>(v@c.@R))"), comment="Create from column vectors"))
|
|
||||||
|
|
||||||
return constructors
|
|
||||||
|
|
||||||
|
|
||||||
def genValues(row, col):
|
|
||||||
s = genstring(row, col, "T @;\n", "")
|
|
||||||
return s
|
|
||||||
|
|
||||||
def genAssignment(row, col):
|
|
||||||
# TODO opt idea: memcpy for component wise assignment when types have same size
|
|
||||||
members = []
|
|
||||||
members.append(Member(classname(row, col), "operator=", c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr], ret_type="void",
|
|
||||||
args=f"const {classname(row, col, 'N')}& other", body=genstring(row, col, f"\t@ = static_cast<T>(other.@);\n", "").split("\n"), comment="Component-wise assignment"))
|
|
||||||
|
|
||||||
members.append(Member(classname(row, col), "operator=", c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr], ret_type="void",
|
|
||||||
args="const N& other", body=genstring(row, col, f"\t@ = static_cast<T>(other);\n", "").split("\n"), comment="Assignment from scalar"))
|
|
||||||
|
|
||||||
return members
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ops = {
|
|
||||||
"+": "operator+",
|
|
||||||
"-": "operator-",
|
|
||||||
"%": "operator%",
|
|
||||||
"*": "compWiseMult",
|
|
||||||
"/": "compWiseDiv",
|
|
||||||
}
|
|
||||||
as_ops = {
|
|
||||||
"+=": "operator+=",
|
|
||||||
"-=": "operator-=",
|
|
||||||
"%=": "operator%=",
|
|
||||||
"*=": "compWiseAssMult",
|
|
||||||
"/=": "compWiseAssDiv",
|
|
||||||
}
|
|
||||||
def genArithmeticVectorial(row, col):
|
|
||||||
operators = []
|
|
||||||
for op, opname in ops.items():
|
|
||||||
body = "return " + classname(row, col, "T") + "(" + genstring(row, col, f"@ {op} static_cast<T>(other.@)") + ");"
|
|
||||||
operators.append(Member(classname(row, col), opname, c_temp=Class_T, m_temp=[(concept(row, col), concept(row, col)[0])], prefixes=[constexpr], ret_type=classname(row, col, "T"),
|
|
||||||
args=f"const {concept(row, col)[0]}& other", const=True, body=[body], comment=f"Component-wise {op}"))
|
|
||||||
|
|
||||||
for op, opname in as_ops.items():
|
|
||||||
body = genstring(row, col, f"\t@ {op} static_cast<T>(other.@);", "\n")
|
|
||||||
operators.append(Member(classname(row, col), opname, c_temp=Class_T, m_temp=[(concept(row, col), concept(row, col)[0])], prefixes=[constexpr], ret_type="void",
|
|
||||||
args=f"const {concept(row, col)[0]}& other", body=body.split("\n"), comment=f"Component-wise assignment {op}"))
|
|
||||||
return operators
|
|
||||||
|
|
||||||
def genArithmeticScalar(row, col):
|
|
||||||
operators = []
|
|
||||||
for op, opname in ops.items():
|
|
||||||
body = "return " + classname(row, col, "T") + "(" + genstring(row, col, f"@ {op} static_cast<T>(other)") + ");"
|
|
||||||
operators.append(Member(classname(row, col), opname, c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr], ret_type=classname(row, col, "T"),
|
|
||||||
args=f"const N& other", const=True, body=[body], comment=f"Component-wise {op} with scalar"))
|
|
||||||
for op, opname in as_ops.items():
|
|
||||||
body = genstring(row, col, f"\t@ {op} static_cast<T>(other);", "\n")
|
|
||||||
operators.append(Member(classname(row, col), opname, c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr], ret_type="void",
|
|
||||||
args=f"const N& other", body=body.split("\n"), comment=f"Component-wise assignment {op} from scalar"))
|
|
||||||
return operators
|
|
||||||
|
|
||||||
|
|
||||||
def genComparisonVectorial(row, col):
|
|
||||||
operators = []
|
|
||||||
for op in ["==", "<", ">"]:
|
|
||||||
body = "return " + genstring(row, col, f"@ {op} other.@", " and ") + ";"
|
|
||||||
operators.append(Member(classname(row, col), f"operator{op}", c_temp=Class_T, m_temp=[(concept(row, col), concept(row, col)[0])], prefixes=[constexpr], ret_type="bool",
|
|
||||||
args=f"const {concept(row, col)[0]}& other", const=True, body=[body], comment=f"Component-wise comparison {op} (and)"))
|
|
||||||
for op, antiop in { "!=": "==", "<=": ">", ">=": "<" }.items():
|
|
||||||
body = "return " + genstring(row, col, f"@ {antiop} other.@", " and ") + ";"
|
|
||||||
operators.append(Member(classname(row, col), f"operator{op}", c_temp=Class_T, m_temp=[(concept(row, col), concept(row, col)[0])], prefixes=[constexpr], ret_type="bool",
|
|
||||||
args=f"const {concept(row, col)[0]}& other", const=True, body=[body], comment=f"Component-wise comparison {op} (and)"))
|
|
||||||
return operators
|
|
||||||
|
|
||||||
def genComparisonScalar(row, col):
|
|
||||||
operators = []
|
|
||||||
for op in ["==", "<", ">"]:
|
|
||||||
body = "return " + genstring(row, col, f"@ {op} other", " and ") + ";"
|
|
||||||
operators.append(Member(classname(row, col), f"operator{op}", c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr], ret_type="bool",
|
|
||||||
args=f"const N& other", const=True, body=[body], comment=f"Component-wise comparison {op} (and)"))
|
|
||||||
for op, antiop in { "!=": "==", "<=": ">", ">=": "<" }.items():
|
|
||||||
body = "return " + genstring(row, col, f"@ {antiop} other", " and ") + ";"
|
|
||||||
operators.append(Member(classname(row, col), f"operator{op}", c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr], ret_type="bool",
|
|
||||||
args=f"const N& other", const=True, body=[body], comment=f"Component-wise comparison {op} (and)"))
|
|
||||||
return operators
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getDependecyClasses(row, col):
|
|
||||||
"""
|
|
||||||
Get all class names that row,col class depends on for matrix multplication and the .row() and .column() methods
|
|
||||||
The dependencies will be forward declared in the header and included in the source
|
|
||||||
"""
|
|
||||||
deps = []
|
|
||||||
# for .row(), .column()
|
|
||||||
if row > 1 and col > 1:
|
|
||||||
deps.append(classname(row, 1))
|
|
||||||
deps.append(classname(1, col))
|
|
||||||
|
|
||||||
# for matrix mult
|
|
||||||
for i in range(1, MAX_N + 1):
|
|
||||||
# results from matrix calculations
|
|
||||||
deps.append(classname(row, i))
|
|
||||||
|
|
||||||
# operands from matrix calculations
|
|
||||||
deps.append(classname(col, i))
|
|
||||||
|
|
||||||
deps = list(dict.fromkeys(deps))
|
|
||||||
# remove vec1
|
|
||||||
if classname(1, 1) in deps:
|
|
||||||
deps.remove(classname(1, 1))
|
|
||||||
if classname(row, col) in deps:
|
|
||||||
deps.remove(classname(row, col))
|
|
||||||
deps.sort()
|
|
||||||
return deps
|
|
||||||
|
|
||||||
|
|
||||||
def genArithmeticMatrix(row, col):
|
|
||||||
"""
|
|
||||||
Generate all matrix multiplications.
|
|
||||||
dimensions of result = mat(row, other.col) where col = other.row
|
|
||||||
"""
|
|
||||||
operators = []
|
|
||||||
other_row = col
|
|
||||||
other_cols = [ i for i in range(1, MAX_N + 1) ]
|
|
||||||
for other_col in other_cols:
|
|
||||||
if (row == 1 and other_col == 1) or (other_row == 1 and other_col == 1): # if ret_type or arg is a scalar
|
|
||||||
continue
|
|
||||||
body = classname(row, other_col, "T") + " new_;\n"
|
|
||||||
for r in range(row):
|
|
||||||
for o_c in range(other_col):
|
|
||||||
body += "new_." + varname(r, o_c, row, other_col) + " = "
|
|
||||||
for i in range(col):
|
|
||||||
# print(f"genArithmeticMatrix: {row}x{col} * {other_row}x{other_col}", r, o_c, "->", c)
|
|
||||||
body += varname(r, i, row, col) + " * other." + varname(i, o_c, other_row, other_col) + " + "
|
|
||||||
body = body.removesuffix(" + ") + ";\n"
|
|
||||||
# if scalar, put ret_type creation and assignment in same line
|
|
||||||
body = body.replace("new_;\nnew_." + varname(0, 0, 1, 1) + " =", "new_ =") + "return new_;"
|
|
||||||
arg_concept = concept(other_row, other_col)
|
|
||||||
operators.append(Member(classname(row, col), "operator*", c_temp=Class_T, m_temp=[(arg_concept, arg_concept[0])], prefixes=[constexpr], ret_type=classname(row, other_col, "T"), const=True,
|
|
||||||
args=f"const {arg_concept[0]}& other", body=body.split("\n"), comment=f"Matrix multiplication with {classname(other_row, other_col)} -> {classname(row, other_col)}"))
|
|
||||||
|
|
||||||
return operators
|
|
||||||
|
|
||||||
|
|
||||||
def genSubscription(row, col):
|
|
||||||
operators = []
|
|
||||||
# [i]
|
|
||||||
operators.append(Member(classname(row, col), "operator[]", c_temp=Class_T, prefixes=[constexpr], ret_type="T",
|
|
||||||
args="std::size_t i", const=True, body=[f"return *(&{varname(0, 0, row, col)} + sizeof(T) * i);"], comment="Get the ith element. i starts at 0"))
|
|
||||||
|
|
||||||
if row > 1 and col > 1:
|
|
||||||
# at(row, col)
|
|
||||||
body = f"return *(&{varname(0, 0, row, col)} + (row * {row} + col * {col}) * sizeof(T));"
|
|
||||||
operators.append(Member(classname(row, col), "at", c_temp=Class_T, prefixes=[constexpr], ret_type="T",
|
|
||||||
args="std::size_t row, std::size_t col", const=True, body=[body], comment="Get the element at row and col. row and col start at 0"))
|
|
||||||
|
|
||||||
# row()
|
|
||||||
body = f"return {classname(1, col, 'T')}(" + genstring(1, col, f"*(&{varname(0, 0, row, col)} + ({row} * @c + i) * sizeof(T))") + ");"
|
|
||||||
operators.append(Member(classname(row, col), "row", c_temp=Class_T, prefixes=[constexpr], ret_type=classname(1, col, 'T'),
|
|
||||||
args="std::size_t i", const=True, body=[body], comment="Get the ith row as column vector. i starts at 0"))
|
|
||||||
|
|
||||||
# column()
|
|
||||||
body = f"return {classname(row, 1, 'T')}(" + genstring(row, 1, f"*(&{varname(0, 0, row, col)} + ({col} * @r + i) * sizeof(T))") + ");"
|
|
||||||
operators.append(Member(classname(row, col), "column", c_temp=Class_T, prefixes=[constexpr], ret_type=classname(row, 1, 'T'),
|
|
||||||
args="std::size_t i", const=True, body=[body], comment="Get the ith column as row vector. i starts at 0"))
|
|
||||||
|
|
||||||
return operators
|
|
||||||
|
|
||||||
|
|
||||||
def genIterator(row, col):
|
|
||||||
members = []
|
|
||||||
its = [
|
|
||||||
("cbegin", "return Iterator(const_cast<T*>(&" + varname(0, 0, row, col) + "));", "Return an Iterator to the first element"),
|
|
||||||
("cend", "return Iterator(const_cast<T*>(&" + varname(row-1, col-1, row, col) + " + sizeof(T)));", "Return an Iterator past the last element"),
|
|
||||||
("begin", "return Iterator(const_cast<T*>(&" + varname(0, 0, row, col) + "));", "Return an Iterator to the first element"),
|
|
||||||
("end", "return Iterator(const_cast<T*>(&" + varname(row-1, col-1, row, col) + " + sizeof(T)));", "Return an Iterator past the last element"),
|
|
||||||
]
|
|
||||||
for name, body, comment in its:
|
|
||||||
members.append(Member(classname(row, col), name, c_temp=Class_T, prefixes=[constexpr], ret_type="Iterator<T>", const=True, body=[body], comment=comment))
|
|
||||||
return members
|
|
||||||
|
|
||||||
|
|
||||||
def genFunctional(row, col):
|
|
||||||
members = []
|
|
||||||
# abs
|
|
||||||
members.append(Member(classname(row, col), "abs", c_temp=Class_T, prefixes=[constexpr, inline], ret_type=float_type,
|
|
||||||
const=True, body=["return std::sqrt(" + genstring(row, col, f"static_cast<{float_type}>(@ * @)", " + ") + ");"], comment="Returns the absolute value of the vector (sqrt of scalar product with itself)"))
|
|
||||||
|
|
||||||
if (row == 2 and col == 1) or (col == 2 and row == 1):
|
|
||||||
# ratio
|
|
||||||
members.append(Member(classname(row, col), "ratio", c_temp=Class_T, prefixes=[constexpr, inline], ret_type=float_type,
|
|
||||||
const=True, body=["return static_cast<" + float_type + f">({varnameI(0, row, col)}) / {varnameI(1, row, col)};"], comment=f"Returns x/y"))
|
|
||||||
|
|
||||||
# inverse ratio
|
|
||||||
members.append(Member(classname(row, col), "invereseRatio", c_temp=Class_T, prefixes=[constexpr, inline], ret_type=float_type,
|
|
||||||
const=True, body=["return static_cast<" + float_type + f">({varnameI(1, row, col)}) / {varnameI(0, row, col)};"], comment=f"Returns y/x"))
|
|
||||||
|
|
||||||
|
|
||||||
# min
|
|
||||||
members.append(Member(classname(row, col), "min", c_temp=Class_T, prefixes=[constexpr, inline], ret_type="T", const=True,
|
|
||||||
body=["return *std::min_element(cbegin(), cend());"], comment="Returns the min of the components"))
|
|
||||||
|
|
||||||
# max
|
|
||||||
members.append(Member(classname(row, col), "max", c_temp=Class_T, prefixes=[constexpr, inline], ret_type="T", const=True,
|
|
||||||
body=["return *std::max_element(cbegin(), cend());"], comment="Returns the max of the components"))
|
|
||||||
|
|
||||||
# dot
|
|
||||||
body = f"return " + genstring(row, col, "@ * static_cast<T>(other.@)", " + ") + ";"
|
|
||||||
members.append(Member(classname(row, col), "dot", c_temp=Class_T, m_temp=[Number_N], prefixes=[constexpr, inline], ret_type="T", const=True,
|
|
||||||
args=f"const {classname(row, col, 'N')}& other", body=[body], comment="Scalar product (x1 * other.x1 + x2 * other.x2 ...)"))
|
|
||||||
return members
|
|
||||||
|
|
||||||
|
|
||||||
def genUtility(row, col):
|
|
||||||
s = "\n"
|
|
||||||
# s = "std::string to_string() const { return \"(\" + " + genstring(row, col, "std::to_string(@)", " + \", \" + ") + " + \")\"; };\n"
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def genUsing(row, col):
|
|
||||||
global typeShorts
|
|
||||||
s = ""
|
|
||||||
for t, c in typeShorts.items():
|
|
||||||
s += f"using {classname(row, col)}{c} = {classname(row, col)}<{t}>;\n"
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# TEMPLATE INSTANTIATION
|
|
||||||
#
|
|
||||||
def getTemplateInsts(method_name, instantiations, templates, types, depth=0):
|
|
||||||
""" method name must be like this:
|
|
||||||
constexpr ret_type Class<T>::name<U>(int, U) const;"""
|
|
||||||
if depth < len(templates):
|
|
||||||
if templates[depth][0] == "Number":
|
|
||||||
for n in types:
|
|
||||||
newmethod = method_name.replace(
|
|
||||||
f"<{templates[depth][1]}>", f"<{n}>").replace(
|
|
||||||
f"{templates[depth][1]} ", f"{n} ").replace(
|
|
||||||
f"{templates[depth][1]})", f"{n})").replace(
|
|
||||||
f"{templates[depth][1]},", f"{n},").replace(
|
|
||||||
f"{templates[depth][1]}& ", f"{n}& ").replace(
|
|
||||||
f"{templates[depth][1]}&)", f"{n}&)").replace(
|
|
||||||
f"{templates[depth][1]}&,", f"{n}&,")
|
|
||||||
getTemplateInsts(newmethod, instantiations, templates, types, depth+1)
|
|
||||||
else:
|
|
||||||
for n in types:
|
|
||||||
newmethod = method_name.replace(
|
|
||||||
f"<{templates[depth][1]}>", f"<{classnameFromConcept(templates[depth][0])}<{n}>>").replace(
|
|
||||||
f"{templates[depth][1]} ", f"{classnameFromConcept(templates[depth][0])}<{n}> ").replace(
|
|
||||||
f"{templates[depth][1]})", f"{classnameFromConcept(templates[depth][0])}<{n}> ").replace(
|
|
||||||
f"{templates[depth][1]},", f"{classnameFromConcept(templates[depth][0])}<{n}> ").replace(
|
|
||||||
f"{templates[depth][1]}& ", f"{classnameFromConcept(templates[depth][0])}<{n}>& ").replace(
|
|
||||||
f"{templates[depth][1]}&)", f"{classnameFromConcept(templates[depth][0])}<{n}>&)").replace(
|
|
||||||
f"{templates[depth][1]}&,", f"{classnameFromConcept(templates[depth][0])}<{n}>&,")
|
|
||||||
getTemplateInsts(newmethod, instantiations, templates, types, depth+1)
|
|
||||||
elif depth == len(templates) and len(templates)> 0:
|
|
||||||
instantiations.append("template " + method_name + ";")
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# GENERATION
|
|
||||||
#
|
|
||||||
def generateFiles(row, col):
|
|
||||||
hd = 0 # header depth
|
|
||||||
sd = 0 # source and template depth
|
|
||||||
|
|
||||||
# header
|
|
||||||
h = "#pragma once\n\n"
|
|
||||||
# source
|
|
||||||
s = "#include \"" + classname(row, col) + ".hpp\"\n\n"
|
|
||||||
# template instantiations
|
|
||||||
t = f"// template instantiations for {classname(row, col)}\n\n"
|
|
||||||
|
|
||||||
dependencies = getDependecyClasses(row, col)
|
|
||||||
for dep in dependencies:
|
|
||||||
s += "#include \"" + dep + ".hpp\"\n"
|
|
||||||
s += "\n"
|
|
||||||
for i in headerIncludes:
|
|
||||||
h += "#include " + i + "\n"
|
|
||||||
h += "\n"
|
|
||||||
for i in sourceIncludes:
|
|
||||||
s += "#include " + i + "\n"
|
|
||||||
s += "\n"
|
|
||||||
if namespace:
|
|
||||||
h += "namespace " + namespace + " {\n\n"
|
|
||||||
s += "namespace " + namespace + " {\n\n"
|
|
||||||
t += "namespace " + namespace + " {\n\n"
|
|
||||||
hd += 1
|
|
||||||
sd += 1
|
|
||||||
|
|
||||||
# template instantiations
|
|
||||||
if include_template_instantiations:
|
|
||||||
for typ in templateInstantiationTypes:
|
|
||||||
t += transformString("template class " + classname(row, col, typ) + ";\n", 0)
|
|
||||||
t += "\n"
|
|
||||||
|
|
||||||
# forward declarations
|
|
||||||
h += transformString("// Forward declarations\n", hd)
|
|
||||||
for dep in dependencies:
|
|
||||||
h += transformString("template<Number T>\nclass " + dep + ";\n", hd)
|
|
||||||
h += "\n"
|
|
||||||
|
|
||||||
header, source, templates = generateMatrix(row, col, hd, sd)
|
|
||||||
h += header + "\n"
|
|
||||||
s += source + "\n"
|
|
||||||
t += templates + "\n"
|
|
||||||
|
|
||||||
if include_static_asserts:
|
|
||||||
h += transformString("static_assert(" + concept(row, col, classname(row, col, "int")) +", \"" + classname(row, col, "int") + " does not satisfy the concept " + concept(row, col) + "\");\n", hd)
|
|
||||||
|
|
||||||
if namespace:
|
|
||||||
hd -= 1
|
|
||||||
sd -= 1
|
|
||||||
h += transformString("} // namespace " + namespace + "\n", hd)
|
|
||||||
s += transformString("} // namespace " + namespace + "\n", hd)
|
|
||||||
t += transformString("} // namespace " + namespace + "\n", hd)
|
|
||||||
|
|
||||||
for i in range(1, 5):
|
|
||||||
h = h.replace("\n" + i * tab + "\n", "\n\n")
|
|
||||||
s = s.replace("\n" + i * tab + "\n", "\n\n")
|
|
||||||
|
|
||||||
return h, s, t
|
|
||||||
|
|
||||||
|
|
||||||
def append(header:str, source:str, templates:str, members:list[Member], hdepth:int, sdepth:int):
|
|
||||||
for m in members:
|
|
||||||
split = True
|
|
||||||
if m.isConstructor() or (len(m.body) < 2 and len(m.m_temp) > 1):
|
|
||||||
split = False
|
|
||||||
|
|
||||||
if split:
|
|
||||||
header += m.defintionH(hdepth)
|
|
||||||
source += m.source(sdepth)
|
|
||||||
templates += m.templateInstantiations()
|
|
||||||
else:
|
|
||||||
header += m.header(hdepth)
|
|
||||||
return header, source, templates
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generateMatrix(r, c, hd, sd):
|
|
||||||
h = transformString(
|
|
||||||
"""/**
|
|
||||||
* @brief Class containing $ numbers
|
|
||||||
*/
|
|
||||||
""".replace("$", str(r*c)), hd)
|
|
||||||
h += transformString("""template<Number T>
|
|
||||||
class $ {
|
|
||||||
public:
|
|
||||||
""".replace("$", classname(r, c)), hd)
|
|
||||||
|
|
||||||
s = transformString("""//
|
|
||||||
// CLASS $
|
|
||||||
//
|
|
||||||
""".replace("$", classname(r, c)), sd)
|
|
||||||
|
|
||||||
|
|
||||||
t = ""
|
|
||||||
|
|
||||||
hd += 1 # header depth
|
|
||||||
# sd += 1 # source depth
|
|
||||||
|
|
||||||
if classname(r, c).startswith("vec"):
|
|
||||||
h += transformString("/// just to satisfy concept ColumnVector\nusing isColumnVector = T;\n", hd + 1)
|
|
||||||
elif classname(r, c).startswith("rvec"):
|
|
||||||
h += transformString("/// just to satisfy concept RowVector\nusing isRowVector = T;\n", hd + 1)
|
|
||||||
|
|
||||||
h += transformString("// Constructors\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genConstructors(r, c), hd+1, sd)
|
|
||||||
|
|
||||||
h += transformString("// Values\n", hd)
|
|
||||||
h += transformString(genValues(r, c), hd+1)
|
|
||||||
|
|
||||||
h += transformString("// Assignment\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genAssignment(r, c), hd+1, sd)
|
|
||||||
|
|
||||||
h += transformString("// Arithmetic\n", hd-1)
|
|
||||||
h += transformString("// Vectorial\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genArithmeticVectorial(r, c), hd+1, sd)
|
|
||||||
h += transformString("// Scalar\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genArithmeticScalar(r, c),hd+1, sd)
|
|
||||||
h += transformString("// Matrix Multiplication\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genArithmeticMatrix(r, c), hd+1, sd)
|
|
||||||
|
|
||||||
h += transformString("// Comparison\n", hd-1)
|
|
||||||
h += transformString("// Vectorial\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genComparisonVectorial(r, c),hd+1, sd)
|
|
||||||
h += transformString("// Scalar\n", hd)
|
|
||||||
h, s, t = append(h, s, t, genComparisonScalar(r, c), hd+1, sd)
|
|
||||||
|
|
||||||
|
|
||||||
h += transformString("// Functional\n", hd - 1)
|
|
||||||
h, s, t = append(h, s, t, genFunctional(r, c), hd+1, sd)
|
|
||||||
|
|
||||||
h += transformString("// Utility\n", hd-1)
|
|
||||||
h, s, t = append(h, s, t, genSubscription(r, c), hd+1, sd)
|
|
||||||
h, s, t = append(h, s, t, genIterator(r, c), hd + 1, sd)
|
|
||||||
|
|
||||||
h += transformString("}; // " + classname(r, c) + "\n\n", hd - 1)
|
|
||||||
h += transformString(genUsing(r, c), hd - 1)
|
|
||||||
h += "\n"
|
|
||||||
s += "\n"
|
|
||||||
t += "\n"
|
|
||||||
|
|
||||||
return h, s, t
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# CONCEPTS
|
|
||||||
#
|
|
||||||
def generateConceptsFile(row, col):
|
|
||||||
# Number
|
|
||||||
s = "#pragma once\n\n"
|
|
||||||
s += "#include <concepts>\n\n"
|
|
||||||
s += "// Number\n"
|
|
||||||
s += "template<typename T>\n"
|
|
||||||
s += "concept Number = std::integral<T> or std::floating_point<T>;\n\n"
|
|
||||||
|
|
||||||
s += "// VectorX\n"
|
|
||||||
for i in range(2, max(row, col)):
|
|
||||||
s += "template<typename T>\n"
|
|
||||||
# s += "concept Vector" + str(i) + " = requires(T t) { " + genstring(i, 1, "{ t.@ } -> Number; ", "") + "};\n\n"
|
|
||||||
s += "concept Vector" + str(i) + " = requires(T t) {\n" + genstring(i, 1, tab + "requires Number<decltype(t.@)>;\n", "") + "} and requires(T t) { sizeof(t." + varname(0, 0, i, 1) + ") == (sizeof(T) * " + str(i) + "); };\n\n"
|
|
||||||
s += "// RowVectorX\n"
|
|
||||||
for i in range(2, max(row, col)):
|
|
||||||
s += "template<typename T>\n"
|
|
||||||
s += "concept RowVector" + str(i) + " = Vector" + str(i) + "<T> and Number<typename T::isRowVector>;\n\n"
|
|
||||||
s += "// ColumnVectorX\n"
|
|
||||||
for i in range(2, max(row, col)):
|
|
||||||
s += "template<typename T>\n"
|
|
||||||
s += "concept ColumnVector" + str(i) + " = Vector" + str(i) + "<T> and Number<typename T::isColumnVector>;\n\n"
|
|
||||||
s += "// Matrices\n"
|
|
||||||
for r in range(2, row):
|
|
||||||
for c in range(2, col):
|
|
||||||
s += "template<typename T>\n"
|
|
||||||
# s += "concept " + concept(r, c) + " = requires(T t) { t -> template " + classname(r, c) + "; };\n"
|
|
||||||
s += "concept " + concept(r, c) + " = requires(T t) {\n" + genstring(r, c, tab + "requires Number<decltype(t.@)>;\n", "") + "};\n" # and requires(T t) { sizeof(t." + varname(0, 0, r, c) + ") == (sizeof(T) * " + str(r*c) + "); };\n\n"
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
## ITERATORS
|
|
||||||
##
|
|
||||||
#def generateIteratorFile():
|
|
||||||
# i = "#pragma once\n"
|
|
||||||
# if namespace:
|
|
||||||
# i += f"namespace {namespace} " + "{\n"
|
|
||||||
|
|
||||||
# i += """
|
|
||||||
|
|
||||||
#template<typename T>
|
|
||||||
#struct Iterator {
|
|
||||||
# public:
|
|
||||||
# using value_type = T;
|
|
||||||
# Iterator() : ptr(nullptr) {};
|
|
||||||
# Iterator(T* ptr) : ptr(ptr) {};
|
|
||||||
# T& operator*() const { return *ptr; };
|
|
||||||
# Iterator& operator=(const Iterator& other) {
|
|
||||||
# ptr = other.ptr;
|
|
||||||
# return *this;
|
|
||||||
# };
|
|
||||||
# Iterator& operator++() { ptr += sizeof(T); return *this; };
|
|
||||||
# Iterator operator++(int) { auto copy = *this; ptr += sizeof(T); return copy; };
|
|
||||||
# friend int operator-(Iterator lhs, Iterator rhs) {
|
|
||||||
# return lhs.ptr - rhs.ptr;
|
|
||||||
# };
|
|
||||||
# bool operator==(const Iterator& other) const { return ptr == other.ptr; };
|
|
||||||
# // bool operator!=(const Iterator& other) const { return ptr != other.ptr; };
|
|
||||||
# private:
|
|
||||||
# T* ptr;
|
|
||||||
#}; // Iterator
|
|
||||||
#"""
|
|
||||||
|
|
||||||
# if include_static_asserts:
|
|
||||||
# i += 'static_assert(std::forward_iterator<Iterator<int>>, "Iterator not a forward range.");'
|
|
||||||
# if namespace:
|
|
||||||
# i += "} // namespace " + namespace + "\n"
|
|
||||||
# return i
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# MAIN
|
|
||||||
#
|
|
||||||
def write_file(s, filename):
|
|
||||||
if path.exists(filename):
|
|
||||||
answer = "y"
|
|
||||||
# answer = input("File " + filename + "already exists. Overwrite? (y/n): ")
|
|
||||||
if answer not in "yY":
|
|
||||||
return
|
|
||||||
|
|
||||||
with open(filename, "w") as file:
|
|
||||||
file.write(s)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if not path.isdir(directory):
|
|
||||||
mkdir(directory)
|
|
||||||
todo = [ [i, j] for i in range(1, MAX_N + 1) for j in range(1, MAX_N + 1)]
|
|
||||||
todo.remove([1, 1]) # remove [1, 1]
|
|
||||||
for r, c in todo:
|
|
||||||
filename = directory + "/" + classname(r, c)
|
|
||||||
header, source, templates = generateFiles(r, c)
|
|
||||||
if include_template_instantiations:
|
|
||||||
write_file(templates, filename + ".tpp")
|
|
||||||
source += "\n#include \"" + classname(r, c) + ".tpp\""
|
|
||||||
write_file(header, filename + ".hpp")
|
|
||||||
write_file(source, filename + ".cpp")
|
|
||||||
|
|
||||||
write_file(generateConceptsFile(MAX_N + 1, MAX_N + 1), directory + "/" + "concepts.hpp")
|
|
||||||
# write_file(generateIteratorFile(), directory + "/" + "iterator.hpp")
|
|
0
src/.doxygen_config
Normal file → Executable file
0
src/.doxygen_config
Normal file → Executable file
@ -25,7 +25,7 @@ default: $(LIB)
|
|||||||
echo $(OBJECTS)
|
echo $(OBJECTS)
|
||||||
|
|
||||||
# with debug flags
|
# with debug flags
|
||||||
debug: CXXFLAGS += -g +Wextra # -DDEBUG
|
debug: CXXFLAGS += -g # -DDEBUG
|
||||||
debug: default
|
debug: default
|
||||||
|
|
||||||
$(LIB): $(OBJECT_DIRS) $(OBJECTS)
|
$(LIB): $(OBJECT_DIRS) $(OBJECTS)
|
||||||
@ -51,7 +51,7 @@ uninstall:
|
|||||||
-rm $(DESTDIR)/usr/lib/$(subst ../,,$(LIB))
|
-rm $(DESTDIR)/usr/lib/$(subst ../,,$(LIB))
|
||||||
-rm $(DESTDIR)/usr/bin/gz-enum-str
|
-rm $(DESTDIR)/usr/bin/gz-enum-str
|
||||||
-rm -r $(DESTDIR)/usr/include/gz-util/
|
-rm -r $(DESTDIR)/usr/include/gz-util/
|
||||||
-rm $(OBJECT_DIR)/*.stamp
|
-rm -f $(OBJECT_DIR)/*.stamp
|
||||||
|
|
||||||
|
|
||||||
$(OBJECT_DIR)/%.stamp: %.hpp $(OBJECT_DIR)
|
$(OBJECT_DIR)/%.stamp: %.hpp $(OBJECT_DIR)
|
||||||
@ -63,7 +63,7 @@ $(OBJECT_DIR)/%.stamp: %.hpp $(OBJECT_DIR)
|
|||||||
#
|
#
|
||||||
# remove all object and dependecy files
|
# remove all object and dependecy files
|
||||||
clean:
|
clean:
|
||||||
-rm -r $(OBJECT_DIR)
|
-rm -rf $(OBJECT_DIR)
|
||||||
-rm $(LIB)
|
-rm $(LIB)
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
|
@ -1,159 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <concepts>
|
|
||||||
|
|
||||||
// Number
|
|
||||||
template<typename T>
|
|
||||||
concept Number = std::integral<T> or std::floating_point<T>;
|
|
||||||
|
|
||||||
// VectorX
|
|
||||||
template<typename T>
|
|
||||||
concept Vector2 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x)>;
|
|
||||||
requires Number<decltype(t.y)>;
|
|
||||||
} and requires(T t) { sizeof(t.x) == (sizeof(T) * 2); };
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
concept Vector3 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x)>;
|
|
||||||
requires Number<decltype(t.y)>;
|
|
||||||
requires Number<decltype(t.z)>;
|
|
||||||
} and requires(T t) { sizeof(t.x) == (sizeof(T) * 3); };
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
concept Vector4 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x)>;
|
|
||||||
requires Number<decltype(t.y)>;
|
|
||||||
requires Number<decltype(t.z)>;
|
|
||||||
requires Number<decltype(t.w)>;
|
|
||||||
} and requires(T t) { sizeof(t.x) == (sizeof(T) * 4); };
|
|
||||||
|
|
||||||
// RowVectorX
|
|
||||||
template<typename T>
|
|
||||||
concept RowVector2 = Vector2<T> and Number<typename T::isRowVector>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
concept RowVector3 = Vector3<T> and Number<typename T::isRowVector>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
concept RowVector4 = Vector4<T> and Number<typename T::isRowVector>;
|
|
||||||
|
|
||||||
// ColumnVectorX
|
|
||||||
template<typename T>
|
|
||||||
concept ColumnVector2 = Vector2<T> and Number<typename T::isColumnVector>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
concept ColumnVector3 = Vector3<T> and Number<typename T::isColumnVector>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
concept ColumnVector4 = Vector4<T> and Number<typename T::isColumnVector>;
|
|
||||||
|
|
||||||
// Matrices
|
|
||||||
template<typename T>
|
|
||||||
concept Mat2x2 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat2x3 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x1_3)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x2_3)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat2x4 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x1_3)>;
|
|
||||||
requires Number<decltype(t.x1_4)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x2_3)>;
|
|
||||||
requires Number<decltype(t.x2_4)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat3x2 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x3_1)>;
|
|
||||||
requires Number<decltype(t.x3_2)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat3x3 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x1_3)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x2_3)>;
|
|
||||||
requires Number<decltype(t.x3_1)>;
|
|
||||||
requires Number<decltype(t.x3_2)>;
|
|
||||||
requires Number<decltype(t.x3_3)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat3x4 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x1_3)>;
|
|
||||||
requires Number<decltype(t.x1_4)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x2_3)>;
|
|
||||||
requires Number<decltype(t.x2_4)>;
|
|
||||||
requires Number<decltype(t.x3_1)>;
|
|
||||||
requires Number<decltype(t.x3_2)>;
|
|
||||||
requires Number<decltype(t.x3_3)>;
|
|
||||||
requires Number<decltype(t.x3_4)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat4x2 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x3_1)>;
|
|
||||||
requires Number<decltype(t.x3_2)>;
|
|
||||||
requires Number<decltype(t.x4_1)>;
|
|
||||||
requires Number<decltype(t.x4_2)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat4x3 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x1_3)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x2_3)>;
|
|
||||||
requires Number<decltype(t.x3_1)>;
|
|
||||||
requires Number<decltype(t.x3_2)>;
|
|
||||||
requires Number<decltype(t.x3_3)>;
|
|
||||||
requires Number<decltype(t.x4_1)>;
|
|
||||||
requires Number<decltype(t.x4_2)>;
|
|
||||||
requires Number<decltype(t.x4_3)>;
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
concept Mat4x4 = requires(T t) {
|
|
||||||
requires Number<decltype(t.x1_1)>;
|
|
||||||
requires Number<decltype(t.x1_2)>;
|
|
||||||
requires Number<decltype(t.x1_3)>;
|
|
||||||
requires Number<decltype(t.x1_4)>;
|
|
||||||
requires Number<decltype(t.x2_1)>;
|
|
||||||
requires Number<decltype(t.x2_2)>;
|
|
||||||
requires Number<decltype(t.x2_3)>;
|
|
||||||
requires Number<decltype(t.x2_4)>;
|
|
||||||
requires Number<decltype(t.x3_1)>;
|
|
||||||
requires Number<decltype(t.x3_2)>;
|
|
||||||
requires Number<decltype(t.x3_3)>;
|
|
||||||
requires Number<decltype(t.x3_4)>;
|
|
||||||
requires Number<decltype(t.x4_1)>;
|
|
||||||
requires Number<decltype(t.x4_2)>;
|
|
||||||
requires Number<decltype(t.x4_3)>;
|
|
||||||
requires Number<decltype(t.x4_4)>;
|
|
||||||
};
|
|
@ -1,322 +0,0 @@
|
|||||||
#include "mat2x2.hpp"
|
|
||||||
|
|
||||||
#include "mat2x3.hpp"
|
|
||||||
#include "mat2x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "vec2.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat2x2
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::operator=(const mat2x2<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator+(const M& other) const {
|
|
||||||
return mat2x2<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator-(const M& other) const {
|
|
||||||
return mat2x2<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator%(const M& other) const {
|
|
||||||
return mat2x2<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat2x2<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat2x2<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void mat2x2<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void mat2x2<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void mat2x2<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void mat2x2<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void mat2x2<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator+(const N& other) const {
|
|
||||||
return mat2x2<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator-(const N& other) const {
|
|
||||||
return mat2x2<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator%(const N& other) const {
|
|
||||||
return mat2x2<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat2x2<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat2x2<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x2<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> mat2x2<T>::operator*(const C& other) const {
|
|
||||||
vec2<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x2<T>::operator*(const M& other) const {
|
|
||||||
mat2x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x2<T>::operator*(const M& other) const {
|
|
||||||
mat2x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x2<T>::operator*(const M& other) const {
|
|
||||||
mat2x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool mat2x2<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool mat2x2<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool mat2x2<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool mat2x2<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool mat2x2<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool mat2x2<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x2<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x2<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x2<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x2<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x2<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x2<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat2x2<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat2x2<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat2x2<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat2x2<T>::dot(const mat2x2<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat2x2<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat2x2<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 2 + col * 2) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec2<T> mat2x2<T>::row(std::size_t i) const {
|
|
||||||
return rvec2<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec2<T> mat2x2<T>::column(std::size_t i) const {
|
|
||||||
return vec2<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x2<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x2<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x2_2 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x2<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x2<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x2_2 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat2x2.tpp"
|
|
@ -1,207 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 4 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat2x2()
|
|
||||||
: x1_1(0), x1_2(0), x2_1(0), x2_2(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N1_0, Number N1_1>
|
|
||||||
constexpr mat2x2(const N0_0 x1_1, const N0_1 x1_2, const N1_0 x2_1, const N1_1 x2_2)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector2 V0, RowVector2 V1>
|
|
||||||
constexpr mat2x2(const V0& v0, const V1& v1)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector2 V0, ColumnVector2 V1>
|
|
||||||
constexpr mat2x2(const V0& v0, const V1& v1)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat2x2<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x2<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec2 -> vec2
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat2x2 -> mat2x2
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat2x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x3 -> mat2x3
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x4 -> mat2x4
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat2x2<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec2<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec2<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat2x2
|
|
||||||
|
|
||||||
using mat2x2f = mat2x2<float>;
|
|
||||||
using mat2x2d = mat2x2<double>;
|
|
||||||
using mat2x2i = mat2x2<int>;
|
|
||||||
using mat2x2u = mat2x2<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat2x2<mat2x2<int>>, "mat2x2<int> does not satisfy the concept Mat2x2");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat2x2.tpp
4559
src/math/mat2x2.tpp
File diff suppressed because it is too large
Load Diff
@ -1,350 +0,0 @@
|
|||||||
#include "mat2x3.hpp"
|
|
||||||
|
|
||||||
#include "mat2x2.hpp"
|
|
||||||
#include "mat2x4.hpp"
|
|
||||||
#include "mat3x2.hpp"
|
|
||||||
#include "mat3x3.hpp"
|
|
||||||
#include "mat3x4.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "vec2.hpp"
|
|
||||||
#include "vec3.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat2x3
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::operator=(const mat2x3<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x1_3 = static_cast<T>(other.x1_3);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x2_3 = static_cast<T>(other.x2_3);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x1_3 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x2_3 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator+(const M& other) const {
|
|
||||||
return mat2x3<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator-(const M& other) const {
|
|
||||||
return mat2x3<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator%(const M& other) const {
|
|
||||||
return mat2x3<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat2x3<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat2x3<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void mat2x3<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x1_3 += static_cast<T>(other.x1_3);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x2_3 += static_cast<T>(other.x2_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void mat2x3<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 -= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 -= static_cast<T>(other.x2_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void mat2x3<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 %= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 %= static_cast<T>(other.x2_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void mat2x3<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 *= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 *= static_cast<T>(other.x2_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void mat2x3<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 /= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 /= static_cast<T>(other.x2_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator+(const N& other) const {
|
|
||||||
return mat2x3<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator-(const N& other) const {
|
|
||||||
return mat2x3<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator%(const N& other) const {
|
|
||||||
return mat2x3<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat2x3<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat2x3<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x1_3 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x2_3 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x1_3 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x2_3 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x1_3 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x2_3 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x1_3 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x2_3 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x3<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x1_3 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x2_3 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec2<T> mat2x3<T>::operator*(const C& other) const {
|
|
||||||
vec2<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x3<T>::operator*(const M& other) const {
|
|
||||||
mat2x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x3<T>::operator*(const M& other) const {
|
|
||||||
mat2x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x3<T>::operator*(const M& other) const {
|
|
||||||
mat2x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool mat2x3<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool mat2x3<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool mat2x3<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool mat2x3<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool mat2x3<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool mat2x3<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x3<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x3<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x3<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x3<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x3<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x3<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat2x3<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat2x3<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat2x3<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat2x3<T>::dot(const mat2x3<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat2x3<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat2x3<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 2 + col * 3) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec3<T> mat2x3<T>::row(std::size_t i) const {
|
|
||||||
return rvec3<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec2<T> mat2x3<T>::column(std::size_t i) const {
|
|
||||||
return vec2<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x3<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x3<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x2_3 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x3<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x3<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x2_3 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat2x3.tpp"
|
|
@ -1,217 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class vec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 6 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat2x3()
|
|
||||||
: x1_1(0), x1_2(0), x1_3(0), x2_1(0), x2_2(0), x2_3(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N0_2, Number N1_0, Number N1_1, Number N1_2>
|
|
||||||
constexpr mat2x3(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector3 V0, RowVector3 V1>
|
|
||||||
constexpr mat2x3(const V0& v0, const V1& v1)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector2 V0, ColumnVector2 V1, ColumnVector2 V2>
|
|
||||||
constexpr mat2x3(const V0& v0, const V1& v1, const V2& v2)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x1_3;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x2_3;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat2x3<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat2x3<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x3<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec3 -> vec2
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec2<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat3x2 -> mat2x2
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat2x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x3 -> mat2x3
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat2x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x4 -> mat2x4
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat2x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat2x3<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec3<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec2<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat2x3
|
|
||||||
|
|
||||||
using mat2x3f = mat2x3<float>;
|
|
||||||
using mat2x3d = mat2x3<double>;
|
|
||||||
using mat2x3i = mat2x3<int>;
|
|
||||||
using mat2x3u = mat2x3<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat2x3<mat2x3<int>>, "mat2x3<int> does not satisfy the concept Mat2x3");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat2x3.tpp
4559
src/math/mat2x3.tpp
File diff suppressed because it is too large
Load Diff
@ -1,374 +0,0 @@
|
|||||||
#include "mat2x4.hpp"
|
|
||||||
|
|
||||||
#include "mat2x2.hpp"
|
|
||||||
#include "mat2x3.hpp"
|
|
||||||
#include "mat4x2.hpp"
|
|
||||||
#include "mat4x3.hpp"
|
|
||||||
#include "mat4x4.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
#include "vec2.hpp"
|
|
||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat2x4
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::operator=(const mat2x4<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x1_3 = static_cast<T>(other.x1_3);
|
|
||||||
x1_4 = static_cast<T>(other.x1_4);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x2_3 = static_cast<T>(other.x2_3);
|
|
||||||
x2_4 = static_cast<T>(other.x2_4);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x1_3 = static_cast<T>(other);
|
|
||||||
x1_4 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x2_3 = static_cast<T>(other);
|
|
||||||
x2_4 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator+(const M& other) const {
|
|
||||||
return mat2x4<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x1_4 + static_cast<T>(other.x1_4), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x2_4 + static_cast<T>(other.x2_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator-(const M& other) const {
|
|
||||||
return mat2x4<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x1_4 - static_cast<T>(other.x1_4), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x2_4 - static_cast<T>(other.x2_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator%(const M& other) const {
|
|
||||||
return mat2x4<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x1_4 % static_cast<T>(other.x1_4), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x2_4 % static_cast<T>(other.x2_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat2x4<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x1_4 * static_cast<T>(other.x1_4), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x2_4 * static_cast<T>(other.x2_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat2x4<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x1_4 / static_cast<T>(other.x1_4), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x2_4 / static_cast<T>(other.x2_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void mat2x4<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x1_3 += static_cast<T>(other.x1_3);
|
|
||||||
x1_4 += static_cast<T>(other.x1_4);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x2_3 += static_cast<T>(other.x2_3);
|
|
||||||
x2_4 += static_cast<T>(other.x2_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void mat2x4<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 -= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 -= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 -= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 -= static_cast<T>(other.x2_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void mat2x4<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 %= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 %= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 %= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 %= static_cast<T>(other.x2_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void mat2x4<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 *= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 *= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 *= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 *= static_cast<T>(other.x2_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void mat2x4<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 /= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 /= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 /= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 /= static_cast<T>(other.x2_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator+(const N& other) const {
|
|
||||||
return mat2x4<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x1_4 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x2_4 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator-(const N& other) const {
|
|
||||||
return mat2x4<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x1_4 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x2_4 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator%(const N& other) const {
|
|
||||||
return mat2x4<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x1_4 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x2_4 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat2x4<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x1_4 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x2_4 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat2x4<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x1_4 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x2_4 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x1_3 += static_cast<T>(other);
|
|
||||||
x1_4 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x2_3 += static_cast<T>(other);
|
|
||||||
x2_4 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x1_3 -= static_cast<T>(other);
|
|
||||||
x1_4 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x2_3 -= static_cast<T>(other);
|
|
||||||
x2_4 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x1_3 %= static_cast<T>(other);
|
|
||||||
x1_4 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x2_3 %= static_cast<T>(other);
|
|
||||||
x2_4 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x1_3 *= static_cast<T>(other);
|
|
||||||
x1_4 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x2_3 *= static_cast<T>(other);
|
|
||||||
x2_4 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat2x4<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x1_3 /= static_cast<T>(other);
|
|
||||||
x1_4 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x2_3 /= static_cast<T>(other);
|
|
||||||
x2_4 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec2<T> mat2x4<T>::operator*(const C& other) const {
|
|
||||||
vec2<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z + x1_4 * other.w;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z + x2_4 * other.w;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat2x2<T> mat2x4<T>::operator*(const M& other) const {
|
|
||||||
mat2x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat2x3<T> mat2x4<T>::operator*(const M& other) const {
|
|
||||||
mat2x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat2x4<T> mat2x4<T>::operator*(const M& other) const {
|
|
||||||
mat2x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4 + x1_4 * other.x4_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4 + x2_4 * other.x4_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool mat2x4<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool mat2x4<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool mat2x4<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool mat2x4<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool mat2x4<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool mat2x4<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x4<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x4<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x4<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x4<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x4<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat2x4<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat2x4<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x1_4 * x1_4) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x2_4 * x2_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat2x4<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat2x4<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat2x4<T>::dot(const mat2x4<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x1_4 * static_cast<T>(other.x1_4) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x2_4 * static_cast<T>(other.x2_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat2x4<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat2x4<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 2 + col * 4) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec4<T> mat2x4<T>::row(std::size_t i) const {
|
|
||||||
return rvec4<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)), *(&x1_1 + (2 * 3 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec2<T> mat2x4<T>::column(std::size_t i) const {
|
|
||||||
return vec2<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x4<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x4<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x2_4 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x4<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat2x4<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x2_4 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat2x4.tpp"
|
|
@ -1,219 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
template<Number T>
|
|
||||||
class vec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 8 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat2x4()
|
|
||||||
: x1_1(0), x1_2(0), x1_3(0), x1_4(0), x2_1(0), x2_2(0), x2_3(0), x2_4(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x1_4(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x2_4(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N0_2, Number N0_3, Number N1_0, Number N1_1, Number N1_2, Number N1_3>
|
|
||||||
constexpr mat2x4(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N0_3 x1_4, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N1_3 x2_4)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x1_4(static_cast<T>(x1_4)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x2_4(static_cast<T>(x2_4)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector4 V0, RowVector4 V1>
|
|
||||||
constexpr mat2x4(const V0& v0, const V1& v1)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x1_4(static_cast<T>(v0.w)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x2_4(static_cast<T>(v1.w)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector2 V0, ColumnVector2 V1, ColumnVector2 V2, ColumnVector2 V3>
|
|
||||||
constexpr mat2x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x1_4(static_cast<T>(v3.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x2_4(static_cast<T>(v3.y)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x1_3;
|
|
||||||
T x1_4;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x2_3;
|
|
||||||
T x2_4;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat2x4<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat2x4<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat2x4<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec4 -> vec2
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec2<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat4x2 -> mat2x2
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat2x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x3 -> mat2x3
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat2x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x4 -> mat2x4
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat2x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat2x4<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec4<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec2<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat2x4
|
|
||||||
|
|
||||||
using mat2x4f = mat2x4<float>;
|
|
||||||
using mat2x4d = mat2x4<double>;
|
|
||||||
using mat2x4i = mat2x4<int>;
|
|
||||||
using mat2x4u = mat2x4<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat2x4<mat2x4<int>>, "mat2x4<int> does not satisfy the concept Mat2x4");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat2x4.tpp
4559
src/math/mat2x4.tpp
File diff suppressed because it is too large
Load Diff
@ -1,360 +0,0 @@
|
|||||||
#include "mat3x2.hpp"
|
|
||||||
|
|
||||||
#include "mat2x2.hpp"
|
|
||||||
#include "mat2x3.hpp"
|
|
||||||
#include "mat2x4.hpp"
|
|
||||||
#include "mat3x3.hpp"
|
|
||||||
#include "mat3x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "vec2.hpp"
|
|
||||||
#include "vec3.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat3x2
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::operator=(const mat3x2<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x3_1 = static_cast<T>(other.x3_1);
|
|
||||||
x3_2 = static_cast<T>(other.x3_2);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x3_1 = static_cast<T>(other);
|
|
||||||
x3_2 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator+(const M& other) const {
|
|
||||||
return mat3x2<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator-(const M& other) const {
|
|
||||||
return mat3x2<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator%(const M& other) const {
|
|
||||||
return mat3x2<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat3x2<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat3x2<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void mat3x2<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x3_1 += static_cast<T>(other.x3_1);
|
|
||||||
x3_2 += static_cast<T>(other.x3_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void mat3x2<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 -= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 -= static_cast<T>(other.x3_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void mat3x2<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 %= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 %= static_cast<T>(other.x3_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void mat3x2<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 *= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 *= static_cast<T>(other.x3_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void mat3x2<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 /= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 /= static_cast<T>(other.x3_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator+(const N& other) const {
|
|
||||||
return mat3x2<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator-(const N& other) const {
|
|
||||||
return mat3x2<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator%(const N& other) const {
|
|
||||||
return mat3x2<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat3x2<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat3x2<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x3_1 += static_cast<T>(other);
|
|
||||||
x3_2 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x3_1 -= static_cast<T>(other);
|
|
||||||
x3_2 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x3_1 %= static_cast<T>(other);
|
|
||||||
x3_2 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x3_1 *= static_cast<T>(other);
|
|
||||||
x3_2 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x2<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x3_1 /= static_cast<T>(other);
|
|
||||||
x3_2 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec3<T> mat3x2<T>::operator*(const C& other) const {
|
|
||||||
vec3<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y;
|
|
||||||
new_.z = x3_1 * other.x + x3_2 * other.y;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x2<T>::operator*(const M& other) const {
|
|
||||||
mat3x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x2<T>::operator*(const M& other) const {
|
|
||||||
mat3x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x2<T>::operator*(const M& other) const {
|
|
||||||
mat3x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
|
||||||
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool mat3x2<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool mat3x2<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool mat3x2<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool mat3x2<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool mat3x2<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool mat3x2<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x2<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x2<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x2<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x2<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x2<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x2<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat3x2<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat3x2<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat3x2<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat3x2<T>::dot(const mat3x2<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat3x2<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat3x2<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 3 + col * 2) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec2<T> mat3x2<T>::row(std::size_t i) const {
|
|
||||||
return rvec2<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec3<T> mat3x2<T>::column(std::size_t i) const {
|
|
||||||
return vec3<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x2<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x2<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x3_2 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x2<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x2<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x3_2 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat3x2.tpp"
|
|
@ -1,217 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 6 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat3x2()
|
|
||||||
: x1_1(0), x1_2(0), x2_1(0), x2_2(0), x3_1(0), x3_2(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N1_0, Number N1_1, Number N2_0, Number N2_1>
|
|
||||||
constexpr mat3x2(const N0_0 x1_1, const N0_1 x1_2, const N1_0 x2_1, const N1_1 x2_2, const N2_0 x3_1, const N2_1 x3_2)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector2 V0, RowVector2 V1, RowVector2 V2>
|
|
||||||
constexpr mat3x2(const V0& v0, const V1& v1, const V2& v2)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector3 V0, ColumnVector3 V1>
|
|
||||||
constexpr mat3x2(const V0& v0, const V1& v1)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x3_1;
|
|
||||||
T x3_2;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat3x2<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x2<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec2 -> vec3
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec3<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat2x2 -> mat3x2
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat3x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x3 -> mat3x3
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat3x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x4 -> mat3x4
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat3x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat3x2<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec2<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec3<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat3x2
|
|
||||||
|
|
||||||
using mat3x2f = mat3x2<float>;
|
|
||||||
using mat3x2d = mat3x2<double>;
|
|
||||||
using mat3x2i = mat3x2<int>;
|
|
||||||
using mat3x2u = mat3x2<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat3x2<mat3x2<int>>, "mat3x2<int> does not satisfy the concept Mat3x2");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat3x2.tpp
4559
src/math/mat3x2.tpp
File diff suppressed because it is too large
Load Diff
@ -1,392 +0,0 @@
|
|||||||
#include "mat3x3.hpp"
|
|
||||||
|
|
||||||
#include "mat3x2.hpp"
|
|
||||||
#include "mat3x4.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "vec3.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat3x3
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::operator=(const mat3x3<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x1_3 = static_cast<T>(other.x1_3);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x2_3 = static_cast<T>(other.x2_3);
|
|
||||||
x3_1 = static_cast<T>(other.x3_1);
|
|
||||||
x3_2 = static_cast<T>(other.x3_2);
|
|
||||||
x3_3 = static_cast<T>(other.x3_3);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x1_3 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x2_3 = static_cast<T>(other);
|
|
||||||
x3_1 = static_cast<T>(other);
|
|
||||||
x3_2 = static_cast<T>(other);
|
|
||||||
x3_3 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator+(const M& other) const {
|
|
||||||
return mat3x3<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator-(const M& other) const {
|
|
||||||
return mat3x3<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator%(const M& other) const {
|
|
||||||
return mat3x3<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat3x3<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat3x3<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void mat3x3<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x1_3 += static_cast<T>(other.x1_3);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x2_3 += static_cast<T>(other.x2_3);
|
|
||||||
x3_1 += static_cast<T>(other.x3_1);
|
|
||||||
x3_2 += static_cast<T>(other.x3_2);
|
|
||||||
x3_3 += static_cast<T>(other.x3_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void mat3x3<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 -= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 -= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 -= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 -= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 -= static_cast<T>(other.x3_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void mat3x3<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 %= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 %= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 %= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 %= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 %= static_cast<T>(other.x3_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void mat3x3<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 *= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 *= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 *= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 *= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 *= static_cast<T>(other.x3_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void mat3x3<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 /= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 /= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 /= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 /= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 /= static_cast<T>(other.x3_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator+(const N& other) const {
|
|
||||||
return mat3x3<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator-(const N& other) const {
|
|
||||||
return mat3x3<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator%(const N& other) const {
|
|
||||||
return mat3x3<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat3x3<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat3x3<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x1_3 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x2_3 += static_cast<T>(other);
|
|
||||||
x3_1 += static_cast<T>(other);
|
|
||||||
x3_2 += static_cast<T>(other);
|
|
||||||
x3_3 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x1_3 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x2_3 -= static_cast<T>(other);
|
|
||||||
x3_1 -= static_cast<T>(other);
|
|
||||||
x3_2 -= static_cast<T>(other);
|
|
||||||
x3_3 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x1_3 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x2_3 %= static_cast<T>(other);
|
|
||||||
x3_1 %= static_cast<T>(other);
|
|
||||||
x3_2 %= static_cast<T>(other);
|
|
||||||
x3_3 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x1_3 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x2_3 *= static_cast<T>(other);
|
|
||||||
x3_1 *= static_cast<T>(other);
|
|
||||||
x3_2 *= static_cast<T>(other);
|
|
||||||
x3_3 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x3<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x1_3 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x2_3 /= static_cast<T>(other);
|
|
||||||
x3_1 /= static_cast<T>(other);
|
|
||||||
x3_2 /= static_cast<T>(other);
|
|
||||||
x3_3 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> mat3x3<T>::operator*(const C& other) const {
|
|
||||||
vec3<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z;
|
|
||||||
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x3<T>::operator*(const M& other) const {
|
|
||||||
mat3x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x3<T>::operator*(const M& other) const {
|
|
||||||
mat3x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x3<T>::operator*(const M& other) const {
|
|
||||||
mat3x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
|
||||||
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool mat3x3<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool mat3x3<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool mat3x3<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool mat3x3<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool mat3x3<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool mat3x3<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x3<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x3<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x3<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x3<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x3<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x3<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat3x3<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat3x3<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat3x3<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat3x3<T>::dot(const mat3x3<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat3x3<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat3x3<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 3 + col * 3) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec3<T> mat3x3<T>::row(std::size_t i) const {
|
|
||||||
return rvec3<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec3<T> mat3x3<T>::column(std::size_t i) const {
|
|
||||||
return vec3<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x3<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x3<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x3_3 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x3<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x3<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x3_3 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat3x3.tpp"
|
|
@ -1,212 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class vec3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 9 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat3x3()
|
|
||||||
: x1_1(0), x1_2(0), x1_3(0), x2_1(0), x2_2(0), x2_3(0), x3_1(0), x3_2(0), x3_3(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N0_2, Number N1_0, Number N1_1, Number N1_2, Number N2_0, Number N2_1, Number N2_2>
|
|
||||||
constexpr mat3x3(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector3 V0, RowVector3 V1, RowVector3 V2>
|
|
||||||
constexpr mat3x3(const V0& v0, const V1& v1, const V2& v2)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector3 V0, ColumnVector3 V1, ColumnVector3 V2>
|
|
||||||
constexpr mat3x3(const V0& v0, const V1& v1, const V2& v2)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x1_3;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x2_3;
|
|
||||||
T x3_1;
|
|
||||||
T x3_2;
|
|
||||||
T x3_3;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat3x3<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x3<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec3 -> vec3
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat3x2 -> mat3x2
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat3x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x3 -> mat3x3
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat3x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x4 -> mat3x4
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat3x3<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec3<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec3<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat3x3
|
|
||||||
|
|
||||||
using mat3x3f = mat3x3<float>;
|
|
||||||
using mat3x3d = mat3x3<double>;
|
|
||||||
using mat3x3i = mat3x3<int>;
|
|
||||||
using mat3x3u = mat3x3<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat3x3<mat3x3<int>>, "mat3x3<int> does not satisfy the concept Mat3x3");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat3x3.tpp
4559
src/math/mat3x3.tpp
File diff suppressed because it is too large
Load Diff
@ -1,432 +0,0 @@
|
|||||||
#include "mat3x4.hpp"
|
|
||||||
|
|
||||||
#include "mat3x2.hpp"
|
|
||||||
#include "mat3x3.hpp"
|
|
||||||
#include "mat4x2.hpp"
|
|
||||||
#include "mat4x3.hpp"
|
|
||||||
#include "mat4x4.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
#include "vec3.hpp"
|
|
||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat3x4
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::operator=(const mat3x4<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x1_3 = static_cast<T>(other.x1_3);
|
|
||||||
x1_4 = static_cast<T>(other.x1_4);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x2_3 = static_cast<T>(other.x2_3);
|
|
||||||
x2_4 = static_cast<T>(other.x2_4);
|
|
||||||
x3_1 = static_cast<T>(other.x3_1);
|
|
||||||
x3_2 = static_cast<T>(other.x3_2);
|
|
||||||
x3_3 = static_cast<T>(other.x3_3);
|
|
||||||
x3_4 = static_cast<T>(other.x3_4);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x1_3 = static_cast<T>(other);
|
|
||||||
x1_4 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x2_3 = static_cast<T>(other);
|
|
||||||
x2_4 = static_cast<T>(other);
|
|
||||||
x3_1 = static_cast<T>(other);
|
|
||||||
x3_2 = static_cast<T>(other);
|
|
||||||
x3_3 = static_cast<T>(other);
|
|
||||||
x3_4 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator+(const M& other) const {
|
|
||||||
return mat3x4<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x1_4 + static_cast<T>(other.x1_4), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x2_4 + static_cast<T>(other.x2_4), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3), x3_4 + static_cast<T>(other.x3_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator-(const M& other) const {
|
|
||||||
return mat3x4<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x1_4 - static_cast<T>(other.x1_4), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x2_4 - static_cast<T>(other.x2_4), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3), x3_4 - static_cast<T>(other.x3_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator%(const M& other) const {
|
|
||||||
return mat3x4<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x1_4 % static_cast<T>(other.x1_4), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x2_4 % static_cast<T>(other.x2_4), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3), x3_4 % static_cast<T>(other.x3_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat3x4<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x1_4 * static_cast<T>(other.x1_4), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x2_4 * static_cast<T>(other.x2_4), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3), x3_4 * static_cast<T>(other.x3_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat3x4<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x1_4 / static_cast<T>(other.x1_4), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x2_4 / static_cast<T>(other.x2_4), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3), x3_4 / static_cast<T>(other.x3_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void mat3x4<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x1_3 += static_cast<T>(other.x1_3);
|
|
||||||
x1_4 += static_cast<T>(other.x1_4);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x2_3 += static_cast<T>(other.x2_3);
|
|
||||||
x2_4 += static_cast<T>(other.x2_4);
|
|
||||||
x3_1 += static_cast<T>(other.x3_1);
|
|
||||||
x3_2 += static_cast<T>(other.x3_2);
|
|
||||||
x3_3 += static_cast<T>(other.x3_3);
|
|
||||||
x3_4 += static_cast<T>(other.x3_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void mat3x4<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 -= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 -= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 -= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 -= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 -= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 -= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 -= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 -= static_cast<T>(other.x3_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void mat3x4<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 %= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 %= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 %= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 %= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 %= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 %= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 %= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 %= static_cast<T>(other.x3_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void mat3x4<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 *= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 *= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 *= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 *= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 *= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 *= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 *= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 *= static_cast<T>(other.x3_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void mat3x4<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 /= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 /= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 /= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 /= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 /= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 /= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 /= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 /= static_cast<T>(other.x3_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator+(const N& other) const {
|
|
||||||
return mat3x4<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x1_4 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x2_4 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other), x3_4 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator-(const N& other) const {
|
|
||||||
return mat3x4<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x1_4 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x2_4 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other), x3_4 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator%(const N& other) const {
|
|
||||||
return mat3x4<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x1_4 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x2_4 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other), x3_4 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat3x4<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x1_4 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x2_4 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other), x3_4 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat3x4<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x1_4 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x2_4 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other), x3_4 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x1_3 += static_cast<T>(other);
|
|
||||||
x1_4 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x2_3 += static_cast<T>(other);
|
|
||||||
x2_4 += static_cast<T>(other);
|
|
||||||
x3_1 += static_cast<T>(other);
|
|
||||||
x3_2 += static_cast<T>(other);
|
|
||||||
x3_3 += static_cast<T>(other);
|
|
||||||
x3_4 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x1_3 -= static_cast<T>(other);
|
|
||||||
x1_4 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x2_3 -= static_cast<T>(other);
|
|
||||||
x2_4 -= static_cast<T>(other);
|
|
||||||
x3_1 -= static_cast<T>(other);
|
|
||||||
x3_2 -= static_cast<T>(other);
|
|
||||||
x3_3 -= static_cast<T>(other);
|
|
||||||
x3_4 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x1_3 %= static_cast<T>(other);
|
|
||||||
x1_4 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x2_3 %= static_cast<T>(other);
|
|
||||||
x2_4 %= static_cast<T>(other);
|
|
||||||
x3_1 %= static_cast<T>(other);
|
|
||||||
x3_2 %= static_cast<T>(other);
|
|
||||||
x3_3 %= static_cast<T>(other);
|
|
||||||
x3_4 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x1_3 *= static_cast<T>(other);
|
|
||||||
x1_4 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x2_3 *= static_cast<T>(other);
|
|
||||||
x2_4 *= static_cast<T>(other);
|
|
||||||
x3_1 *= static_cast<T>(other);
|
|
||||||
x3_2 *= static_cast<T>(other);
|
|
||||||
x3_3 *= static_cast<T>(other);
|
|
||||||
x3_4 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat3x4<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x1_3 /= static_cast<T>(other);
|
|
||||||
x1_4 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x2_3 /= static_cast<T>(other);
|
|
||||||
x2_4 /= static_cast<T>(other);
|
|
||||||
x3_1 /= static_cast<T>(other);
|
|
||||||
x3_2 /= static_cast<T>(other);
|
|
||||||
x3_3 /= static_cast<T>(other);
|
|
||||||
x3_4 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec3<T> mat3x4<T>::operator*(const C& other) const {
|
|
||||||
vec3<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z + x1_4 * other.w;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z + x2_4 * other.w;
|
|
||||||
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z + x3_4 * other.w;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat3x2<T> mat3x4<T>::operator*(const M& other) const {
|
|
||||||
mat3x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat3x3<T> mat3x4<T>::operator*(const M& other) const {
|
|
||||||
mat3x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat3x4<T> mat3x4<T>::operator*(const M& other) const {
|
|
||||||
mat3x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4 + x1_4 * other.x4_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4 + x2_4 * other.x4_4;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
|
||||||
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4 + x3_4 * other.x4_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool mat3x4<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool mat3x4<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool mat3x4<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool mat3x4<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool mat3x4<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool mat3x4<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x4<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x4<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x4<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x4<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x4<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat3x4<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat3x4<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x1_4 * x1_4) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x2_4 * x2_4) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3) + static_cast<float>(x3_4 * x3_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat3x4<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat3x4<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat3x4<T>::dot(const mat3x4<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x1_4 * static_cast<T>(other.x1_4) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x2_4 * static_cast<T>(other.x2_4) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3) + x3_4 * static_cast<T>(other.x3_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat3x4<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat3x4<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 3 + col * 4) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec4<T> mat3x4<T>::row(std::size_t i) const {
|
|
||||||
return rvec4<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)), *(&x1_1 + (3 * 3 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec3<T> mat3x4<T>::column(std::size_t i) const {
|
|
||||||
return vec3<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x4<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x4<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x3_4 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x4<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat3x4<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x3_4 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat3x4.tpp"
|
|
@ -1,223 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
template<Number T>
|
|
||||||
class vec3;
|
|
||||||
template<Number T>
|
|
||||||
class vec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 12 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat3x4()
|
|
||||||
: x1_1(0), x1_2(0), x1_3(0), x1_4(0), x2_1(0), x2_2(0), x2_3(0), x2_4(0), x3_1(0), x3_2(0), x3_3(0), x3_4(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x1_4(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x2_4(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)), x3_4(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N0_2, Number N0_3, Number N1_0, Number N1_1, Number N1_2, Number N1_3, Number N2_0, Number N2_1, Number N2_2, Number N2_3>
|
|
||||||
constexpr mat3x4(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N0_3 x1_4, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N1_3 x2_4, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3, const N2_3 x3_4)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x1_4(static_cast<T>(x1_4)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x2_4(static_cast<T>(x2_4)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)), x3_4(static_cast<T>(x3_4)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector4 V0, RowVector4 V1, RowVector4 V2>
|
|
||||||
constexpr mat3x4(const V0& v0, const V1& v1, const V2& v2)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x1_4(static_cast<T>(v0.w)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x2_4(static_cast<T>(v1.w)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v2.w)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector3 V0, ColumnVector3 V1, ColumnVector3 V2, ColumnVector3 V3>
|
|
||||||
constexpr mat3x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x1_4(static_cast<T>(v3.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x2_4(static_cast<T>(v3.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v3.z)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x1_3;
|
|
||||||
T x1_4;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x2_3;
|
|
||||||
T x2_4;
|
|
||||||
T x3_1;
|
|
||||||
T x3_2;
|
|
||||||
T x3_3;
|
|
||||||
T x3_4;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat3x4<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat3x4<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat3x4<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec4 -> vec3
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec3<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat4x2 -> mat3x2
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat3x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x3 -> mat3x3
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat3x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x4 -> mat3x4
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat3x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat3x4<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec4<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec3<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat3x4
|
|
||||||
|
|
||||||
using mat3x4f = mat3x4<float>;
|
|
||||||
using mat3x4d = mat3x4<double>;
|
|
||||||
using mat3x4i = mat3x4<int>;
|
|
||||||
using mat3x4u = mat3x4<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat3x4<mat3x4<int>>, "mat3x4<int> does not satisfy the concept Mat3x4");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat3x4.tpp
4559
src/math/mat3x4.tpp
File diff suppressed because it is too large
Load Diff
@ -1,394 +0,0 @@
|
|||||||
#include "mat4x2.hpp"
|
|
||||||
|
|
||||||
#include "mat2x2.hpp"
|
|
||||||
#include "mat2x3.hpp"
|
|
||||||
#include "mat2x4.hpp"
|
|
||||||
#include "mat4x3.hpp"
|
|
||||||
#include "mat4x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "vec2.hpp"
|
|
||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat4x2
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::operator=(const mat4x2<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x3_1 = static_cast<T>(other.x3_1);
|
|
||||||
x3_2 = static_cast<T>(other.x3_2);
|
|
||||||
x4_1 = static_cast<T>(other.x4_1);
|
|
||||||
x4_2 = static_cast<T>(other.x4_2);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x3_1 = static_cast<T>(other);
|
|
||||||
x3_2 = static_cast<T>(other);
|
|
||||||
x4_1 = static_cast<T>(other);
|
|
||||||
x4_2 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator+(const M& other) const {
|
|
||||||
return mat4x2<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x4_1 + static_cast<T>(other.x4_1), x4_2 + static_cast<T>(other.x4_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator-(const M& other) const {
|
|
||||||
return mat4x2<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x4_1 - static_cast<T>(other.x4_1), x4_2 - static_cast<T>(other.x4_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator%(const M& other) const {
|
|
||||||
return mat4x2<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x4_1 % static_cast<T>(other.x4_1), x4_2 % static_cast<T>(other.x4_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat4x2<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x4_1 * static_cast<T>(other.x4_1), x4_2 * static_cast<T>(other.x4_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat4x2<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x4_1 / static_cast<T>(other.x4_1), x4_2 / static_cast<T>(other.x4_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void mat4x2<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x3_1 += static_cast<T>(other.x3_1);
|
|
||||||
x3_2 += static_cast<T>(other.x3_2);
|
|
||||||
x4_1 += static_cast<T>(other.x4_1);
|
|
||||||
x4_2 += static_cast<T>(other.x4_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void mat4x2<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 -= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 -= static_cast<T>(other.x3_2);
|
|
||||||
x4_1 -= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 -= static_cast<T>(other.x4_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void mat4x2<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 %= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 %= static_cast<T>(other.x3_2);
|
|
||||||
x4_1 %= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 %= static_cast<T>(other.x4_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void mat4x2<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 *= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 *= static_cast<T>(other.x3_2);
|
|
||||||
x4_1 *= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 *= static_cast<T>(other.x4_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void mat4x2<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x3_1 /= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 /= static_cast<T>(other.x3_2);
|
|
||||||
x4_1 /= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 /= static_cast<T>(other.x4_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator+(const N& other) const {
|
|
||||||
return mat4x2<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x4_1 + static_cast<T>(other), x4_2 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator-(const N& other) const {
|
|
||||||
return mat4x2<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x4_1 - static_cast<T>(other), x4_2 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator%(const N& other) const {
|
|
||||||
return mat4x2<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x4_1 % static_cast<T>(other), x4_2 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat4x2<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x4_1 * static_cast<T>(other), x4_2 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat4x2<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x4_1 / static_cast<T>(other), x4_2 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x3_1 += static_cast<T>(other);
|
|
||||||
x3_2 += static_cast<T>(other);
|
|
||||||
x4_1 += static_cast<T>(other);
|
|
||||||
x4_2 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x3_1 -= static_cast<T>(other);
|
|
||||||
x3_2 -= static_cast<T>(other);
|
|
||||||
x4_1 -= static_cast<T>(other);
|
|
||||||
x4_2 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x3_1 %= static_cast<T>(other);
|
|
||||||
x3_2 %= static_cast<T>(other);
|
|
||||||
x4_1 %= static_cast<T>(other);
|
|
||||||
x4_2 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x3_1 *= static_cast<T>(other);
|
|
||||||
x3_2 *= static_cast<T>(other);
|
|
||||||
x4_1 *= static_cast<T>(other);
|
|
||||||
x4_2 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x2<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x3_1 /= static_cast<T>(other);
|
|
||||||
x3_2 /= static_cast<T>(other);
|
|
||||||
x4_1 /= static_cast<T>(other);
|
|
||||||
x4_2 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec4<T> mat4x2<T>::operator*(const C& other) const {
|
|
||||||
vec4<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y;
|
|
||||||
new_.z = x3_1 * other.x + x3_2 * other.y;
|
|
||||||
new_.w = x4_1 * other.x + x4_2 * other.y;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x2<T>::operator*(const M& other) const {
|
|
||||||
mat4x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x2<T>::operator*(const M& other) const {
|
|
||||||
mat4x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2;
|
|
||||||
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x2<T>::operator*(const M& other) const {
|
|
||||||
mat4x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3;
|
|
||||||
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2;
|
|
||||||
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3;
|
|
||||||
new_.x4_4 = x4_1 * other.x1_4 + x4_2 * other.x2_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool mat4x2<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x4_1 == other.x4_1 and x4_2 == other.x4_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool mat4x2<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x4_1 < other.x4_1 and x4_2 < other.x4_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool mat4x2<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x4_1 > other.x4_1 and x4_2 > other.x4_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool mat4x2<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x4_1 == other.x4_1 and x4_2 == other.x4_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool mat4x2<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x4_1 > other.x4_1 and x4_2 > other.x4_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool mat4x2<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x4_1 < other.x4_1 and x4_2 < other.x4_2;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x2<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other and x4_1 == other and x4_2 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x2<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other and x4_1 < other and x4_2 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x2<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other and x4_1 > other and x4_2 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x2<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x2_1 == other and x2_2 == other and x3_1 == other and x3_2 == other and x4_1 == other and x4_2 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x2<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x2_1 > other and x2_2 > other and x3_1 > other and x3_2 > other and x4_1 > other and x4_2 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x2<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x2_1 < other and x2_2 < other and x3_1 < other and x3_2 < other and x4_1 < other and x4_2 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat4x2<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x4_1 * x4_1) + static_cast<float>(x4_2 * x4_2));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat4x2<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat4x2<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat4x2<T>::dot(const mat4x2<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x4_1 * static_cast<T>(other.x4_1) + x4_2 * static_cast<T>(other.x4_2);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat4x2<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat4x2<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 4 + col * 2) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec2<T> mat4x2<T>::row(std::size_t i) const {
|
|
||||||
return rvec2<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec4<T> mat4x2<T>::column(std::size_t i) const {
|
|
||||||
return vec4<T>(*(&x1_1 + (2 * 0 + i) * sizeof(T)), *(&x1_1 + (2 * 1 + i) * sizeof(T)), *(&x1_1 + (2 * 2 + i) * sizeof(T)), *(&x1_1 + (2 * 3 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x2<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x2<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x4_2 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x2<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x2<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x4_2 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat4x2.tpp"
|
|
@ -1,219 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec2;
|
|
||||||
template<Number T>
|
|
||||||
class vec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 8 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat4x2()
|
|
||||||
: x1_1(0), x1_2(0), x2_1(0), x2_2(0), x3_1(0), x3_2(0), x4_1(0), x4_2(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x4_1(static_cast<T>(n)), x4_2(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N1_0, Number N1_1, Number N2_0, Number N2_1, Number N3_0, Number N3_1>
|
|
||||||
constexpr mat4x2(const N0_0 x1_1, const N0_1 x1_2, const N1_0 x2_1, const N1_1 x2_2, const N2_0 x3_1, const N2_1 x3_2, const N3_0 x4_1, const N3_1 x4_2)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x4_1(static_cast<T>(x4_1)), x4_2(static_cast<T>(x4_2)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector2 V0, RowVector2 V1, RowVector2 V2, RowVector2 V3>
|
|
||||||
constexpr mat4x2(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x4_1(static_cast<T>(v3.x)), x4_2(static_cast<T>(v3.y)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector4 V0, ColumnVector4 V1>
|
|
||||||
constexpr mat4x2(const V0& v0, const V1& v1)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x4_1(static_cast<T>(v0.w)), x4_2(static_cast<T>(v1.w)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x3_1;
|
|
||||||
T x3_2;
|
|
||||||
T x4_1;
|
|
||||||
T x4_2;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat4x2<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x2<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec2 -> vec4
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec4<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat2x2 -> mat4x2
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr mat4x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x3 -> mat4x3
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr mat4x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x4 -> mat4x4
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr mat4x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat4x2<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec2<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec4<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat4x2
|
|
||||||
|
|
||||||
using mat4x2f = mat4x2<float>;
|
|
||||||
using mat4x2d = mat4x2<double>;
|
|
||||||
using mat4x2i = mat4x2<int>;
|
|
||||||
using mat4x2u = mat4x2<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat4x2<mat4x2<int>>, "mat4x2<int> does not satisfy the concept Mat4x2");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat4x2.tpp
4559
src/math/mat4x2.tpp
File diff suppressed because it is too large
Load Diff
@ -1,442 +0,0 @@
|
|||||||
#include "mat4x3.hpp"
|
|
||||||
|
|
||||||
#include "mat3x2.hpp"
|
|
||||||
#include "mat3x3.hpp"
|
|
||||||
#include "mat3x4.hpp"
|
|
||||||
#include "mat4x2.hpp"
|
|
||||||
#include "mat4x4.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "vec3.hpp"
|
|
||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat4x3
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::operator=(const mat4x3<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x1_3 = static_cast<T>(other.x1_3);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x2_3 = static_cast<T>(other.x2_3);
|
|
||||||
x3_1 = static_cast<T>(other.x3_1);
|
|
||||||
x3_2 = static_cast<T>(other.x3_2);
|
|
||||||
x3_3 = static_cast<T>(other.x3_3);
|
|
||||||
x4_1 = static_cast<T>(other.x4_1);
|
|
||||||
x4_2 = static_cast<T>(other.x4_2);
|
|
||||||
x4_3 = static_cast<T>(other.x4_3);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x1_3 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x2_3 = static_cast<T>(other);
|
|
||||||
x3_1 = static_cast<T>(other);
|
|
||||||
x3_2 = static_cast<T>(other);
|
|
||||||
x3_3 = static_cast<T>(other);
|
|
||||||
x4_1 = static_cast<T>(other);
|
|
||||||
x4_2 = static_cast<T>(other);
|
|
||||||
x4_3 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator+(const M& other) const {
|
|
||||||
return mat4x3<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3), x4_1 + static_cast<T>(other.x4_1), x4_2 + static_cast<T>(other.x4_2), x4_3 + static_cast<T>(other.x4_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator-(const M& other) const {
|
|
||||||
return mat4x3<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3), x4_1 - static_cast<T>(other.x4_1), x4_2 - static_cast<T>(other.x4_2), x4_3 - static_cast<T>(other.x4_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator%(const M& other) const {
|
|
||||||
return mat4x3<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3), x4_1 % static_cast<T>(other.x4_1), x4_2 % static_cast<T>(other.x4_2), x4_3 % static_cast<T>(other.x4_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat4x3<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3), x4_1 * static_cast<T>(other.x4_1), x4_2 * static_cast<T>(other.x4_2), x4_3 * static_cast<T>(other.x4_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat4x3<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3), x4_1 / static_cast<T>(other.x4_1), x4_2 / static_cast<T>(other.x4_2), x4_3 / static_cast<T>(other.x4_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void mat4x3<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x1_3 += static_cast<T>(other.x1_3);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x2_3 += static_cast<T>(other.x2_3);
|
|
||||||
x3_1 += static_cast<T>(other.x3_1);
|
|
||||||
x3_2 += static_cast<T>(other.x3_2);
|
|
||||||
x3_3 += static_cast<T>(other.x3_3);
|
|
||||||
x4_1 += static_cast<T>(other.x4_1);
|
|
||||||
x4_2 += static_cast<T>(other.x4_2);
|
|
||||||
x4_3 += static_cast<T>(other.x4_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void mat4x3<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 -= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 -= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 -= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 -= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 -= static_cast<T>(other.x3_3);
|
|
||||||
x4_1 -= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 -= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 -= static_cast<T>(other.x4_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void mat4x3<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 %= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 %= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 %= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 %= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 %= static_cast<T>(other.x3_3);
|
|
||||||
x4_1 %= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 %= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 %= static_cast<T>(other.x4_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void mat4x3<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 *= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 *= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 *= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 *= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 *= static_cast<T>(other.x3_3);
|
|
||||||
x4_1 *= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 *= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 *= static_cast<T>(other.x4_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void mat4x3<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 /= static_cast<T>(other.x1_3);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 /= static_cast<T>(other.x2_3);
|
|
||||||
x3_1 /= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 /= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 /= static_cast<T>(other.x3_3);
|
|
||||||
x4_1 /= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 /= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 /= static_cast<T>(other.x4_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator+(const N& other) const {
|
|
||||||
return mat4x3<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other), x4_1 + static_cast<T>(other), x4_2 + static_cast<T>(other), x4_3 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator-(const N& other) const {
|
|
||||||
return mat4x3<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other), x4_1 - static_cast<T>(other), x4_2 - static_cast<T>(other), x4_3 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator%(const N& other) const {
|
|
||||||
return mat4x3<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other), x4_1 % static_cast<T>(other), x4_2 % static_cast<T>(other), x4_3 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat4x3<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other), x4_1 * static_cast<T>(other), x4_2 * static_cast<T>(other), x4_3 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat4x3<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other), x4_1 / static_cast<T>(other), x4_2 / static_cast<T>(other), x4_3 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x1_3 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x2_3 += static_cast<T>(other);
|
|
||||||
x3_1 += static_cast<T>(other);
|
|
||||||
x3_2 += static_cast<T>(other);
|
|
||||||
x3_3 += static_cast<T>(other);
|
|
||||||
x4_1 += static_cast<T>(other);
|
|
||||||
x4_2 += static_cast<T>(other);
|
|
||||||
x4_3 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x1_3 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x2_3 -= static_cast<T>(other);
|
|
||||||
x3_1 -= static_cast<T>(other);
|
|
||||||
x3_2 -= static_cast<T>(other);
|
|
||||||
x3_3 -= static_cast<T>(other);
|
|
||||||
x4_1 -= static_cast<T>(other);
|
|
||||||
x4_2 -= static_cast<T>(other);
|
|
||||||
x4_3 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x1_3 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x2_3 %= static_cast<T>(other);
|
|
||||||
x3_1 %= static_cast<T>(other);
|
|
||||||
x3_2 %= static_cast<T>(other);
|
|
||||||
x3_3 %= static_cast<T>(other);
|
|
||||||
x4_1 %= static_cast<T>(other);
|
|
||||||
x4_2 %= static_cast<T>(other);
|
|
||||||
x4_3 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x1_3 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x2_3 *= static_cast<T>(other);
|
|
||||||
x3_1 *= static_cast<T>(other);
|
|
||||||
x3_2 *= static_cast<T>(other);
|
|
||||||
x3_3 *= static_cast<T>(other);
|
|
||||||
x4_1 *= static_cast<T>(other);
|
|
||||||
x4_2 *= static_cast<T>(other);
|
|
||||||
x4_3 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x3<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x1_3 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x2_3 /= static_cast<T>(other);
|
|
||||||
x3_1 /= static_cast<T>(other);
|
|
||||||
x3_2 /= static_cast<T>(other);
|
|
||||||
x3_3 /= static_cast<T>(other);
|
|
||||||
x4_1 /= static_cast<T>(other);
|
|
||||||
x4_2 /= static_cast<T>(other);
|
|
||||||
x4_3 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec4<T> mat4x3<T>::operator*(const C& other) const {
|
|
||||||
vec4<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z;
|
|
||||||
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z;
|
|
||||||
new_.w = x4_1 * other.x + x4_2 * other.y + x4_3 * other.z;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x3<T>::operator*(const M& other) const {
|
|
||||||
mat4x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x3<T>::operator*(const M& other) const {
|
|
||||||
mat4x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2;
|
|
||||||
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x3<T>::operator*(const M& other) const {
|
|
||||||
mat4x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3;
|
|
||||||
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2;
|
|
||||||
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3;
|
|
||||||
new_.x4_4 = x4_1 * other.x1_4 + x4_2 * other.x2_4 + x4_3 * other.x3_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool mat4x3<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool mat4x3<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool mat4x3<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool mat4x3<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool mat4x3<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool mat4x3<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x3<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other and x4_1 == other and x4_2 == other and x4_3 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x3<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other and x4_1 < other and x4_2 < other and x4_3 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x3<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other and x4_1 > other and x4_2 > other and x4_3 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x3<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x2_1 == other and x2_2 == other and x2_3 == other and x3_1 == other and x3_2 == other and x3_3 == other and x4_1 == other and x4_2 == other and x4_3 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x3<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x2_1 > other and x2_2 > other and x2_3 > other and x3_1 > other and x3_2 > other and x3_3 > other and x4_1 > other and x4_2 > other and x4_3 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x3<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x2_1 < other and x2_2 < other and x2_3 < other and x3_1 < other and x3_2 < other and x3_3 < other and x4_1 < other and x4_2 < other and x4_3 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat4x3<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3) + static_cast<float>(x4_1 * x4_1) + static_cast<float>(x4_2 * x4_2) + static_cast<float>(x4_3 * x4_3));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat4x3<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat4x3<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat4x3<T>::dot(const mat4x3<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3) + x4_1 * static_cast<T>(other.x4_1) + x4_2 * static_cast<T>(other.x4_2) + x4_3 * static_cast<T>(other.x4_3);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat4x3<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat4x3<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 4 + col * 3) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec3<T> mat4x3<T>::row(std::size_t i) const {
|
|
||||||
return rvec3<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec4<T> mat4x3<T>::column(std::size_t i) const {
|
|
||||||
return vec4<T>(*(&x1_1 + (3 * 0 + i) * sizeof(T)), *(&x1_1 + (3 * 1 + i) * sizeof(T)), *(&x1_1 + (3 * 2 + i) * sizeof(T)), *(&x1_1 + (3 * 3 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x3<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x3<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x4_3 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x3<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x3<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x4_3 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat4x3.tpp"
|
|
@ -1,223 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class vec3;
|
|
||||||
template<Number T>
|
|
||||||
class vec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 12 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat4x3()
|
|
||||||
: x1_1(0), x1_2(0), x1_3(0), x2_1(0), x2_2(0), x2_3(0), x3_1(0), x3_2(0), x3_3(0), x4_1(0), x4_2(0), x4_3(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)), x4_1(static_cast<T>(n)), x4_2(static_cast<T>(n)), x4_3(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N0_2, Number N1_0, Number N1_1, Number N1_2, Number N2_0, Number N2_1, Number N2_2, Number N3_0, Number N3_1, Number N3_2>
|
|
||||||
constexpr mat4x3(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3, const N3_0 x4_1, const N3_1 x4_2, const N3_2 x4_3)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)), x4_1(static_cast<T>(x4_1)), x4_2(static_cast<T>(x4_2)), x4_3(static_cast<T>(x4_3)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector3 V0, RowVector3 V1, RowVector3 V2, RowVector3 V3>
|
|
||||||
constexpr mat4x3(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)), x4_1(static_cast<T>(v3.x)), x4_2(static_cast<T>(v3.y)), x4_3(static_cast<T>(v3.z)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector4 V0, ColumnVector4 V1, ColumnVector4 V2>
|
|
||||||
constexpr mat4x3(const V0& v0, const V1& v1, const V2& v2)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)), x4_1(static_cast<T>(v0.w)), x4_2(static_cast<T>(v1.w)), x4_3(static_cast<T>(v2.w)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x1_3;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x2_3;
|
|
||||||
T x3_1;
|
|
||||||
T x3_2;
|
|
||||||
T x3_3;
|
|
||||||
T x4_1;
|
|
||||||
T x4_2;
|
|
||||||
T x4_3;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat4x3<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x3<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec3 -> vec4
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec4<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat3x2 -> mat4x2
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr mat4x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x3 -> mat4x3
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr mat4x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x4 -> mat4x4
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr mat4x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat4x3<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec3<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec4<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat4x3
|
|
||||||
|
|
||||||
using mat4x3f = mat4x3<float>;
|
|
||||||
using mat4x3d = mat4x3<double>;
|
|
||||||
using mat4x3i = mat4x3<int>;
|
|
||||||
using mat4x3u = mat4x3<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat4x3<mat4x3<int>>, "mat4x3<int> does not satisfy the concept Mat4x3");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat4x3.tpp
4559
src/math/mat4x3.tpp
File diff suppressed because it is too large
Load Diff
@ -1,486 +0,0 @@
|
|||||||
#include "mat4x4.hpp"
|
|
||||||
|
|
||||||
#include "mat4x2.hpp"
|
|
||||||
#include "mat4x3.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS mat4x4
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::operator=(const mat4x4<N>& other) {
|
|
||||||
x1_1 = static_cast<T>(other.x1_1);
|
|
||||||
x1_2 = static_cast<T>(other.x1_2);
|
|
||||||
x1_3 = static_cast<T>(other.x1_3);
|
|
||||||
x1_4 = static_cast<T>(other.x1_4);
|
|
||||||
x2_1 = static_cast<T>(other.x2_1);
|
|
||||||
x2_2 = static_cast<T>(other.x2_2);
|
|
||||||
x2_3 = static_cast<T>(other.x2_3);
|
|
||||||
x2_4 = static_cast<T>(other.x2_4);
|
|
||||||
x3_1 = static_cast<T>(other.x3_1);
|
|
||||||
x3_2 = static_cast<T>(other.x3_2);
|
|
||||||
x3_3 = static_cast<T>(other.x3_3);
|
|
||||||
x3_4 = static_cast<T>(other.x3_4);
|
|
||||||
x4_1 = static_cast<T>(other.x4_1);
|
|
||||||
x4_2 = static_cast<T>(other.x4_2);
|
|
||||||
x4_3 = static_cast<T>(other.x4_3);
|
|
||||||
x4_4 = static_cast<T>(other.x4_4);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::operator=(const N& other) {
|
|
||||||
x1_1 = static_cast<T>(other);
|
|
||||||
x1_2 = static_cast<T>(other);
|
|
||||||
x1_3 = static_cast<T>(other);
|
|
||||||
x1_4 = static_cast<T>(other);
|
|
||||||
x2_1 = static_cast<T>(other);
|
|
||||||
x2_2 = static_cast<T>(other);
|
|
||||||
x2_3 = static_cast<T>(other);
|
|
||||||
x2_4 = static_cast<T>(other);
|
|
||||||
x3_1 = static_cast<T>(other);
|
|
||||||
x3_2 = static_cast<T>(other);
|
|
||||||
x3_3 = static_cast<T>(other);
|
|
||||||
x3_4 = static_cast<T>(other);
|
|
||||||
x4_1 = static_cast<T>(other);
|
|
||||||
x4_2 = static_cast<T>(other);
|
|
||||||
x4_3 = static_cast<T>(other);
|
|
||||||
x4_4 = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator+(const M& other) const {
|
|
||||||
return mat4x4<T>(x1_1 + static_cast<T>(other.x1_1), x1_2 + static_cast<T>(other.x1_2), x1_3 + static_cast<T>(other.x1_3), x1_4 + static_cast<T>(other.x1_4), x2_1 + static_cast<T>(other.x2_1), x2_2 + static_cast<T>(other.x2_2), x2_3 + static_cast<T>(other.x2_3), x2_4 + static_cast<T>(other.x2_4), x3_1 + static_cast<T>(other.x3_1), x3_2 + static_cast<T>(other.x3_2), x3_3 + static_cast<T>(other.x3_3), x3_4 + static_cast<T>(other.x3_4), x4_1 + static_cast<T>(other.x4_1), x4_2 + static_cast<T>(other.x4_2), x4_3 + static_cast<T>(other.x4_3), x4_4 + static_cast<T>(other.x4_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator-(const M& other) const {
|
|
||||||
return mat4x4<T>(x1_1 - static_cast<T>(other.x1_1), x1_2 - static_cast<T>(other.x1_2), x1_3 - static_cast<T>(other.x1_3), x1_4 - static_cast<T>(other.x1_4), x2_1 - static_cast<T>(other.x2_1), x2_2 - static_cast<T>(other.x2_2), x2_3 - static_cast<T>(other.x2_3), x2_4 - static_cast<T>(other.x2_4), x3_1 - static_cast<T>(other.x3_1), x3_2 - static_cast<T>(other.x3_2), x3_3 - static_cast<T>(other.x3_3), x3_4 - static_cast<T>(other.x3_4), x4_1 - static_cast<T>(other.x4_1), x4_2 - static_cast<T>(other.x4_2), x4_3 - static_cast<T>(other.x4_3), x4_4 - static_cast<T>(other.x4_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator%(const M& other) const {
|
|
||||||
return mat4x4<T>(x1_1 % static_cast<T>(other.x1_1), x1_2 % static_cast<T>(other.x1_2), x1_3 % static_cast<T>(other.x1_3), x1_4 % static_cast<T>(other.x1_4), x2_1 % static_cast<T>(other.x2_1), x2_2 % static_cast<T>(other.x2_2), x2_3 % static_cast<T>(other.x2_3), x2_4 % static_cast<T>(other.x2_4), x3_1 % static_cast<T>(other.x3_1), x3_2 % static_cast<T>(other.x3_2), x3_3 % static_cast<T>(other.x3_3), x3_4 % static_cast<T>(other.x3_4), x4_1 % static_cast<T>(other.x4_1), x4_2 % static_cast<T>(other.x4_2), x4_3 % static_cast<T>(other.x4_3), x4_4 % static_cast<T>(other.x4_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::compWiseMult(const M& other) const {
|
|
||||||
return mat4x4<T>(x1_1 * static_cast<T>(other.x1_1), x1_2 * static_cast<T>(other.x1_2), x1_3 * static_cast<T>(other.x1_3), x1_4 * static_cast<T>(other.x1_4), x2_1 * static_cast<T>(other.x2_1), x2_2 * static_cast<T>(other.x2_2), x2_3 * static_cast<T>(other.x2_3), x2_4 * static_cast<T>(other.x2_4), x3_1 * static_cast<T>(other.x3_1), x3_2 * static_cast<T>(other.x3_2), x3_3 * static_cast<T>(other.x3_3), x3_4 * static_cast<T>(other.x3_4), x4_1 * static_cast<T>(other.x4_1), x4_2 * static_cast<T>(other.x4_2), x4_3 * static_cast<T>(other.x4_3), x4_4 * static_cast<T>(other.x4_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::compWiseDiv(const M& other) const {
|
|
||||||
return mat4x4<T>(x1_1 / static_cast<T>(other.x1_1), x1_2 / static_cast<T>(other.x1_2), x1_3 / static_cast<T>(other.x1_3), x1_4 / static_cast<T>(other.x1_4), x2_1 / static_cast<T>(other.x2_1), x2_2 / static_cast<T>(other.x2_2), x2_3 / static_cast<T>(other.x2_3), x2_4 / static_cast<T>(other.x2_4), x3_1 / static_cast<T>(other.x3_1), x3_2 / static_cast<T>(other.x3_2), x3_3 / static_cast<T>(other.x3_3), x3_4 / static_cast<T>(other.x3_4), x4_1 / static_cast<T>(other.x4_1), x4_2 / static_cast<T>(other.x4_2), x4_3 / static_cast<T>(other.x4_3), x4_4 / static_cast<T>(other.x4_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void mat4x4<T>::operator+=(const M& other) {
|
|
||||||
x1_1 += static_cast<T>(other.x1_1);
|
|
||||||
x1_2 += static_cast<T>(other.x1_2);
|
|
||||||
x1_3 += static_cast<T>(other.x1_3);
|
|
||||||
x1_4 += static_cast<T>(other.x1_4);
|
|
||||||
x2_1 += static_cast<T>(other.x2_1);
|
|
||||||
x2_2 += static_cast<T>(other.x2_2);
|
|
||||||
x2_3 += static_cast<T>(other.x2_3);
|
|
||||||
x2_4 += static_cast<T>(other.x2_4);
|
|
||||||
x3_1 += static_cast<T>(other.x3_1);
|
|
||||||
x3_2 += static_cast<T>(other.x3_2);
|
|
||||||
x3_3 += static_cast<T>(other.x3_3);
|
|
||||||
x3_4 += static_cast<T>(other.x3_4);
|
|
||||||
x4_1 += static_cast<T>(other.x4_1);
|
|
||||||
x4_2 += static_cast<T>(other.x4_2);
|
|
||||||
x4_3 += static_cast<T>(other.x4_3);
|
|
||||||
x4_4 += static_cast<T>(other.x4_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void mat4x4<T>::operator-=(const M& other) {
|
|
||||||
x1_1 -= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 -= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 -= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 -= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 -= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 -= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 -= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 -= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 -= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 -= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 -= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 -= static_cast<T>(other.x3_4);
|
|
||||||
x4_1 -= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 -= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 -= static_cast<T>(other.x4_3);
|
|
||||||
x4_4 -= static_cast<T>(other.x4_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void mat4x4<T>::operator%=(const M& other) {
|
|
||||||
x1_1 %= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 %= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 %= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 %= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 %= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 %= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 %= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 %= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 %= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 %= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 %= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 %= static_cast<T>(other.x3_4);
|
|
||||||
x4_1 %= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 %= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 %= static_cast<T>(other.x4_3);
|
|
||||||
x4_4 %= static_cast<T>(other.x4_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void mat4x4<T>::compWiseAssMult(const M& other) {
|
|
||||||
x1_1 *= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 *= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 *= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 *= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 *= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 *= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 *= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 *= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 *= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 *= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 *= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 *= static_cast<T>(other.x3_4);
|
|
||||||
x4_1 *= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 *= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 *= static_cast<T>(other.x4_3);
|
|
||||||
x4_4 *= static_cast<T>(other.x4_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void mat4x4<T>::compWiseAssDiv(const M& other) {
|
|
||||||
x1_1 /= static_cast<T>(other.x1_1);
|
|
||||||
x1_2 /= static_cast<T>(other.x1_2);
|
|
||||||
x1_3 /= static_cast<T>(other.x1_3);
|
|
||||||
x1_4 /= static_cast<T>(other.x1_4);
|
|
||||||
x2_1 /= static_cast<T>(other.x2_1);
|
|
||||||
x2_2 /= static_cast<T>(other.x2_2);
|
|
||||||
x2_3 /= static_cast<T>(other.x2_3);
|
|
||||||
x2_4 /= static_cast<T>(other.x2_4);
|
|
||||||
x3_1 /= static_cast<T>(other.x3_1);
|
|
||||||
x3_2 /= static_cast<T>(other.x3_2);
|
|
||||||
x3_3 /= static_cast<T>(other.x3_3);
|
|
||||||
x3_4 /= static_cast<T>(other.x3_4);
|
|
||||||
x4_1 /= static_cast<T>(other.x4_1);
|
|
||||||
x4_2 /= static_cast<T>(other.x4_2);
|
|
||||||
x4_3 /= static_cast<T>(other.x4_3);
|
|
||||||
x4_4 /= static_cast<T>(other.x4_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator+(const N& other) const {
|
|
||||||
return mat4x4<T>(x1_1 + static_cast<T>(other), x1_2 + static_cast<T>(other), x1_3 + static_cast<T>(other), x1_4 + static_cast<T>(other), x2_1 + static_cast<T>(other), x2_2 + static_cast<T>(other), x2_3 + static_cast<T>(other), x2_4 + static_cast<T>(other), x3_1 + static_cast<T>(other), x3_2 + static_cast<T>(other), x3_3 + static_cast<T>(other), x3_4 + static_cast<T>(other), x4_1 + static_cast<T>(other), x4_2 + static_cast<T>(other), x4_3 + static_cast<T>(other), x4_4 + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator-(const N& other) const {
|
|
||||||
return mat4x4<T>(x1_1 - static_cast<T>(other), x1_2 - static_cast<T>(other), x1_3 - static_cast<T>(other), x1_4 - static_cast<T>(other), x2_1 - static_cast<T>(other), x2_2 - static_cast<T>(other), x2_3 - static_cast<T>(other), x2_4 - static_cast<T>(other), x3_1 - static_cast<T>(other), x3_2 - static_cast<T>(other), x3_3 - static_cast<T>(other), x3_4 - static_cast<T>(other), x4_1 - static_cast<T>(other), x4_2 - static_cast<T>(other), x4_3 - static_cast<T>(other), x4_4 - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator%(const N& other) const {
|
|
||||||
return mat4x4<T>(x1_1 % static_cast<T>(other), x1_2 % static_cast<T>(other), x1_3 % static_cast<T>(other), x1_4 % static_cast<T>(other), x2_1 % static_cast<T>(other), x2_2 % static_cast<T>(other), x2_3 % static_cast<T>(other), x2_4 % static_cast<T>(other), x3_1 % static_cast<T>(other), x3_2 % static_cast<T>(other), x3_3 % static_cast<T>(other), x3_4 % static_cast<T>(other), x4_1 % static_cast<T>(other), x4_2 % static_cast<T>(other), x4_3 % static_cast<T>(other), x4_4 % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::compWiseMult(const N& other) const {
|
|
||||||
return mat4x4<T>(x1_1 * static_cast<T>(other), x1_2 * static_cast<T>(other), x1_3 * static_cast<T>(other), x1_4 * static_cast<T>(other), x2_1 * static_cast<T>(other), x2_2 * static_cast<T>(other), x2_3 * static_cast<T>(other), x2_4 * static_cast<T>(other), x3_1 * static_cast<T>(other), x3_2 * static_cast<T>(other), x3_3 * static_cast<T>(other), x3_4 * static_cast<T>(other), x4_1 * static_cast<T>(other), x4_2 * static_cast<T>(other), x4_3 * static_cast<T>(other), x4_4 * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::compWiseDiv(const N& other) const {
|
|
||||||
return mat4x4<T>(x1_1 / static_cast<T>(other), x1_2 / static_cast<T>(other), x1_3 / static_cast<T>(other), x1_4 / static_cast<T>(other), x2_1 / static_cast<T>(other), x2_2 / static_cast<T>(other), x2_3 / static_cast<T>(other), x2_4 / static_cast<T>(other), x3_1 / static_cast<T>(other), x3_2 / static_cast<T>(other), x3_3 / static_cast<T>(other), x3_4 / static_cast<T>(other), x4_1 / static_cast<T>(other), x4_2 / static_cast<T>(other), x4_3 / static_cast<T>(other), x4_4 / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::operator+=(const N& other) {
|
|
||||||
x1_1 += static_cast<T>(other);
|
|
||||||
x1_2 += static_cast<T>(other);
|
|
||||||
x1_3 += static_cast<T>(other);
|
|
||||||
x1_4 += static_cast<T>(other);
|
|
||||||
x2_1 += static_cast<T>(other);
|
|
||||||
x2_2 += static_cast<T>(other);
|
|
||||||
x2_3 += static_cast<T>(other);
|
|
||||||
x2_4 += static_cast<T>(other);
|
|
||||||
x3_1 += static_cast<T>(other);
|
|
||||||
x3_2 += static_cast<T>(other);
|
|
||||||
x3_3 += static_cast<T>(other);
|
|
||||||
x3_4 += static_cast<T>(other);
|
|
||||||
x4_1 += static_cast<T>(other);
|
|
||||||
x4_2 += static_cast<T>(other);
|
|
||||||
x4_3 += static_cast<T>(other);
|
|
||||||
x4_4 += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::operator-=(const N& other) {
|
|
||||||
x1_1 -= static_cast<T>(other);
|
|
||||||
x1_2 -= static_cast<T>(other);
|
|
||||||
x1_3 -= static_cast<T>(other);
|
|
||||||
x1_4 -= static_cast<T>(other);
|
|
||||||
x2_1 -= static_cast<T>(other);
|
|
||||||
x2_2 -= static_cast<T>(other);
|
|
||||||
x2_3 -= static_cast<T>(other);
|
|
||||||
x2_4 -= static_cast<T>(other);
|
|
||||||
x3_1 -= static_cast<T>(other);
|
|
||||||
x3_2 -= static_cast<T>(other);
|
|
||||||
x3_3 -= static_cast<T>(other);
|
|
||||||
x3_4 -= static_cast<T>(other);
|
|
||||||
x4_1 -= static_cast<T>(other);
|
|
||||||
x4_2 -= static_cast<T>(other);
|
|
||||||
x4_3 -= static_cast<T>(other);
|
|
||||||
x4_4 -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::operator%=(const N& other) {
|
|
||||||
x1_1 %= static_cast<T>(other);
|
|
||||||
x1_2 %= static_cast<T>(other);
|
|
||||||
x1_3 %= static_cast<T>(other);
|
|
||||||
x1_4 %= static_cast<T>(other);
|
|
||||||
x2_1 %= static_cast<T>(other);
|
|
||||||
x2_2 %= static_cast<T>(other);
|
|
||||||
x2_3 %= static_cast<T>(other);
|
|
||||||
x2_4 %= static_cast<T>(other);
|
|
||||||
x3_1 %= static_cast<T>(other);
|
|
||||||
x3_2 %= static_cast<T>(other);
|
|
||||||
x3_3 %= static_cast<T>(other);
|
|
||||||
x3_4 %= static_cast<T>(other);
|
|
||||||
x4_1 %= static_cast<T>(other);
|
|
||||||
x4_2 %= static_cast<T>(other);
|
|
||||||
x4_3 %= static_cast<T>(other);
|
|
||||||
x4_4 %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::compWiseAssMult(const N& other) {
|
|
||||||
x1_1 *= static_cast<T>(other);
|
|
||||||
x1_2 *= static_cast<T>(other);
|
|
||||||
x1_3 *= static_cast<T>(other);
|
|
||||||
x1_4 *= static_cast<T>(other);
|
|
||||||
x2_1 *= static_cast<T>(other);
|
|
||||||
x2_2 *= static_cast<T>(other);
|
|
||||||
x2_3 *= static_cast<T>(other);
|
|
||||||
x2_4 *= static_cast<T>(other);
|
|
||||||
x3_1 *= static_cast<T>(other);
|
|
||||||
x3_2 *= static_cast<T>(other);
|
|
||||||
x3_3 *= static_cast<T>(other);
|
|
||||||
x3_4 *= static_cast<T>(other);
|
|
||||||
x4_1 *= static_cast<T>(other);
|
|
||||||
x4_2 *= static_cast<T>(other);
|
|
||||||
x4_3 *= static_cast<T>(other);
|
|
||||||
x4_4 *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void mat4x4<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x1_1 /= static_cast<T>(other);
|
|
||||||
x1_2 /= static_cast<T>(other);
|
|
||||||
x1_3 /= static_cast<T>(other);
|
|
||||||
x1_4 /= static_cast<T>(other);
|
|
||||||
x2_1 /= static_cast<T>(other);
|
|
||||||
x2_2 /= static_cast<T>(other);
|
|
||||||
x2_3 /= static_cast<T>(other);
|
|
||||||
x2_4 /= static_cast<T>(other);
|
|
||||||
x3_1 /= static_cast<T>(other);
|
|
||||||
x3_2 /= static_cast<T>(other);
|
|
||||||
x3_3 /= static_cast<T>(other);
|
|
||||||
x3_4 /= static_cast<T>(other);
|
|
||||||
x4_1 /= static_cast<T>(other);
|
|
||||||
x4_2 /= static_cast<T>(other);
|
|
||||||
x4_3 /= static_cast<T>(other);
|
|
||||||
x4_4 /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> mat4x4<T>::operator*(const C& other) const {
|
|
||||||
vec4<T> new_;
|
|
||||||
new_.x = x1_1 * other.x + x1_2 * other.y + x1_3 * other.z + x1_4 * other.w;
|
|
||||||
new_.y = x2_1 * other.x + x2_2 * other.y + x2_3 * other.z + x2_4 * other.w;
|
|
||||||
new_.z = x3_1 * other.x + x3_2 * other.y + x3_3 * other.z + x3_4 * other.w;
|
|
||||||
new_.w = x4_1 * other.x + x4_2 * other.y + x4_3 * other.z + x4_4 * other.w;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> mat4x4<T>::operator*(const M& other) const {
|
|
||||||
mat4x2<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1 + x4_4 * other.x4_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2 + x4_4 * other.x4_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> mat4x4<T>::operator*(const M& other) const {
|
|
||||||
mat4x3<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1 + x4_4 * other.x4_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2 + x4_4 * other.x4_2;
|
|
||||||
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3 + x4_4 * other.x4_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> mat4x4<T>::operator*(const M& other) const {
|
|
||||||
mat4x4<T> new_;
|
|
||||||
new_.x1_1 = x1_1 * other.x1_1 + x1_2 * other.x2_1 + x1_3 * other.x3_1 + x1_4 * other.x4_1;
|
|
||||||
new_.x1_2 = x1_1 * other.x1_2 + x1_2 * other.x2_2 + x1_3 * other.x3_2 + x1_4 * other.x4_2;
|
|
||||||
new_.x1_3 = x1_1 * other.x1_3 + x1_2 * other.x2_3 + x1_3 * other.x3_3 + x1_4 * other.x4_3;
|
|
||||||
new_.x1_4 = x1_1 * other.x1_4 + x1_2 * other.x2_4 + x1_3 * other.x3_4 + x1_4 * other.x4_4;
|
|
||||||
new_.x2_1 = x2_1 * other.x1_1 + x2_2 * other.x2_1 + x2_3 * other.x3_1 + x2_4 * other.x4_1;
|
|
||||||
new_.x2_2 = x2_1 * other.x1_2 + x2_2 * other.x2_2 + x2_3 * other.x3_2 + x2_4 * other.x4_2;
|
|
||||||
new_.x2_3 = x2_1 * other.x1_3 + x2_2 * other.x2_3 + x2_3 * other.x3_3 + x2_4 * other.x4_3;
|
|
||||||
new_.x2_4 = x2_1 * other.x1_4 + x2_2 * other.x2_4 + x2_3 * other.x3_4 + x2_4 * other.x4_4;
|
|
||||||
new_.x3_1 = x3_1 * other.x1_1 + x3_2 * other.x2_1 + x3_3 * other.x3_1 + x3_4 * other.x4_1;
|
|
||||||
new_.x3_2 = x3_1 * other.x1_2 + x3_2 * other.x2_2 + x3_3 * other.x3_2 + x3_4 * other.x4_2;
|
|
||||||
new_.x3_3 = x3_1 * other.x1_3 + x3_2 * other.x2_3 + x3_3 * other.x3_3 + x3_4 * other.x4_3;
|
|
||||||
new_.x3_4 = x3_1 * other.x1_4 + x3_2 * other.x2_4 + x3_3 * other.x3_4 + x3_4 * other.x4_4;
|
|
||||||
new_.x4_1 = x4_1 * other.x1_1 + x4_2 * other.x2_1 + x4_3 * other.x3_1 + x4_4 * other.x4_1;
|
|
||||||
new_.x4_2 = x4_1 * other.x1_2 + x4_2 * other.x2_2 + x4_3 * other.x3_2 + x4_4 * other.x4_2;
|
|
||||||
new_.x4_3 = x4_1 * other.x1_3 + x4_2 * other.x2_3 + x4_3 * other.x3_3 + x4_4 * other.x4_3;
|
|
||||||
new_.x4_4 = x4_1 * other.x1_4 + x4_2 * other.x2_4 + x4_3 * other.x3_4 + x4_4 * other.x4_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool mat4x4<T>::operator==(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3 and x4_4 == other.x4_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool mat4x4<T>::operator<(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3 and x4_4 < other.x4_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool mat4x4<T>::operator>(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3 and x4_4 > other.x4_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool mat4x4<T>::operator!=(const M& other) const {
|
|
||||||
return x1_1 == other.x1_1 and x1_2 == other.x1_2 and x1_3 == other.x1_3 and x1_4 == other.x1_4 and x2_1 == other.x2_1 and x2_2 == other.x2_2 and x2_3 == other.x2_3 and x2_4 == other.x2_4 and x3_1 == other.x3_1 and x3_2 == other.x3_2 and x3_3 == other.x3_3 and x3_4 == other.x3_4 and x4_1 == other.x4_1 and x4_2 == other.x4_2 and x4_3 == other.x4_3 and x4_4 == other.x4_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool mat4x4<T>::operator<=(const M& other) const {
|
|
||||||
return x1_1 > other.x1_1 and x1_2 > other.x1_2 and x1_3 > other.x1_3 and x1_4 > other.x1_4 and x2_1 > other.x2_1 and x2_2 > other.x2_2 and x2_3 > other.x2_3 and x2_4 > other.x2_4 and x3_1 > other.x3_1 and x3_2 > other.x3_2 and x3_3 > other.x3_3 and x3_4 > other.x3_4 and x4_1 > other.x4_1 and x4_2 > other.x4_2 and x4_3 > other.x4_3 and x4_4 > other.x4_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool mat4x4<T>::operator>=(const M& other) const {
|
|
||||||
return x1_1 < other.x1_1 and x1_2 < other.x1_2 and x1_3 < other.x1_3 and x1_4 < other.x1_4 and x2_1 < other.x2_1 and x2_2 < other.x2_2 and x2_3 < other.x2_3 and x2_4 < other.x2_4 and x3_1 < other.x3_1 and x3_2 < other.x3_2 and x3_3 < other.x3_3 and x3_4 < other.x3_4 and x4_1 < other.x4_1 and x4_2 < other.x4_2 and x4_3 < other.x4_3 and x4_4 < other.x4_4;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x4<T>::operator==(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other and x4_1 == other and x4_2 == other and x4_3 == other and x4_4 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x4<T>::operator<(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other and x4_1 < other and x4_2 < other and x4_3 < other and x4_4 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x4<T>::operator>(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other and x4_1 > other and x4_2 > other and x4_3 > other and x4_4 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x4<T>::operator!=(const N& other) const {
|
|
||||||
return x1_1 == other and x1_2 == other and x1_3 == other and x1_4 == other and x2_1 == other and x2_2 == other and x2_3 == other and x2_4 == other and x3_1 == other and x3_2 == other and x3_3 == other and x3_4 == other and x4_1 == other and x4_2 == other and x4_3 == other and x4_4 == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x4<T>::operator<=(const N& other) const {
|
|
||||||
return x1_1 > other and x1_2 > other and x1_3 > other and x1_4 > other and x2_1 > other and x2_2 > other and x2_3 > other and x2_4 > other and x3_1 > other and x3_2 > other and x3_3 > other and x3_4 > other and x4_1 > other and x4_2 > other and x4_3 > other and x4_4 > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool mat4x4<T>::operator>=(const N& other) const {
|
|
||||||
return x1_1 < other and x1_2 < other and x1_3 < other and x1_4 < other and x2_1 < other and x2_2 < other and x2_3 < other and x2_4 < other and x3_1 < other and x3_2 < other and x3_3 < other and x3_4 < other and x4_1 < other and x4_2 < other and x4_3 < other and x4_4 < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float mat4x4<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x1_1 * x1_1) + static_cast<float>(x1_2 * x1_2) + static_cast<float>(x1_3 * x1_3) + static_cast<float>(x1_4 * x1_4) + static_cast<float>(x2_1 * x2_1) + static_cast<float>(x2_2 * x2_2) + static_cast<float>(x2_3 * x2_3) + static_cast<float>(x2_4 * x2_4) + static_cast<float>(x3_1 * x3_1) + static_cast<float>(x3_2 * x3_2) + static_cast<float>(x3_3 * x3_3) + static_cast<float>(x3_4 * x3_4) + static_cast<float>(x4_1 * x4_1) + static_cast<float>(x4_2 * x4_2) + static_cast<float>(x4_3 * x4_3) + static_cast<float>(x4_4 * x4_4));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat4x4<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T mat4x4<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T mat4x4<T>::dot(const mat4x4<N>& other) const {
|
|
||||||
return x1_1 * static_cast<T>(other.x1_1) + x1_2 * static_cast<T>(other.x1_2) + x1_3 * static_cast<T>(other.x1_3) + x1_4 * static_cast<T>(other.x1_4) + x2_1 * static_cast<T>(other.x2_1) + x2_2 * static_cast<T>(other.x2_2) + x2_3 * static_cast<T>(other.x2_3) + x2_4 * static_cast<T>(other.x2_4) + x3_1 * static_cast<T>(other.x3_1) + x3_2 * static_cast<T>(other.x3_2) + x3_3 * static_cast<T>(other.x3_3) + x3_4 * static_cast<T>(other.x3_4) + x4_1 * static_cast<T>(other.x4_1) + x4_2 * static_cast<T>(other.x4_2) + x4_3 * static_cast<T>(other.x4_3) + x4_4 * static_cast<T>(other.x4_4);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat4x4<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x1_1 + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T mat4x4<T>::at(std::size_t row, std::size_t col) const {
|
|
||||||
return *(&x1_1 + (row * 4 + col * 4) * sizeof(T));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr rvec4<T> mat4x4<T>::row(std::size_t i) const {
|
|
||||||
return rvec4<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)), *(&x1_1 + (4 * 3 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr vec4<T> mat4x4<T>::column(std::size_t i) const {
|
|
||||||
return vec4<T>(*(&x1_1 + (4 * 0 + i) * sizeof(T)), *(&x1_1 + (4 * 1 + i) * sizeof(T)), *(&x1_1 + (4 * 2 + i) * sizeof(T)), *(&x1_1 + (4 * 3 + i) * sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x4<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x4<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&x4_4 + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x4<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x1_1));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> mat4x4<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&x4_4 + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "mat4x4.tpp"
|
|
@ -1,219 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
template<Number T>
|
|
||||||
class vec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 16 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4 {
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr mat4x4()
|
|
||||||
: x1_1(0), x1_2(0), x1_3(0), x1_4(0), x2_1(0), x2_2(0), x2_3(0), x2_4(0), x3_1(0), x3_2(0), x3_3(0), x3_4(0), x4_1(0), x4_2(0), x4_3(0), x4_4(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4(const N n)
|
|
||||||
: x1_1(static_cast<T>(n)), x1_2(static_cast<T>(n)), x1_3(static_cast<T>(n)), x1_4(static_cast<T>(n)), x2_1(static_cast<T>(n)), x2_2(static_cast<T>(n)), x2_3(static_cast<T>(n)), x2_4(static_cast<T>(n)), x3_1(static_cast<T>(n)), x3_2(static_cast<T>(n)), x3_3(static_cast<T>(n)), x3_4(static_cast<T>(n)), x4_1(static_cast<T>(n)), x4_2(static_cast<T>(n)), x4_3(static_cast<T>(n)), x4_4(static_cast<T>(n)) {}
|
|
||||||
/// Create from scalars
|
|
||||||
template<Number N0_0, Number N0_1, Number N0_2, Number N0_3, Number N1_0, Number N1_1, Number N1_2, Number N1_3, Number N2_0, Number N2_1, Number N2_2, Number N2_3, Number N3_0, Number N3_1, Number N3_2, Number N3_3>
|
|
||||||
constexpr mat4x4(const N0_0 x1_1, const N0_1 x1_2, const N0_2 x1_3, const N0_3 x1_4, const N1_0 x2_1, const N1_1 x2_2, const N1_2 x2_3, const N1_3 x2_4, const N2_0 x3_1, const N2_1 x3_2, const N2_2 x3_3, const N2_3 x3_4, const N3_0 x4_1, const N3_1 x4_2, const N3_2 x4_3, const N3_3 x4_4)
|
|
||||||
: x1_1(static_cast<T>(x1_1)), x1_2(static_cast<T>(x1_2)), x1_3(static_cast<T>(x1_3)), x1_4(static_cast<T>(x1_4)), x2_1(static_cast<T>(x2_1)), x2_2(static_cast<T>(x2_2)), x2_3(static_cast<T>(x2_3)), x2_4(static_cast<T>(x2_4)), x3_1(static_cast<T>(x3_1)), x3_2(static_cast<T>(x3_2)), x3_3(static_cast<T>(x3_3)), x3_4(static_cast<T>(x3_4)), x4_1(static_cast<T>(x4_1)), x4_2(static_cast<T>(x4_2)), x4_3(static_cast<T>(x4_3)), x4_4(static_cast<T>(x4_4)) {}
|
|
||||||
/// Create from row vectors
|
|
||||||
template<RowVector4 V0, RowVector4 V1, RowVector4 V2, RowVector4 V3>
|
|
||||||
constexpr mat4x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v0.y)), x1_3(static_cast<T>(v0.z)), x1_4(static_cast<T>(v0.w)), x2_1(static_cast<T>(v1.x)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v1.z)), x2_4(static_cast<T>(v1.w)), x3_1(static_cast<T>(v2.x)), x3_2(static_cast<T>(v2.y)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v2.w)), x4_1(static_cast<T>(v3.x)), x4_2(static_cast<T>(v3.y)), x4_3(static_cast<T>(v3.z)), x4_4(static_cast<T>(v3.w)) {}
|
|
||||||
/// Create from column vectors
|
|
||||||
template<ColumnVector4 V0, ColumnVector4 V1, ColumnVector4 V2, ColumnVector4 V3>
|
|
||||||
constexpr mat4x4(const V0& v0, const V1& v1, const V2& v2, const V3& v3)
|
|
||||||
: x1_1(static_cast<T>(v0.x)), x1_2(static_cast<T>(v1.x)), x1_3(static_cast<T>(v2.x)), x1_4(static_cast<T>(v3.x)), x2_1(static_cast<T>(v0.y)), x2_2(static_cast<T>(v1.y)), x2_3(static_cast<T>(v2.y)), x2_4(static_cast<T>(v3.y)), x3_1(static_cast<T>(v0.z)), x3_2(static_cast<T>(v1.z)), x3_3(static_cast<T>(v2.z)), x3_4(static_cast<T>(v3.z)), x4_1(static_cast<T>(v0.w)), x4_2(static_cast<T>(v1.w)), x4_3(static_cast<T>(v2.w)), x4_4(static_cast<T>(v3.w)) {}
|
|
||||||
// Values
|
|
||||||
T x1_1;
|
|
||||||
T x1_2;
|
|
||||||
T x1_3;
|
|
||||||
T x1_4;
|
|
||||||
T x2_1;
|
|
||||||
T x2_2;
|
|
||||||
T x2_3;
|
|
||||||
T x2_4;
|
|
||||||
T x3_1;
|
|
||||||
T x3_2;
|
|
||||||
T x3_3;
|
|
||||||
T x3_4;
|
|
||||||
T x4_1;
|
|
||||||
T x4_2;
|
|
||||||
T x4_3;
|
|
||||||
T x4_4;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const mat4x4<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> operator+(const M& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> operator-(const M& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> operator%(const M& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> compWiseMult(const M& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> compWiseDiv(const M& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void operator+=(const M& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void operator-=(const M& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void operator%=(const M& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void compWiseAssMult(const M& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr void compWiseAssDiv(const M& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr mat4x4<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with vec4 -> vec4
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> operator*(const C& other) const;
|
|
||||||
/// Matrix multiplication with mat4x2 -> mat4x2
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr mat4x2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x3 -> mat4x3
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr mat4x3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x4 -> mat4x4
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr mat4x4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool operator==(const M& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool operator<(const M& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool operator>(const M& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool operator!=(const M& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool operator<=(const M& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr bool operator>=(const M& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const mat4x4<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Get the element at row and col. row and col start at 0
|
|
||||||
constexpr T at(std::size_t row, std::size_t col) const;
|
|
||||||
/// Get the ith row as column vector. i starts at 0
|
|
||||||
constexpr rvec4<T> row(std::size_t i) const;
|
|
||||||
/// Get the ith column as row vector. i starts at 0
|
|
||||||
constexpr vec4<T> column(std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // mat4x4
|
|
||||||
|
|
||||||
using mat4x4f = mat4x4<float>;
|
|
||||||
using mat4x4d = mat4x4<double>;
|
|
||||||
using mat4x4i = mat4x4<int>;
|
|
||||||
using mat4x4u = mat4x4<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(Mat4x4<mat4x4<int>>, "mat4x4<int> does not satisfy the concept Mat4x4");
|
|
||||||
} // namespace gz
|
|
4559
src/math/mat4x4.tpp
4559
src/math/mat4x4.tpp
File diff suppressed because it is too large
Load Diff
@ -1,279 +0,0 @@
|
|||||||
#include "rvec2.hpp"
|
|
||||||
|
|
||||||
#include "mat2x2.hpp"
|
|
||||||
#include "mat2x3.hpp"
|
|
||||||
#include "mat2x4.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
#include "vec2.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS rvec2
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::operator=(const rvec2<N>& other) {
|
|
||||||
x = static_cast<T>(other.x);
|
|
||||||
y = static_cast<T>(other.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::operator=(const N& other) {
|
|
||||||
x = static_cast<T>(other);
|
|
||||||
y = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator+(const R& other) const {
|
|
||||||
return rvec2<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator-(const R& other) const {
|
|
||||||
return rvec2<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator%(const R& other) const {
|
|
||||||
return rvec2<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> rvec2<T>::compWiseMult(const R& other) const {
|
|
||||||
return rvec2<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> rvec2<T>::compWiseDiv(const R& other) const {
|
|
||||||
return rvec2<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void rvec2<T>::operator+=(const R& other) {
|
|
||||||
x += static_cast<T>(other.x);
|
|
||||||
y += static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void rvec2<T>::operator-=(const R& other) {
|
|
||||||
x -= static_cast<T>(other.x);
|
|
||||||
y -= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void rvec2<T>::operator%=(const R& other) {
|
|
||||||
x %= static_cast<T>(other.x);
|
|
||||||
y %= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void rvec2<T>::compWiseAssMult(const R& other) {
|
|
||||||
x *= static_cast<T>(other.x);
|
|
||||||
y *= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void rvec2<T>::compWiseAssDiv(const R& other) {
|
|
||||||
x /= static_cast<T>(other.x);
|
|
||||||
y /= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator+(const N& other) const {
|
|
||||||
return rvec2<T>(x + static_cast<T>(other), y + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator-(const N& other) const {
|
|
||||||
return rvec2<T>(x - static_cast<T>(other), y - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator%(const N& other) const {
|
|
||||||
return rvec2<T>(x % static_cast<T>(other), y % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> rvec2<T>::compWiseMult(const N& other) const {
|
|
||||||
return rvec2<T>(x * static_cast<T>(other), y * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> rvec2<T>::compWiseDiv(const N& other) const {
|
|
||||||
return rvec2<T>(x / static_cast<T>(other), y / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::operator+=(const N& other) {
|
|
||||||
x += static_cast<T>(other);
|
|
||||||
y += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::operator-=(const N& other) {
|
|
||||||
x -= static_cast<T>(other);
|
|
||||||
y -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::operator%=(const N& other) {
|
|
||||||
x %= static_cast<T>(other);
|
|
||||||
y %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::compWiseAssMult(const N& other) {
|
|
||||||
x *= static_cast<T>(other);
|
|
||||||
y *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec2<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x /= static_cast<T>(other);
|
|
||||||
y /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr rvec2<T> rvec2<T>::operator*(const M& other) const {
|
|
||||||
rvec2<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr rvec3<T> rvec2<T>::operator*(const M& other) const {
|
|
||||||
rvec3<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2;
|
|
||||||
new_.z = x * other.x1_3 + y * other.x2_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr rvec4<T> rvec2<T>::operator*(const M& other) const {
|
|
||||||
rvec4<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2;
|
|
||||||
new_.z = x * other.x1_3 + y * other.x2_3;
|
|
||||||
new_.w = x * other.x1_4 + y * other.x2_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool rvec2<T>::operator==(const R& other) const {
|
|
||||||
return x == other.x and y == other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool rvec2<T>::operator<(const R& other) const {
|
|
||||||
return x < other.x and y < other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool rvec2<T>::operator>(const R& other) const {
|
|
||||||
return x > other.x and y > other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool rvec2<T>::operator!=(const R& other) const {
|
|
||||||
return x == other.x and y == other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool rvec2<T>::operator<=(const R& other) const {
|
|
||||||
return x > other.x and y > other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool rvec2<T>::operator>=(const R& other) const {
|
|
||||||
return x < other.x and y < other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec2<T>::operator==(const N& other) const {
|
|
||||||
return x == other and y == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec2<T>::operator<(const N& other) const {
|
|
||||||
return x < other and y < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec2<T>::operator>(const N& other) const {
|
|
||||||
return x > other and y > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec2<T>::operator!=(const N& other) const {
|
|
||||||
return x == other and y == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec2<T>::operator<=(const N& other) const {
|
|
||||||
return x > other and y > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec2<T>::operator>=(const N& other) const {
|
|
||||||
return x < other and y < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float rvec2<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float rvec2<T>::ratio() const {
|
|
||||||
return static_cast<float>(x) / y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float rvec2<T>::invereseRatio() const {
|
|
||||||
return static_cast<float>(y) / x;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T rvec2<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T rvec2<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T rvec2<T>::dot(const rvec2<N>& other) const {
|
|
||||||
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T rvec2<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec2<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec2<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec2<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec2<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "rvec2.tpp"
|
|
@ -1,202 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
template<Number T>
|
|
||||||
class vec2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 2 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class rvec2 {
|
|
||||||
public:
|
|
||||||
/// just to satisfy concept RowVector
|
|
||||||
using isRowVector = T;
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr rvec2()
|
|
||||||
: x(0), y(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2(const N n)
|
|
||||||
: x(static_cast<T>(n)), y(static_cast<T>(n)) {}
|
|
||||||
/// Create from n n
|
|
||||||
template<Number N1, Number N2>
|
|
||||||
constexpr rvec2(N1 n1, N2 n2)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)) {}
|
|
||||||
/// Create from vec2
|
|
||||||
template<Vector2 V1>
|
|
||||||
constexpr rvec2(const V1& v1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)) {}
|
|
||||||
// Values
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const rvec2<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> operator+(const R& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> operator-(const R& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> operator%(const R& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> compWiseMult(const R& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr rvec2<T> compWiseDiv(const R& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void operator+=(const R& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void operator-=(const R& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void operator%=(const R& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void compWiseAssMult(const R& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr void compWiseAssDiv(const R& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec2<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with mat2x2 -> rvec2
|
|
||||||
template<Mat2x2 M>
|
|
||||||
constexpr rvec2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x3 -> rvec3
|
|
||||||
template<Mat2x3 M>
|
|
||||||
constexpr rvec3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat2x4 -> rvec4
|
|
||||||
template<Mat2x4 M>
|
|
||||||
constexpr rvec4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool operator==(const R& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool operator<(const R& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool operator>(const R& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool operator!=(const R& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool operator<=(const R& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr bool operator>=(const R& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns x/y
|
|
||||||
constexpr inline float ratio() const;
|
|
||||||
/// Returns y/x
|
|
||||||
constexpr inline float invereseRatio() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const rvec2<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // rvec2
|
|
||||||
|
|
||||||
using rvec2f = rvec2<float>;
|
|
||||||
using rvec2d = rvec2<double>;
|
|
||||||
using rvec2i = rvec2<int>;
|
|
||||||
using rvec2u = rvec2<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(RowVector2<rvec2<int>>, "rvec2<int> does not satisfy the concept RowVector2");
|
|
||||||
} // namespace gz
|
|
4437
src/math/rvec2.tpp
4437
src/math/rvec2.tpp
File diff suppressed because it is too large
Load Diff
@ -1,283 +0,0 @@
|
|||||||
#include "rvec3.hpp"
|
|
||||||
|
|
||||||
#include "mat3x2.hpp"
|
|
||||||
#include "mat3x3.hpp"
|
|
||||||
#include "mat3x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
#include "vec3.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS rvec3
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::operator=(const rvec3<N>& other) {
|
|
||||||
x = static_cast<T>(other.x);
|
|
||||||
y = static_cast<T>(other.y);
|
|
||||||
z = static_cast<T>(other.z);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::operator=(const N& other) {
|
|
||||||
x = static_cast<T>(other);
|
|
||||||
y = static_cast<T>(other);
|
|
||||||
z = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator+(const R& other) const {
|
|
||||||
return rvec3<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator-(const R& other) const {
|
|
||||||
return rvec3<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator%(const R& other) const {
|
|
||||||
return rvec3<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> rvec3<T>::compWiseMult(const R& other) const {
|
|
||||||
return rvec3<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> rvec3<T>::compWiseDiv(const R& other) const {
|
|
||||||
return rvec3<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void rvec3<T>::operator+=(const R& other) {
|
|
||||||
x += static_cast<T>(other.x);
|
|
||||||
y += static_cast<T>(other.y);
|
|
||||||
z += static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void rvec3<T>::operator-=(const R& other) {
|
|
||||||
x -= static_cast<T>(other.x);
|
|
||||||
y -= static_cast<T>(other.y);
|
|
||||||
z -= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void rvec3<T>::operator%=(const R& other) {
|
|
||||||
x %= static_cast<T>(other.x);
|
|
||||||
y %= static_cast<T>(other.y);
|
|
||||||
z %= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void rvec3<T>::compWiseAssMult(const R& other) {
|
|
||||||
x *= static_cast<T>(other.x);
|
|
||||||
y *= static_cast<T>(other.y);
|
|
||||||
z *= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void rvec3<T>::compWiseAssDiv(const R& other) {
|
|
||||||
x /= static_cast<T>(other.x);
|
|
||||||
y /= static_cast<T>(other.y);
|
|
||||||
z /= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator+(const N& other) const {
|
|
||||||
return rvec3<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator-(const N& other) const {
|
|
||||||
return rvec3<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator%(const N& other) const {
|
|
||||||
return rvec3<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> rvec3<T>::compWiseMult(const N& other) const {
|
|
||||||
return rvec3<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> rvec3<T>::compWiseDiv(const N& other) const {
|
|
||||||
return rvec3<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::operator+=(const N& other) {
|
|
||||||
x += static_cast<T>(other);
|
|
||||||
y += static_cast<T>(other);
|
|
||||||
z += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::operator-=(const N& other) {
|
|
||||||
x -= static_cast<T>(other);
|
|
||||||
y -= static_cast<T>(other);
|
|
||||||
z -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::operator%=(const N& other) {
|
|
||||||
x %= static_cast<T>(other);
|
|
||||||
y %= static_cast<T>(other);
|
|
||||||
z %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::compWiseAssMult(const N& other) {
|
|
||||||
x *= static_cast<T>(other);
|
|
||||||
y *= static_cast<T>(other);
|
|
||||||
z *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec3<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x /= static_cast<T>(other);
|
|
||||||
y /= static_cast<T>(other);
|
|
||||||
z /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr rvec2<T> rvec3<T>::operator*(const M& other) const {
|
|
||||||
rvec2<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr rvec3<T> rvec3<T>::operator*(const M& other) const {
|
|
||||||
rvec3<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2;
|
|
||||||
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr rvec4<T> rvec3<T>::operator*(const M& other) const {
|
|
||||||
rvec4<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2;
|
|
||||||
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3;
|
|
||||||
new_.w = x * other.x1_4 + y * other.x2_4 + z * other.x3_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool rvec3<T>::operator==(const R& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool rvec3<T>::operator<(const R& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool rvec3<T>::operator>(const R& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool rvec3<T>::operator!=(const R& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool rvec3<T>::operator<=(const R& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool rvec3<T>::operator>=(const R& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec3<T>::operator==(const N& other) const {
|
|
||||||
return x == other and y == other and z == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec3<T>::operator<(const N& other) const {
|
|
||||||
return x < other and y < other and z < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec3<T>::operator>(const N& other) const {
|
|
||||||
return x > other and y > other and z > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec3<T>::operator!=(const N& other) const {
|
|
||||||
return x == other and y == other and z == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec3<T>::operator<=(const N& other) const {
|
|
||||||
return x > other and y > other and z > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec3<T>::operator>=(const N& other) const {
|
|
||||||
return x < other and y < other and z < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float rvec3<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T rvec3<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T rvec3<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T rvec3<T>::dot(const rvec3<N>& other) const {
|
|
||||||
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T rvec3<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec3<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec3<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec3<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec3<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "rvec3.tpp"
|
|
@ -1,207 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
template<Number T>
|
|
||||||
class vec3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 3 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class rvec3 {
|
|
||||||
public:
|
|
||||||
/// just to satisfy concept RowVector
|
|
||||||
using isRowVector = T;
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr rvec3()
|
|
||||||
: x(0), y(0), z(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3(const N n)
|
|
||||||
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)) {}
|
|
||||||
/// Create from n n n
|
|
||||||
template<Number N1, Number N2, Number N3>
|
|
||||||
constexpr rvec3(N1 n1, N2 n2, N3 n3)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)) {}
|
|
||||||
/// Create from n vec2
|
|
||||||
template<Number N1, Vector3 V1>
|
|
||||||
constexpr rvec3(N1 n1, const V1& v1)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)) {}
|
|
||||||
/// Create from vec2 n
|
|
||||||
template<Vector3 V1, Number N1>
|
|
||||||
constexpr rvec3(const V1& v1, N1 n1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)) {}
|
|
||||||
/// Create from vec3
|
|
||||||
template<Vector3 V1>
|
|
||||||
constexpr rvec3(const V1& v1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)) {}
|
|
||||||
// Values
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
T z;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const rvec3<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> operator+(const R& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> operator-(const R& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> operator%(const R& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> compWiseMult(const R& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr rvec3<T> compWiseDiv(const R& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void operator+=(const R& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void operator-=(const R& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void operator%=(const R& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void compWiseAssMult(const R& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr void compWiseAssDiv(const R& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec3<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with mat3x2 -> rvec2
|
|
||||||
template<Mat3x2 M>
|
|
||||||
constexpr rvec2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x3 -> rvec3
|
|
||||||
template<Mat3x3 M>
|
|
||||||
constexpr rvec3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat3x4 -> rvec4
|
|
||||||
template<Mat3x4 M>
|
|
||||||
constexpr rvec4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool operator==(const R& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool operator<(const R& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool operator>(const R& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool operator!=(const R& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool operator<=(const R& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr bool operator>=(const R& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const rvec3<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // rvec3
|
|
||||||
|
|
||||||
using rvec3f = rvec3<float>;
|
|
||||||
using rvec3d = rvec3<double>;
|
|
||||||
using rvec3i = rvec3<int>;
|
|
||||||
using rvec3u = rvec3<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(RowVector3<rvec3<int>>, "rvec3<int> does not satisfy the concept RowVector3");
|
|
||||||
} // namespace gz
|
|
4437
src/math/rvec3.tpp
4437
src/math/rvec3.tpp
File diff suppressed because it is too large
Load Diff
@ -1,295 +0,0 @@
|
|||||||
#include "rvec4.hpp"
|
|
||||||
|
|
||||||
#include "mat4x2.hpp"
|
|
||||||
#include "mat4x3.hpp"
|
|
||||||
#include "mat4x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS rvec4
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::operator=(const rvec4<N>& other) {
|
|
||||||
x = static_cast<T>(other.x);
|
|
||||||
y = static_cast<T>(other.y);
|
|
||||||
z = static_cast<T>(other.z);
|
|
||||||
w = static_cast<T>(other.w);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::operator=(const N& other) {
|
|
||||||
x = static_cast<T>(other);
|
|
||||||
y = static_cast<T>(other);
|
|
||||||
z = static_cast<T>(other);
|
|
||||||
w = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator+(const R& other) const {
|
|
||||||
return rvec4<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z), w + static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator-(const R& other) const {
|
|
||||||
return rvec4<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z), w - static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator%(const R& other) const {
|
|
||||||
return rvec4<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z), w % static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> rvec4<T>::compWiseMult(const R& other) const {
|
|
||||||
return rvec4<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z), w * static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> rvec4<T>::compWiseDiv(const R& other) const {
|
|
||||||
return rvec4<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z), w / static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void rvec4<T>::operator+=(const R& other) {
|
|
||||||
x += static_cast<T>(other.x);
|
|
||||||
y += static_cast<T>(other.y);
|
|
||||||
z += static_cast<T>(other.z);
|
|
||||||
w += static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void rvec4<T>::operator-=(const R& other) {
|
|
||||||
x -= static_cast<T>(other.x);
|
|
||||||
y -= static_cast<T>(other.y);
|
|
||||||
z -= static_cast<T>(other.z);
|
|
||||||
w -= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void rvec4<T>::operator%=(const R& other) {
|
|
||||||
x %= static_cast<T>(other.x);
|
|
||||||
y %= static_cast<T>(other.y);
|
|
||||||
z %= static_cast<T>(other.z);
|
|
||||||
w %= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void rvec4<T>::compWiseAssMult(const R& other) {
|
|
||||||
x *= static_cast<T>(other.x);
|
|
||||||
y *= static_cast<T>(other.y);
|
|
||||||
z *= static_cast<T>(other.z);
|
|
||||||
w *= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void rvec4<T>::compWiseAssDiv(const R& other) {
|
|
||||||
x /= static_cast<T>(other.x);
|
|
||||||
y /= static_cast<T>(other.y);
|
|
||||||
z /= static_cast<T>(other.z);
|
|
||||||
w /= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator+(const N& other) const {
|
|
||||||
return rvec4<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other), w + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator-(const N& other) const {
|
|
||||||
return rvec4<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other), w - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator%(const N& other) const {
|
|
||||||
return rvec4<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other), w % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> rvec4<T>::compWiseMult(const N& other) const {
|
|
||||||
return rvec4<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other), w * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> rvec4<T>::compWiseDiv(const N& other) const {
|
|
||||||
return rvec4<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other), w / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::operator+=(const N& other) {
|
|
||||||
x += static_cast<T>(other);
|
|
||||||
y += static_cast<T>(other);
|
|
||||||
z += static_cast<T>(other);
|
|
||||||
w += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::operator-=(const N& other) {
|
|
||||||
x -= static_cast<T>(other);
|
|
||||||
y -= static_cast<T>(other);
|
|
||||||
z -= static_cast<T>(other);
|
|
||||||
w -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::operator%=(const N& other) {
|
|
||||||
x %= static_cast<T>(other);
|
|
||||||
y %= static_cast<T>(other);
|
|
||||||
z %= static_cast<T>(other);
|
|
||||||
w %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::compWiseAssMult(const N& other) {
|
|
||||||
x *= static_cast<T>(other);
|
|
||||||
y *= static_cast<T>(other);
|
|
||||||
z *= static_cast<T>(other);
|
|
||||||
w *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void rvec4<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x /= static_cast<T>(other);
|
|
||||||
y /= static_cast<T>(other);
|
|
||||||
z /= static_cast<T>(other);
|
|
||||||
w /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr rvec2<T> rvec4<T>::operator*(const M& other) const {
|
|
||||||
rvec2<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1 + w * other.x4_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2 + w * other.x4_2;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr rvec3<T> rvec4<T>::operator*(const M& other) const {
|
|
||||||
rvec3<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1 + w * other.x4_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2 + w * other.x4_2;
|
|
||||||
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3 + w * other.x4_3;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr rvec4<T> rvec4<T>::operator*(const M& other) const {
|
|
||||||
rvec4<T> new_;
|
|
||||||
new_.x = x * other.x1_1 + y * other.x2_1 + z * other.x3_1 + w * other.x4_1;
|
|
||||||
new_.y = x * other.x1_2 + y * other.x2_2 + z * other.x3_2 + w * other.x4_2;
|
|
||||||
new_.z = x * other.x1_3 + y * other.x2_3 + z * other.x3_3 + w * other.x4_3;
|
|
||||||
new_.w = x * other.x1_4 + y * other.x2_4 + z * other.x3_4 + w * other.x4_4;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool rvec4<T>::operator==(const R& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z and w == other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool rvec4<T>::operator<(const R& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z and w < other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool rvec4<T>::operator>(const R& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z and w > other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool rvec4<T>::operator!=(const R& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z and w == other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool rvec4<T>::operator<=(const R& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z and w > other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool rvec4<T>::operator>=(const R& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z and w < other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec4<T>::operator==(const N& other) const {
|
|
||||||
return x == other and y == other and z == other and w == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec4<T>::operator<(const N& other) const {
|
|
||||||
return x < other and y < other and z < other and w < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec4<T>::operator>(const N& other) const {
|
|
||||||
return x > other and y > other and z > other and w > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec4<T>::operator!=(const N& other) const {
|
|
||||||
return x == other and y == other and z == other and w == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec4<T>::operator<=(const N& other) const {
|
|
||||||
return x > other and y > other and z > other and w > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool rvec4<T>::operator>=(const N& other) const {
|
|
||||||
return x < other and y < other and z < other and w < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float rvec4<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z) + static_cast<float>(w * w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T rvec4<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T rvec4<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T rvec4<T>::dot(const rvec4<N>& other) const {
|
|
||||||
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z) + w * static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T rvec4<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec4<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec4<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec4<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> rvec4<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "rvec4.tpp"
|
|
@ -1,224 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class vec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 4 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class rvec4 {
|
|
||||||
public:
|
|
||||||
/// just to satisfy concept RowVector
|
|
||||||
using isRowVector = T;
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr rvec4()
|
|
||||||
: x(0), y(0), z(0), w(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4(const N n)
|
|
||||||
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)), w(static_cast<T>(n)) {}
|
|
||||||
/// Create from n n n n
|
|
||||||
template<Number N1, Number N2, Number N3, Number N4>
|
|
||||||
constexpr rvec4(N1 n1, N2 n2, N3 n3, N4 n4)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)), w(static_cast<T>(n4)) {}
|
|
||||||
/// Create from n n vec2
|
|
||||||
template<Number N1, Number N2, Vector4 V1>
|
|
||||||
constexpr rvec4(N1 n1, N2 n2, const V1& v1)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(v1.x)), w(static_cast<T>(v1.y)) {}
|
|
||||||
/// Create from n vec2 n
|
|
||||||
template<Number N1, Vector4 V1, Number N2>
|
|
||||||
constexpr rvec4(N1 n1, const V1& v1, N2 n2)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(n2)) {}
|
|
||||||
/// Create from n vec3
|
|
||||||
template<Number N1, Vector4 V1>
|
|
||||||
constexpr rvec4(N1 n1, const V1& v1)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(v1.z)) {}
|
|
||||||
/// Create from vec2 n n
|
|
||||||
template<Vector4 V1, Number N1, Number N2>
|
|
||||||
constexpr rvec4(const V1& v1, N1 n1, N2 n2)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)), w(static_cast<T>(n2)) {}
|
|
||||||
/// Create from vec2 vec2
|
|
||||||
template<Vector4 V1, Vector4 V2>
|
|
||||||
constexpr rvec4(const V1& v1, const V2& v2)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v2.x)), w(static_cast<T>(v2.y)) {}
|
|
||||||
/// Create from vec3 n
|
|
||||||
template<Vector4 V1, Number N1>
|
|
||||||
constexpr rvec4(const V1& v1, N1 n1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(n1)) {}
|
|
||||||
/// Create from vec4
|
|
||||||
template<Vector4 V1>
|
|
||||||
constexpr rvec4(const V1& v1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(v1.w)) {}
|
|
||||||
// Values
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
T z;
|
|
||||||
T w;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const rvec4<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> operator+(const R& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> operator-(const R& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> operator%(const R& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> compWiseMult(const R& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr rvec4<T> compWiseDiv(const R& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void operator+=(const R& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void operator-=(const R& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void operator%=(const R& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void compWiseAssMult(const R& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr void compWiseAssDiv(const R& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr rvec4<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with mat4x2 -> rvec2
|
|
||||||
template<Mat4x2 M>
|
|
||||||
constexpr rvec2<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x3 -> rvec3
|
|
||||||
template<Mat4x3 M>
|
|
||||||
constexpr rvec3<T> operator*(const M& other) const;
|
|
||||||
/// Matrix multiplication with mat4x4 -> rvec4
|
|
||||||
template<Mat4x4 M>
|
|
||||||
constexpr rvec4<T> operator*(const M& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool operator==(const R& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool operator<(const R& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool operator>(const R& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool operator!=(const R& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool operator<=(const R& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr bool operator>=(const R& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const rvec4<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // rvec4
|
|
||||||
|
|
||||||
using rvec4f = rvec4<float>;
|
|
||||||
using rvec4d = rvec4<double>;
|
|
||||||
using rvec4i = rvec4<int>;
|
|
||||||
using rvec4u = rvec4<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(RowVector4<rvec4<int>>, "rvec4<int> does not satisfy the concept RowVector4");
|
|
||||||
} // namespace gz
|
|
4437
src/math/rvec4.tpp
4437
src/math/rvec4.tpp
File diff suppressed because it is too large
Load Diff
@ -1,288 +0,0 @@
|
|||||||
#include "vec2.hpp"
|
|
||||||
|
|
||||||
#include "mat2x2.hpp"
|
|
||||||
#include "mat2x3.hpp"
|
|
||||||
#include "mat2x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS vec2
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::operator=(const vec2<N>& other) {
|
|
||||||
x = static_cast<T>(other.x);
|
|
||||||
y = static_cast<T>(other.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::operator=(const N& other) {
|
|
||||||
x = static_cast<T>(other);
|
|
||||||
y = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> vec2<T>::operator+(const C& other) const {
|
|
||||||
return vec2<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> vec2<T>::operator-(const C& other) const {
|
|
||||||
return vec2<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> vec2<T>::operator%(const C& other) const {
|
|
||||||
return vec2<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> vec2<T>::compWiseMult(const C& other) const {
|
|
||||||
return vec2<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> vec2<T>::compWiseDiv(const C& other) const {
|
|
||||||
return vec2<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void vec2<T>::operator+=(const C& other) {
|
|
||||||
x += static_cast<T>(other.x);
|
|
||||||
y += static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void vec2<T>::operator-=(const C& other) {
|
|
||||||
x -= static_cast<T>(other.x);
|
|
||||||
y -= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void vec2<T>::operator%=(const C& other) {
|
|
||||||
x %= static_cast<T>(other.x);
|
|
||||||
y %= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void vec2<T>::compWiseAssMult(const C& other) {
|
|
||||||
x *= static_cast<T>(other.x);
|
|
||||||
y *= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void vec2<T>::compWiseAssDiv(const C& other) {
|
|
||||||
x /= static_cast<T>(other.x);
|
|
||||||
y /= static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> vec2<T>::operator+(const N& other) const {
|
|
||||||
return vec2<T>(x + static_cast<T>(other), y + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> vec2<T>::operator-(const N& other) const {
|
|
||||||
return vec2<T>(x - static_cast<T>(other), y - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> vec2<T>::operator%(const N& other) const {
|
|
||||||
return vec2<T>(x % static_cast<T>(other), y % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> vec2<T>::compWiseMult(const N& other) const {
|
|
||||||
return vec2<T>(x * static_cast<T>(other), y * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> vec2<T>::compWiseDiv(const N& other) const {
|
|
||||||
return vec2<T>(x / static_cast<T>(other), y / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::operator+=(const N& other) {
|
|
||||||
x += static_cast<T>(other);
|
|
||||||
y += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::operator-=(const N& other) {
|
|
||||||
x -= static_cast<T>(other);
|
|
||||||
y -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::operator%=(const N& other) {
|
|
||||||
x %= static_cast<T>(other);
|
|
||||||
y %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::compWiseAssMult(const N& other) {
|
|
||||||
x *= static_cast<T>(other);
|
|
||||||
y *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec2<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x /= static_cast<T>(other);
|
|
||||||
y /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr mat2x2<T> vec2<T>::operator*(const R& other) const {
|
|
||||||
mat2x2<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr mat2x3<T> vec2<T>::operator*(const R& other) const {
|
|
||||||
mat2x3<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x1_3 = x * other.z;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x2_3 = y * other.z;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr mat2x4<T> vec2<T>::operator*(const R& other) const {
|
|
||||||
mat2x4<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x1_3 = x * other.z;
|
|
||||||
new_.x1_4 = x * other.w;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x2_3 = y * other.z;
|
|
||||||
new_.x2_4 = y * other.w;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool vec2<T>::operator==(const C& other) const {
|
|
||||||
return x == other.x and y == other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool vec2<T>::operator<(const C& other) const {
|
|
||||||
return x < other.x and y < other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool vec2<T>::operator>(const C& other) const {
|
|
||||||
return x > other.x and y > other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool vec2<T>::operator!=(const C& other) const {
|
|
||||||
return x == other.x and y == other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool vec2<T>::operator<=(const C& other) const {
|
|
||||||
return x > other.x and y > other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool vec2<T>::operator>=(const C& other) const {
|
|
||||||
return x < other.x and y < other.y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec2<T>::operator==(const N& other) const {
|
|
||||||
return x == other and y == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec2<T>::operator<(const N& other) const {
|
|
||||||
return x < other and y < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec2<T>::operator>(const N& other) const {
|
|
||||||
return x > other and y > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec2<T>::operator!=(const N& other) const {
|
|
||||||
return x == other and y == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec2<T>::operator<=(const N& other) const {
|
|
||||||
return x > other and y > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec2<T>::operator>=(const N& other) const {
|
|
||||||
return x < other and y < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float vec2<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float vec2<T>::ratio() const {
|
|
||||||
return static_cast<float>(x) / y;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float vec2<T>::invereseRatio() const {
|
|
||||||
return static_cast<float>(y) / x;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T vec2<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T vec2<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T vec2<T>::dot(const vec2<N>& other) const {
|
|
||||||
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T vec2<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec2<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec2<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec2<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec2<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&y + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "vec2.tpp"
|
|
@ -1,202 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat2x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat2x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 2 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class vec2 {
|
|
||||||
public:
|
|
||||||
/// just to satisfy concept ColumnVector
|
|
||||||
using isColumnVector = T;
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr vec2()
|
|
||||||
: x(0), y(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2(const N n)
|
|
||||||
: x(static_cast<T>(n)), y(static_cast<T>(n)) {}
|
|
||||||
/// Create from n n
|
|
||||||
template<Number N1, Number N2>
|
|
||||||
constexpr vec2(N1 n1, N2 n2)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)) {}
|
|
||||||
/// Create from vec2
|
|
||||||
template<Vector2 V1>
|
|
||||||
constexpr vec2(const V1& v1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)) {}
|
|
||||||
// Values
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const vec2<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> operator+(const C& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> operator-(const C& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> operator%(const C& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> compWiseMult(const C& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr vec2<T> compWiseDiv(const C& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void operator+=(const C& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void operator-=(const C& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void operator%=(const C& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void compWiseAssMult(const C& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr void compWiseAssDiv(const C& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec2<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with rvec2 -> mat2x2
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr mat2x2<T> operator*(const R& other) const;
|
|
||||||
/// Matrix multiplication with rvec3 -> mat2x3
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr mat2x3<T> operator*(const R& other) const;
|
|
||||||
/// Matrix multiplication with rvec4 -> mat2x4
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr mat2x4<T> operator*(const R& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool operator==(const C& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool operator<(const C& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool operator>(const C& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool operator!=(const C& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool operator<=(const C& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<ColumnVector2 C>
|
|
||||||
constexpr bool operator>=(const C& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns x/y
|
|
||||||
constexpr inline float ratio() const;
|
|
||||||
/// Returns y/x
|
|
||||||
constexpr inline float invereseRatio() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const vec2<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // vec2
|
|
||||||
|
|
||||||
using vec2f = vec2<float>;
|
|
||||||
using vec2d = vec2<double>;
|
|
||||||
using vec2i = vec2<int>;
|
|
||||||
using vec2u = vec2<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(ColumnVector2<vec2<int>>, "vec2<int> does not satisfy the concept ColumnVector2");
|
|
||||||
} // namespace gz
|
|
4437
src/math/vec2.tpp
4437
src/math/vec2.tpp
File diff suppressed because it is too large
Load Diff
@ -1,301 +0,0 @@
|
|||||||
#include "vec3.hpp"
|
|
||||||
|
|
||||||
#include "mat3x2.hpp"
|
|
||||||
#include "mat3x3.hpp"
|
|
||||||
#include "mat3x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS vec3
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::operator=(const vec3<N>& other) {
|
|
||||||
x = static_cast<T>(other.x);
|
|
||||||
y = static_cast<T>(other.y);
|
|
||||||
z = static_cast<T>(other.z);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::operator=(const N& other) {
|
|
||||||
x = static_cast<T>(other);
|
|
||||||
y = static_cast<T>(other);
|
|
||||||
z = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> vec3<T>::operator+(const C& other) const {
|
|
||||||
return vec3<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> vec3<T>::operator-(const C& other) const {
|
|
||||||
return vec3<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> vec3<T>::operator%(const C& other) const {
|
|
||||||
return vec3<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> vec3<T>::compWiseMult(const C& other) const {
|
|
||||||
return vec3<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> vec3<T>::compWiseDiv(const C& other) const {
|
|
||||||
return vec3<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void vec3<T>::operator+=(const C& other) {
|
|
||||||
x += static_cast<T>(other.x);
|
|
||||||
y += static_cast<T>(other.y);
|
|
||||||
z += static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void vec3<T>::operator-=(const C& other) {
|
|
||||||
x -= static_cast<T>(other.x);
|
|
||||||
y -= static_cast<T>(other.y);
|
|
||||||
z -= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void vec3<T>::operator%=(const C& other) {
|
|
||||||
x %= static_cast<T>(other.x);
|
|
||||||
y %= static_cast<T>(other.y);
|
|
||||||
z %= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void vec3<T>::compWiseAssMult(const C& other) {
|
|
||||||
x *= static_cast<T>(other.x);
|
|
||||||
y *= static_cast<T>(other.y);
|
|
||||||
z *= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void vec3<T>::compWiseAssDiv(const C& other) {
|
|
||||||
x /= static_cast<T>(other.x);
|
|
||||||
y /= static_cast<T>(other.y);
|
|
||||||
z /= static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> vec3<T>::operator+(const N& other) const {
|
|
||||||
return vec3<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> vec3<T>::operator-(const N& other) const {
|
|
||||||
return vec3<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> vec3<T>::operator%(const N& other) const {
|
|
||||||
return vec3<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> vec3<T>::compWiseMult(const N& other) const {
|
|
||||||
return vec3<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> vec3<T>::compWiseDiv(const N& other) const {
|
|
||||||
return vec3<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::operator+=(const N& other) {
|
|
||||||
x += static_cast<T>(other);
|
|
||||||
y += static_cast<T>(other);
|
|
||||||
z += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::operator-=(const N& other) {
|
|
||||||
x -= static_cast<T>(other);
|
|
||||||
y -= static_cast<T>(other);
|
|
||||||
z -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::operator%=(const N& other) {
|
|
||||||
x %= static_cast<T>(other);
|
|
||||||
y %= static_cast<T>(other);
|
|
||||||
z %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::compWiseAssMult(const N& other) {
|
|
||||||
x *= static_cast<T>(other);
|
|
||||||
y *= static_cast<T>(other);
|
|
||||||
z *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec3<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x /= static_cast<T>(other);
|
|
||||||
y /= static_cast<T>(other);
|
|
||||||
z /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr mat3x2<T> vec3<T>::operator*(const R& other) const {
|
|
||||||
mat3x2<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x3_1 = z * other.x;
|
|
||||||
new_.x3_2 = z * other.y;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr mat3x3<T> vec3<T>::operator*(const R& other) const {
|
|
||||||
mat3x3<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x1_3 = x * other.z;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x2_3 = y * other.z;
|
|
||||||
new_.x3_1 = z * other.x;
|
|
||||||
new_.x3_2 = z * other.y;
|
|
||||||
new_.x3_3 = z * other.z;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr mat3x4<T> vec3<T>::operator*(const R& other) const {
|
|
||||||
mat3x4<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x1_3 = x * other.z;
|
|
||||||
new_.x1_4 = x * other.w;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x2_3 = y * other.z;
|
|
||||||
new_.x2_4 = y * other.w;
|
|
||||||
new_.x3_1 = z * other.x;
|
|
||||||
new_.x3_2 = z * other.y;
|
|
||||||
new_.x3_3 = z * other.z;
|
|
||||||
new_.x3_4 = z * other.w;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool vec3<T>::operator==(const C& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool vec3<T>::operator<(const C& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool vec3<T>::operator>(const C& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool vec3<T>::operator!=(const C& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool vec3<T>::operator<=(const C& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool vec3<T>::operator>=(const C& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec3<T>::operator==(const N& other) const {
|
|
||||||
return x == other and y == other and z == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec3<T>::operator<(const N& other) const {
|
|
||||||
return x < other and y < other and z < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec3<T>::operator>(const N& other) const {
|
|
||||||
return x > other and y > other and z > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec3<T>::operator!=(const N& other) const {
|
|
||||||
return x == other and y == other and z == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec3<T>::operator<=(const N& other) const {
|
|
||||||
return x > other and y > other and z > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec3<T>::operator>=(const N& other) const {
|
|
||||||
return x < other and y < other and z < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float vec3<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T vec3<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T vec3<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T vec3<T>::dot(const vec3<N>& other) const {
|
|
||||||
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T vec3<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec3<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec3<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec3<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec3<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&z + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "vec3.tpp"
|
|
@ -1,207 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat3x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat3x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 3 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class vec3 {
|
|
||||||
public:
|
|
||||||
/// just to satisfy concept ColumnVector
|
|
||||||
using isColumnVector = T;
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr vec3()
|
|
||||||
: x(0), y(0), z(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3(const N n)
|
|
||||||
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)) {}
|
|
||||||
/// Create from n n n
|
|
||||||
template<Number N1, Number N2, Number N3>
|
|
||||||
constexpr vec3(N1 n1, N2 n2, N3 n3)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)) {}
|
|
||||||
/// Create from n vec2
|
|
||||||
template<Number N1, Vector3 V1>
|
|
||||||
constexpr vec3(N1 n1, const V1& v1)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)) {}
|
|
||||||
/// Create from vec2 n
|
|
||||||
template<Vector3 V1, Number N1>
|
|
||||||
constexpr vec3(const V1& v1, N1 n1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)) {}
|
|
||||||
/// Create from vec3
|
|
||||||
template<Vector3 V1>
|
|
||||||
constexpr vec3(const V1& v1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)) {}
|
|
||||||
// Values
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
T z;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const vec3<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> operator+(const C& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> operator-(const C& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> operator%(const C& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> compWiseMult(const C& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr vec3<T> compWiseDiv(const C& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void operator+=(const C& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void operator-=(const C& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void operator%=(const C& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void compWiseAssMult(const C& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr void compWiseAssDiv(const C& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec3<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with rvec2 -> mat3x2
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr mat3x2<T> operator*(const R& other) const;
|
|
||||||
/// Matrix multiplication with rvec3 -> mat3x3
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr mat3x3<T> operator*(const R& other) const;
|
|
||||||
/// Matrix multiplication with rvec4 -> mat3x4
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr mat3x4<T> operator*(const R& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool operator==(const C& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool operator<(const C& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool operator>(const C& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool operator!=(const C& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool operator<=(const C& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<ColumnVector3 C>
|
|
||||||
constexpr bool operator>=(const C& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const vec3<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // vec3
|
|
||||||
|
|
||||||
using vec3f = vec3<float>;
|
|
||||||
using vec3d = vec3<double>;
|
|
||||||
using vec3i = vec3<int>;
|
|
||||||
using vec3u = vec3<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(ColumnVector3<vec3<int>>, "vec3<int> does not satisfy the concept ColumnVector3");
|
|
||||||
} // namespace gz
|
|
4437
src/math/vec3.tpp
4437
src/math/vec3.tpp
File diff suppressed because it is too large
Load Diff
@ -1,322 +0,0 @@
|
|||||||
#include "vec4.hpp"
|
|
||||||
|
|
||||||
#include "mat4x2.hpp"
|
|
||||||
#include "mat4x3.hpp"
|
|
||||||
#include "mat4x4.hpp"
|
|
||||||
#include "rvec2.hpp"
|
|
||||||
#include "rvec3.hpp"
|
|
||||||
#include "rvec4.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLASS vec4
|
|
||||||
//
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::operator=(const vec4<N>& other) {
|
|
||||||
x = static_cast<T>(other.x);
|
|
||||||
y = static_cast<T>(other.y);
|
|
||||||
z = static_cast<T>(other.z);
|
|
||||||
w = static_cast<T>(other.w);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::operator=(const N& other) {
|
|
||||||
x = static_cast<T>(other);
|
|
||||||
y = static_cast<T>(other);
|
|
||||||
z = static_cast<T>(other);
|
|
||||||
w = static_cast<T>(other);
|
|
||||||
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> vec4<T>::operator+(const C& other) const {
|
|
||||||
return vec4<T>(x + static_cast<T>(other.x), y + static_cast<T>(other.y), z + static_cast<T>(other.z), w + static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> vec4<T>::operator-(const C& other) const {
|
|
||||||
return vec4<T>(x - static_cast<T>(other.x), y - static_cast<T>(other.y), z - static_cast<T>(other.z), w - static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> vec4<T>::operator%(const C& other) const {
|
|
||||||
return vec4<T>(x % static_cast<T>(other.x), y % static_cast<T>(other.y), z % static_cast<T>(other.z), w % static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> vec4<T>::compWiseMult(const C& other) const {
|
|
||||||
return vec4<T>(x * static_cast<T>(other.x), y * static_cast<T>(other.y), z * static_cast<T>(other.z), w * static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> vec4<T>::compWiseDiv(const C& other) const {
|
|
||||||
return vec4<T>(x / static_cast<T>(other.x), y / static_cast<T>(other.y), z / static_cast<T>(other.z), w / static_cast<T>(other.w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void vec4<T>::operator+=(const C& other) {
|
|
||||||
x += static_cast<T>(other.x);
|
|
||||||
y += static_cast<T>(other.y);
|
|
||||||
z += static_cast<T>(other.z);
|
|
||||||
w += static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void vec4<T>::operator-=(const C& other) {
|
|
||||||
x -= static_cast<T>(other.x);
|
|
||||||
y -= static_cast<T>(other.y);
|
|
||||||
z -= static_cast<T>(other.z);
|
|
||||||
w -= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void vec4<T>::operator%=(const C& other) {
|
|
||||||
x %= static_cast<T>(other.x);
|
|
||||||
y %= static_cast<T>(other.y);
|
|
||||||
z %= static_cast<T>(other.z);
|
|
||||||
w %= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void vec4<T>::compWiseAssMult(const C& other) {
|
|
||||||
x *= static_cast<T>(other.x);
|
|
||||||
y *= static_cast<T>(other.y);
|
|
||||||
z *= static_cast<T>(other.z);
|
|
||||||
w *= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void vec4<T>::compWiseAssDiv(const C& other) {
|
|
||||||
x /= static_cast<T>(other.x);
|
|
||||||
y /= static_cast<T>(other.y);
|
|
||||||
z /= static_cast<T>(other.z);
|
|
||||||
w /= static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> vec4<T>::operator+(const N& other) const {
|
|
||||||
return vec4<T>(x + static_cast<T>(other), y + static_cast<T>(other), z + static_cast<T>(other), w + static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> vec4<T>::operator-(const N& other) const {
|
|
||||||
return vec4<T>(x - static_cast<T>(other), y - static_cast<T>(other), z - static_cast<T>(other), w - static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> vec4<T>::operator%(const N& other) const {
|
|
||||||
return vec4<T>(x % static_cast<T>(other), y % static_cast<T>(other), z % static_cast<T>(other), w % static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> vec4<T>::compWiseMult(const N& other) const {
|
|
||||||
return vec4<T>(x * static_cast<T>(other), y * static_cast<T>(other), z * static_cast<T>(other), w * static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> vec4<T>::compWiseDiv(const N& other) const {
|
|
||||||
return vec4<T>(x / static_cast<T>(other), y / static_cast<T>(other), z / static_cast<T>(other), w / static_cast<T>(other));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::operator+=(const N& other) {
|
|
||||||
x += static_cast<T>(other);
|
|
||||||
y += static_cast<T>(other);
|
|
||||||
z += static_cast<T>(other);
|
|
||||||
w += static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::operator-=(const N& other) {
|
|
||||||
x -= static_cast<T>(other);
|
|
||||||
y -= static_cast<T>(other);
|
|
||||||
z -= static_cast<T>(other);
|
|
||||||
w -= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::operator%=(const N& other) {
|
|
||||||
x %= static_cast<T>(other);
|
|
||||||
y %= static_cast<T>(other);
|
|
||||||
z %= static_cast<T>(other);
|
|
||||||
w %= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::compWiseAssMult(const N& other) {
|
|
||||||
x *= static_cast<T>(other);
|
|
||||||
y *= static_cast<T>(other);
|
|
||||||
z *= static_cast<T>(other);
|
|
||||||
w *= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr void vec4<T>::compWiseAssDiv(const N& other) {
|
|
||||||
x /= static_cast<T>(other);
|
|
||||||
y /= static_cast<T>(other);
|
|
||||||
z /= static_cast<T>(other);
|
|
||||||
w /= static_cast<T>(other);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr mat4x2<T> vec4<T>::operator*(const R& other) const {
|
|
||||||
mat4x2<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x3_1 = z * other.x;
|
|
||||||
new_.x3_2 = z * other.y;
|
|
||||||
new_.x4_1 = w * other.x;
|
|
||||||
new_.x4_2 = w * other.y;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr mat4x3<T> vec4<T>::operator*(const R& other) const {
|
|
||||||
mat4x3<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x1_3 = x * other.z;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x2_3 = y * other.z;
|
|
||||||
new_.x3_1 = z * other.x;
|
|
||||||
new_.x3_2 = z * other.y;
|
|
||||||
new_.x3_3 = z * other.z;
|
|
||||||
new_.x4_1 = w * other.x;
|
|
||||||
new_.x4_2 = w * other.y;
|
|
||||||
new_.x4_3 = w * other.z;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr mat4x4<T> vec4<T>::operator*(const R& other) const {
|
|
||||||
mat4x4<T> new_;
|
|
||||||
new_.x1_1 = x * other.x;
|
|
||||||
new_.x1_2 = x * other.y;
|
|
||||||
new_.x1_3 = x * other.z;
|
|
||||||
new_.x1_4 = x * other.w;
|
|
||||||
new_.x2_1 = y * other.x;
|
|
||||||
new_.x2_2 = y * other.y;
|
|
||||||
new_.x2_3 = y * other.z;
|
|
||||||
new_.x2_4 = y * other.w;
|
|
||||||
new_.x3_1 = z * other.x;
|
|
||||||
new_.x3_2 = z * other.y;
|
|
||||||
new_.x3_3 = z * other.z;
|
|
||||||
new_.x3_4 = z * other.w;
|
|
||||||
new_.x4_1 = w * other.x;
|
|
||||||
new_.x4_2 = w * other.y;
|
|
||||||
new_.x4_3 = w * other.z;
|
|
||||||
new_.x4_4 = w * other.w;
|
|
||||||
return new_;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool vec4<T>::operator==(const C& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z and w == other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool vec4<T>::operator<(const C& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z and w < other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool vec4<T>::operator>(const C& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z and w > other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool vec4<T>::operator!=(const C& other) const {
|
|
||||||
return x == other.x and y == other.y and z == other.z and w == other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool vec4<T>::operator<=(const C& other) const {
|
|
||||||
return x > other.x and y > other.y and z > other.z and w > other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool vec4<T>::operator>=(const C& other) const {
|
|
||||||
return x < other.x and y < other.y and z < other.z and w < other.w;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec4<T>::operator==(const N& other) const {
|
|
||||||
return x == other and y == other and z == other and w == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec4<T>::operator<(const N& other) const {
|
|
||||||
return x < other and y < other and z < other and w < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec4<T>::operator>(const N& other) const {
|
|
||||||
return x > other and y > other and z > other and w > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec4<T>::operator!=(const N& other) const {
|
|
||||||
return x == other and y == other and z == other and w == other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec4<T>::operator<=(const N& other) const {
|
|
||||||
return x > other and y > other and z > other and w > other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool vec4<T>::operator>=(const N& other) const {
|
|
||||||
return x < other and y < other and z < other and w < other;
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline float vec4<T>::abs() const {
|
|
||||||
return std::sqrt(static_cast<float>(x * x) + static_cast<float>(y * y) + static_cast<float>(z * z) + static_cast<float>(w * w));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T vec4<T>::min() const {
|
|
||||||
return *std::min_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr inline T vec4<T>::max() const {
|
|
||||||
return *std::max_element(cbegin(), cend());
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T vec4<T>::dot(const vec4<N>& other) const {
|
|
||||||
return x * static_cast<T>(other.x) + y * static_cast<T>(other.y) + z * static_cast<T>(other.z) + w * static_cast<T>(other.w);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr T vec4<T>::operator[](std::size_t i) const {
|
|
||||||
return *(&x + sizeof(T) * i);
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec4<T>::cbegin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec4<T>::cend() const {
|
|
||||||
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec4<T>::begin() const {
|
|
||||||
return Iterator(const_cast<T*>(&x));
|
|
||||||
}
|
|
||||||
template<Number T>
|
|
||||||
constexpr Iterator<T> vec4<T>::end() const {
|
|
||||||
return Iterator(const_cast<T*>(&w + sizeof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace gz
|
|
||||||
|
|
||||||
#include "vec4.tpp"
|
|
@ -1,224 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "concepts.hpp"
|
|
||||||
#include "../container/iterator.hpp"
|
|
||||||
|
|
||||||
namespace gz {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
template<Number T>
|
|
||||||
class mat4x2;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x3;
|
|
||||||
template<Number T>
|
|
||||||
class mat4x4;
|
|
||||||
template<Number T>
|
|
||||||
class rvec2;
|
|
||||||
template<Number T>
|
|
||||||
class rvec3;
|
|
||||||
template<Number T>
|
|
||||||
class rvec4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Class containing 4 numbers
|
|
||||||
*/
|
|
||||||
template<Number T>
|
|
||||||
class vec4 {
|
|
||||||
public:
|
|
||||||
/// just to satisfy concept ColumnVector
|
|
||||||
using isColumnVector = T;
|
|
||||||
// Constructors
|
|
||||||
/// Default constructor
|
|
||||||
constexpr vec4()
|
|
||||||
: x(0), y(0), z(0), w(0) {}
|
|
||||||
/// Create from scalar, all components will have value n
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4(const N n)
|
|
||||||
: x(static_cast<T>(n)), y(static_cast<T>(n)), z(static_cast<T>(n)), w(static_cast<T>(n)) {}
|
|
||||||
/// Create from n n n n
|
|
||||||
template<Number N1, Number N2, Number N3, Number N4>
|
|
||||||
constexpr vec4(N1 n1, N2 n2, N3 n3, N4 n4)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(n3)), w(static_cast<T>(n4)) {}
|
|
||||||
/// Create from n n vec2
|
|
||||||
template<Number N1, Number N2, Vector4 V1>
|
|
||||||
constexpr vec4(N1 n1, N2 n2, const V1& v1)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(n2)), z(static_cast<T>(v1.x)), w(static_cast<T>(v1.y)) {}
|
|
||||||
/// Create from n vec2 n
|
|
||||||
template<Number N1, Vector4 V1, Number N2>
|
|
||||||
constexpr vec4(N1 n1, const V1& v1, N2 n2)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(n2)) {}
|
|
||||||
/// Create from n vec3
|
|
||||||
template<Number N1, Vector4 V1>
|
|
||||||
constexpr vec4(N1 n1, const V1& v1)
|
|
||||||
: x(static_cast<T>(n1)), y(static_cast<T>(v1.x)), z(static_cast<T>(v1.y)), w(static_cast<T>(v1.z)) {}
|
|
||||||
/// Create from vec2 n n
|
|
||||||
template<Vector4 V1, Number N1, Number N2>
|
|
||||||
constexpr vec4(const V1& v1, N1 n1, N2 n2)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(n1)), w(static_cast<T>(n2)) {}
|
|
||||||
/// Create from vec2 vec2
|
|
||||||
template<Vector4 V1, Vector4 V2>
|
|
||||||
constexpr vec4(const V1& v1, const V2& v2)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v2.x)), w(static_cast<T>(v2.y)) {}
|
|
||||||
/// Create from vec3 n
|
|
||||||
template<Vector4 V1, Number N1>
|
|
||||||
constexpr vec4(const V1& v1, N1 n1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(n1)) {}
|
|
||||||
/// Create from vec4
|
|
||||||
template<Vector4 V1>
|
|
||||||
constexpr vec4(const V1& v1)
|
|
||||||
: x(static_cast<T>(v1.x)), y(static_cast<T>(v1.y)), z(static_cast<T>(v1.z)), w(static_cast<T>(v1.w)) {}
|
|
||||||
// Values
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
T z;
|
|
||||||
T w;
|
|
||||||
// Assignment
|
|
||||||
/// Component-wise assignment
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const vec4<N>& other);
|
|
||||||
/// Assignment from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator=(const N& other);
|
|
||||||
// Arithmetic
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise +
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> operator+(const C& other) const;
|
|
||||||
/// Component-wise -
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> operator-(const C& other) const;
|
|
||||||
/// Component-wise %
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> operator%(const C& other) const;
|
|
||||||
/// Component-wise *
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> compWiseMult(const C& other) const;
|
|
||||||
/// Component-wise /
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr vec4<T> compWiseDiv(const C& other) const;
|
|
||||||
/// Component-wise assignment +=
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void operator+=(const C& other);
|
|
||||||
/// Component-wise assignment -=
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void operator-=(const C& other);
|
|
||||||
/// Component-wise assignment %=
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void operator%=(const C& other);
|
|
||||||
/// Component-wise assignment *=
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void compWiseAssMult(const C& other);
|
|
||||||
/// Component-wise assignment /=
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr void compWiseAssDiv(const C& other);
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise + with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> operator+(const N& other) const;
|
|
||||||
/// Component-wise - with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> operator-(const N& other) const;
|
|
||||||
/// Component-wise % with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> operator%(const N& other) const;
|
|
||||||
/// Component-wise * with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> compWiseMult(const N& other) const;
|
|
||||||
/// Component-wise / with scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr vec4<T> compWiseDiv(const N& other) const;
|
|
||||||
/// Component-wise assignment += from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator+=(const N& other);
|
|
||||||
/// Component-wise assignment -= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator-=(const N& other);
|
|
||||||
/// Component-wise assignment %= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void operator%=(const N& other);
|
|
||||||
/// Component-wise assignment *= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssMult(const N& other);
|
|
||||||
/// Component-wise assignment /= from scalar
|
|
||||||
template<Number N>
|
|
||||||
constexpr void compWiseAssDiv(const N& other);
|
|
||||||
// Matrix Multiplication
|
|
||||||
/// Matrix multiplication with rvec2 -> mat4x2
|
|
||||||
template<RowVector2 R>
|
|
||||||
constexpr mat4x2<T> operator*(const R& other) const;
|
|
||||||
/// Matrix multiplication with rvec3 -> mat4x3
|
|
||||||
template<RowVector3 R>
|
|
||||||
constexpr mat4x3<T> operator*(const R& other) const;
|
|
||||||
/// Matrix multiplication with rvec4 -> mat4x4
|
|
||||||
template<RowVector4 R>
|
|
||||||
constexpr mat4x4<T> operator*(const R& other) const;
|
|
||||||
// Comparison
|
|
||||||
// Vectorial
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool operator==(const C& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool operator<(const C& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool operator>(const C& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool operator!=(const C& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool operator<=(const C& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<ColumnVector4 C>
|
|
||||||
constexpr bool operator>=(const C& other) const;
|
|
||||||
// Scalar
|
|
||||||
/// Component-wise comparison == (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator==(const N& other) const;
|
|
||||||
/// Component-wise comparison < (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<(const N& other) const;
|
|
||||||
/// Component-wise comparison > (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>(const N& other) const;
|
|
||||||
/// Component-wise comparison != (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator!=(const N& other) const;
|
|
||||||
/// Component-wise comparison <= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator<=(const N& other) const;
|
|
||||||
/// Component-wise comparison >= (and)
|
|
||||||
template<Number N>
|
|
||||||
constexpr bool operator>=(const N& other) const;
|
|
||||||
// Functional
|
|
||||||
/// Returns the absolute value of the vector (sqrt of scalar product with itself)
|
|
||||||
constexpr inline float abs() const;
|
|
||||||
/// Returns the min of the components
|
|
||||||
constexpr inline T min() const;
|
|
||||||
/// Returns the max of the components
|
|
||||||
constexpr inline T max() const;
|
|
||||||
/// Scalar product (x1 * other.x1 + x2 * other.x2 ...)
|
|
||||||
template<Number N>
|
|
||||||
constexpr inline T dot(const vec4<N>& other) const;
|
|
||||||
// Utility
|
|
||||||
/// Get the ith element. i starts at 0
|
|
||||||
constexpr T operator[](std::size_t i) const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> cbegin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> cend() const;
|
|
||||||
/// Return an Iterator to the first element
|
|
||||||
constexpr Iterator<T> begin() const;
|
|
||||||
/// Return an Iterator past the last element
|
|
||||||
constexpr Iterator<T> end() const;
|
|
||||||
}; // vec4
|
|
||||||
|
|
||||||
using vec4f = vec4<float>;
|
|
||||||
using vec4d = vec4<double>;
|
|
||||||
using vec4i = vec4<int>;
|
|
||||||
using vec4u = vec4<unsigned int>;
|
|
||||||
|
|
||||||
|
|
||||||
static_assert(ColumnVector4<vec4<int>>, "vec4<int> does not satisfy the concept ColumnVector4");
|
|
||||||
} // namespace gz
|
|
4437
src/math/vec4.tpp
4437
src/math/vec4.tpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user