Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Dec 29, 2024
1 parent 1555326 commit d0df1fb
Showing 1 changed file with 38 additions and 137 deletions.
175 changes: 38 additions & 137 deletions src/sdf/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,150 +40,51 @@ Value Value::Y() { return Value(ValueKind::Y, 0.0); }

Value Value::Z() { return Value(ValueKind::Z, 0.0); }

Value Value::operator+(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::ADD, *this, other, Invalid()));
}

Value Value::operator-(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::SUB, *this, other, Invalid()));
}

Value Value::operator*(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::MUL, *this, other, Invalid()));
}

Value Value::operator/(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::DIV, *this, other, Invalid()));
}

Value Value::cond(const Value& then, const Value& otherwise) const {

Check warning on line 43 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L43

Added line #L43 was not covered by tests
return Value(
ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::CHOICE, *this, then, otherwise));

Check warning on line 46 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L46

Added line #L46 was not covered by tests
}

Value Value::mod(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::MOD, *this, other, Invalid()));
}

Value Value::min(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::MIN, *this, other, Invalid()));
}

Value Value::max(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::MAX, *this, other, Invalid()));
}

Value Value::operator==(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::EQ, *this, other, Invalid()));
}

Value Value::operator>(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::GT, *this, other, Invalid()));
}

Value Value::operator&&(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::MUL, *this, other, Invalid()));
}

Value Value::operator||(const Value& other) const {
return Value(ValueKind::OPERATION, std::make_shared<ValueOperation>(
OpCode::ADD, *this, other, Invalid()));
}

Value Value::abs() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::ABS, *this, Invalid(),
Invalid()));
}

Value Value::operator-() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::NEG, *this, Invalid(),
Invalid()));
}

Value Value::exp() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::EXP, *this, Invalid(),
Invalid()));
}

Value Value::log() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::LOG, *this, Invalid(),
Invalid()));
}

Value Value::sqrt() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::SQRT, *this, Invalid(),
Invalid()));
}

Value Value::floor() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::FLOOR, *this, Invalid(),
Invalid()));
}

Value Value::ceil() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::CEIL, *this, Invalid(),
Invalid()));
}

Value Value::round() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::ROUND, *this, Invalid(),
Invalid()));
}

Value Value::sin() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::SIN, *this, Invalid(),
Invalid()));
}

Value Value::cos() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::COS, *this, Invalid(),
Invalid()));
}

Value Value::tan() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::TAN, *this, Invalid(),
Invalid()));
}

Value Value::asin() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::ASIN, *this, Invalid(),
Invalid()));
}

Value Value::acos() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::ACOS, *this, Invalid(),
Invalid()));
}
#define MAKE_UNARY(NAME, OPCODE) \
Value Value::NAME() const { \
return Value(ValueKind::OPERATION, \
std::make_shared<ValueOperation>(OpCode::OPCODE, *this, \
Invalid(), Invalid())); \
}
#define MAKE_BINARY(NAME, OPCODE) \
Value Value::NAME(const Value& other) const { \
return Value(ValueKind::OPERATION, \
std::make_shared<ValueOperation>(OpCode::OPCODE, *this, \
other, Invalid())); \
}

Value Value::atan() const {
return Value(ValueKind::OPERATION,
std::make_shared<ValueOperation>(OpCode::ATAN, *this, Invalid(),
Invalid()));
}
MAKE_UNARY(abs, ABS)
MAKE_UNARY(operator-, NEG)
MAKE_UNARY(exp, EXP)
MAKE_UNARY(log, LOG)

Check warning on line 65 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L63-L65

Added lines #L63 - L65 were not covered by tests
MAKE_UNARY(sqrt, SQRT)
MAKE_UNARY(floor, FLOOR)
MAKE_UNARY(ceil, CEIL)
MAKE_UNARY(round, ROUND)

Check warning on line 69 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L67-L69

Added lines #L67 - L69 were not covered by tests
MAKE_UNARY(sin, SIN)
MAKE_UNARY(cos, COS)
MAKE_UNARY(tan, TAN)
MAKE_UNARY(asin, ASIN)
MAKE_UNARY(acos, ACOS)
MAKE_UNARY(atan, ATAN)

Check warning on line 75 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L72-L75

Added lines #L72 - L75 were not covered by tests

MAKE_BINARY(operator+, ADD)
MAKE_BINARY(operator-, SUB)
MAKE_BINARY(operator*, MUL)
MAKE_BINARY(operator/, DIV)
MAKE_BINARY(mod, MOD)

Check warning on line 81 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L81

Added line #L81 was not covered by tests
MAKE_BINARY(min, MIN)
MAKE_BINARY(max, MAX)
MAKE_BINARY(operator==, EQ)
MAKE_BINARY(operator>, GT)
MAKE_BINARY(operator&&, MUL)
MAKE_BINARY(operator||, ADD)

Check warning on line 87 in src/sdf/value.cpp

View check run for this annotation

Codecov / codecov/patch

src/sdf/value.cpp#L84-L87

Added lines #L84 - L87 were not covered by tests

Value::~Value() {
using VO = std::shared_ptr<ValueOperation>;
Expand Down

0 comments on commit d0df1fb

Please sign in to comment.