Skip to content

Commit

Permalink
added xyzw to quaternion
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Nov 8, 2023
1 parent cb4ca28 commit 94fd499
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 3 deletions.
32 changes: 32 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,38 @@ Quaternion__to_array <- function(self) {
.Call(`_ravetools_Quaternion__to_array`, self)
}

Quaternion__getX <- function(self) {
.Call(`_ravetools_Quaternion__getX`, self)
}

Quaternion__setX <- function(self, v) {
invisible(.Call(`_ravetools_Quaternion__setX`, self, v))
}

Quaternion__getY <- function(self) {
.Call(`_ravetools_Quaternion__getY`, self)
}

Quaternion__setY <- function(self, v) {
invisible(.Call(`_ravetools_Quaternion__setY`, self, v))
}

Quaternion__getZ <- function(self) {
.Call(`_ravetools_Quaternion__getZ`, self)
}

Quaternion__setZ <- function(self, v) {
invisible(.Call(`_ravetools_Quaternion__setZ`, self, v))
}

Quaternion__getW <- function(self) {
.Call(`_ravetools_Quaternion__getW`, self)
}

Quaternion__setW <- function(self, v) {
invisible(.Call(`_ravetools_Quaternion__setW`, self, v))
}

Quaternion__set_from_axis_angle <- function(self, axis, angle) {
invisible(.Call(`_ravetools_Quaternion__set_from_axis_angle`, self, axis, angle))
}
Expand Down
30 changes: 29 additions & 1 deletion R/class-Quaternion.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,35 @@ Quaternion <- R6::R6Class(
),
active = list(
is_quaternion = function() { TRUE },
pointer = function() { private$.extern_ptr }
pointer = function() { private$.extern_ptr },
x = function( v ) {
if(!missing(v)) {
v <- as.double(v)[[1]]
Quaternion__setX(private$.extern_ptr, v)
}
Quaternion__getX(private$.extern_ptr)
},
y = function( v ) {
if(!missing(v)) {
v <- as.double(v)[[1]]
Quaternion__setY(private$.extern_ptr, v)
}
Quaternion__getY(private$.extern_ptr)
},
z = function( v ) {
if(!missing(v)) {
v <- as.double(v)[[1]]
Quaternion__setZ(private$.extern_ptr, v)
}
Quaternion__getZ(private$.extern_ptr)
},
w = function( v ) {
if(!missing(v)) {
v <- as.double(v)[[1]]
Quaternion__setW(private$.extern_ptr, v)
}
Quaternion__getW(private$.extern_ptr)
}
),
public = list(
initialize = function() {
Expand Down
96 changes: 96 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,94 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// Quaternion__getX
double Quaternion__getX(const SEXP& self);
RcppExport SEXP _ravetools_Quaternion__getX(SEXP selfSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
rcpp_result_gen = Rcpp::wrap(Quaternion__getX(self));
return rcpp_result_gen;
END_RCPP
}
// Quaternion__setX
void Quaternion__setX(const SEXP& self, const double& v);
RcppExport SEXP _ravetools_Quaternion__setX(SEXP selfSEXP, SEXP vSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
Rcpp::traits::input_parameter< const double& >::type v(vSEXP);
Quaternion__setX(self, v);
return R_NilValue;
END_RCPP
}
// Quaternion__getY
double Quaternion__getY(const SEXP& self);
RcppExport SEXP _ravetools_Quaternion__getY(SEXP selfSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
rcpp_result_gen = Rcpp::wrap(Quaternion__getY(self));
return rcpp_result_gen;
END_RCPP
}
// Quaternion__setY
void Quaternion__setY(const SEXP& self, const double& v);
RcppExport SEXP _ravetools_Quaternion__setY(SEXP selfSEXP, SEXP vSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
Rcpp::traits::input_parameter< const double& >::type v(vSEXP);
Quaternion__setY(self, v);
return R_NilValue;
END_RCPP
}
// Quaternion__getZ
double Quaternion__getZ(const SEXP& self);
RcppExport SEXP _ravetools_Quaternion__getZ(SEXP selfSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
rcpp_result_gen = Rcpp::wrap(Quaternion__getZ(self));
return rcpp_result_gen;
END_RCPP
}
// Quaternion__setZ
void Quaternion__setZ(const SEXP& self, const double& v);
RcppExport SEXP _ravetools_Quaternion__setZ(SEXP selfSEXP, SEXP vSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
Rcpp::traits::input_parameter< const double& >::type v(vSEXP);
Quaternion__setZ(self, v);
return R_NilValue;
END_RCPP
}
// Quaternion__getW
double Quaternion__getW(const SEXP& self);
RcppExport SEXP _ravetools_Quaternion__getW(SEXP selfSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
rcpp_result_gen = Rcpp::wrap(Quaternion__getW(self));
return rcpp_result_gen;
END_RCPP
}
// Quaternion__setW
void Quaternion__setW(const SEXP& self, const double& v);
RcppExport SEXP _ravetools_Quaternion__setW(SEXP selfSEXP, SEXP vSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const SEXP& >::type self(selfSEXP);
Rcpp::traits::input_parameter< const double& >::type v(vSEXP);
Quaternion__setW(self, v);
return R_NilValue;
END_RCPP
}
// Quaternion__set_from_axis_angle
void Quaternion__set_from_axis_angle(const SEXP& self, const SEXP& axis, const double& angle);
RcppExport SEXP _ravetools_Quaternion__set_from_axis_angle(SEXP selfSEXP, SEXP axisSEXP, SEXP angleSEXP) {
Expand Down Expand Up @@ -3581,6 +3669,14 @@ static const R_CallMethodDef CallEntries[] = {
{"_ravetools_Quaternion__set", (DL_FUNC) &_ravetools_Quaternion__set, 5},
{"_ravetools_Quaternion__copy", (DL_FUNC) &_ravetools_Quaternion__copy, 2},
{"_ravetools_Quaternion__to_array", (DL_FUNC) &_ravetools_Quaternion__to_array, 1},
{"_ravetools_Quaternion__getX", (DL_FUNC) &_ravetools_Quaternion__getX, 1},
{"_ravetools_Quaternion__setX", (DL_FUNC) &_ravetools_Quaternion__setX, 2},
{"_ravetools_Quaternion__getY", (DL_FUNC) &_ravetools_Quaternion__getY, 1},
{"_ravetools_Quaternion__setY", (DL_FUNC) &_ravetools_Quaternion__setY, 2},
{"_ravetools_Quaternion__getZ", (DL_FUNC) &_ravetools_Quaternion__getZ, 1},
{"_ravetools_Quaternion__setZ", (DL_FUNC) &_ravetools_Quaternion__setZ, 2},
{"_ravetools_Quaternion__getW", (DL_FUNC) &_ravetools_Quaternion__getW, 1},
{"_ravetools_Quaternion__setW", (DL_FUNC) &_ravetools_Quaternion__setW, 2},
{"_ravetools_Quaternion__set_from_axis_angle", (DL_FUNC) &_ravetools_Quaternion__set_from_axis_angle, 3},
{"_ravetools_Quaternion__set_from_rotation_matrix", (DL_FUNC) &_ravetools_Quaternion__set_from_rotation_matrix, 2},
{"_ravetools_Quaternion__set_from_unit_vectors", (DL_FUNC) &_ravetools_Quaternion__set_from_unit_vectors, 3},
Expand Down
41 changes: 41 additions & 0 deletions src/glQuaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,47 @@ SEXP Quaternion__to_array(const SEXP& self) {
return re;
}

// [[Rcpp::export]]
double Quaternion__getX(const SEXP& self) {
Rcpp::XPtr<Quaternion> ptr(self);
return ptr->x;
}
// [[Rcpp::export]]
void Quaternion__setX(const SEXP& self, const double& v) {
Rcpp::XPtr<Quaternion> ptr(self);
ptr->x = v;
}
// [[Rcpp::export]]
double Quaternion__getY(const SEXP& self) {
Rcpp::XPtr<Quaternion> ptr(self);
return ptr->y;
}
// [[Rcpp::export]]
void Quaternion__setY(const SEXP& self, const double& v) {
Rcpp::XPtr<Quaternion> ptr(self);
ptr->y = v;
}
// [[Rcpp::export]]
double Quaternion__getZ(const SEXP& self) {
Rcpp::XPtr<Quaternion> ptr(self);
return ptr->z;
}
// [[Rcpp::export]]
void Quaternion__setZ(const SEXP& self, const double& v) {
Rcpp::XPtr<Quaternion> ptr(self);
ptr->z = v;
}
// [[Rcpp::export]]
double Quaternion__getW(const SEXP& self) {
Rcpp::XPtr<Quaternion> ptr(self);
return ptr->w;
}
// [[Rcpp::export]]
void Quaternion__setW(const SEXP& self, const double& v) {
Rcpp::XPtr<Quaternion> ptr(self);
ptr->w = v;
}

// Quaternion& Quaternion::setFromEuler(const Euler& euler, bool update) {
//
// const auto x = euler.x(), y = euler.y(), z = euler.z();
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test-quaternion.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ test_that("Quaternion", {
# new THREE.Quaternion().set(1,2,3,4).premultiply(new THREE.Quaternion().set(4,3,2,1)).toArray()
q$set(1,2,3,4)
q1$set(4,3,2,1)
q$premultiply(q1)

expect_equal(q[], 1:4)
expect_equal(q1[], 4:1)

expect_equal(c(q$x, q$y, q$z, q$w), 1:4)
expect_equal(c(q1$x, q1$y, q1$z, q1$w), 4:1)

q$premultiply(q1)
if(!all(q[] == c(22, 4, 16, -12))) {
print(q)
stop(format(q))
stop(format(q), "\n", q$x, " ", q$y, " ", q$z, " ", q$w)
}

expect_equal(
Expand Down

0 comments on commit 94fd499

Please sign in to comment.