Skip to content

Commit 8b2ae61

Browse files
committed
[geogram] Update to 1.7.6
1 parent 98def2c commit 8b2ae61

346 files changed

Lines changed: 125415 additions & 32222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ include(cmake/geogram.cmake)
4848

4949
set(VORPALINE_VERSION_MAJOR 1)
5050
set(VORPALINE_VERSION_MINOR 7)
51-
set(VORPALINE_VERSION_PATCH 5)
51+
set(VORPALINE_VERSION_PATCH 6)
5252
set(VORPALINE_VERSION ${VORPALINE_VERSION_MAJOR}.${VORPALINE_VERSION_MINOR}.${VORPALINE_VERSION_PATCH})
5353

5454
set(VORPALINE_INCLUDE_SUBPATH geogram${VORPALINE_VERSION_MAJOR})

‎src/bin/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ endif()
2020

2121
if(GEOGRAM_WITH_FPG)
2222
add_subdirectory(fpg)
23+
add_subdirectory(pck)
2324
endif()

‎src/bin/pck/CMakeLists.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(APP_NAME pck)
2+
aux_source_directories(SOURCES "" .)
3+
vor_add_executable(${APP_NAME} ${SOURCES})
4+
target_link_libraries(${APP_NAME} geogram)
5+
install_runtime_targets(${APP_NAME})
6+
7+
set_target_properties(${APP_NAME} PROPERTIES FOLDER "GEOGRAM/Programs")
8+

‎src/bin/pck/expr.cpp‎

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
#include "expr.h"
2+
#include "interpreter.h"
3+
#include <geogram/basic/string.h>
4+
5+
extern "C" {
6+
#include <geogram/third_party/lua/lauxlib.h>
7+
#include <geogram/third_party/lua/lualib.h>
8+
}
9+
10+
11+
12+
namespace GEO {
13+
14+
namespace String {
15+
std::string to_string(Expr* e) {
16+
return e->atomic() ? e->to_string() : "(" + e->to_string() + ")";
17+
}
18+
}
19+
20+
/**************************************************************************/
21+
22+
Expr::~Expr() { }
23+
24+
std::string Expr::name() const {
25+
std::string result;
26+
27+
// Try to find this variable in Lua's global scope,
28+
// if found, use its name.
29+
lua_State* L = Interpreter::instance()->lua_state();
30+
lua_pushglobaltable(L);
31+
int index = lua_gettop(L);
32+
lua_pushnil(L);
33+
while(lua_next(L,index) != 0) {
34+
if(lua_isexpr(L,-1) && lua_toexpr(L,-1) == this) {
35+
result = std::string(lua_tostring(L,-2));
36+
37+
}
38+
lua_pop(L,1);
39+
}
40+
41+
// If not found in Lua's global scope, generate a unique ID
42+
// from this Expr's address.
43+
if(result.length() == 0) {
44+
result = "expr@" + String::to_string(this);
45+
}
46+
return result;
47+
}
48+
49+
/**************************************************************************/
50+
51+
Expr::Type Constant::type() const {
52+
return SCALAR;
53+
}
54+
55+
index_t Constant::dim() const {
56+
return 1;
57+
}
58+
59+
std::string Constant::to_string() const {
60+
return String::to_string(value());
61+
}
62+
63+
bool Constant::atomic() const {
64+
return true;
65+
}
66+
67+
/**************************************************************************/
68+
69+
Expr::Type Variable::type() const {
70+
return type_;
71+
}
72+
73+
bool Variable::atomic() const {
74+
return true;
75+
}
76+
77+
/**************************************************************************/
78+
79+
index_t ScalarVar::dim() const {
80+
return 1;
81+
}
82+
83+
std::string ScalarVar::to_string() const {
84+
// return name() + ":scalar";
85+
return name();
86+
}
87+
88+
/**************************************************************************/
89+
90+
index_t VectorVar::default_dim_ = 3;
91+
92+
index_t VectorVar::dim() const {
93+
return dim_ == index_t(-1) ? default_dim_ : dim_;
94+
}
95+
96+
std::string VectorVar::to_string() const {
97+
std::string result = name();
98+
/*
99+
result += ":vec";
100+
if(dim_ != index_t(-1)) {
101+
result += ("[" + String::to_string(dim_) + "]");
102+
}
103+
*/
104+
return result;
105+
}
106+
107+
/**************************************************************************/
108+
109+
std::string VectorComponent::to_string() const {
110+
return String::to_string(vector()) + "[" + String::to_string(component_) + "]";
111+
}
112+
113+
bool VectorComponent::atomic() const {
114+
return true;
115+
}
116+
117+
Expr::Type VectorComponent::type() const {
118+
return SCALAR;
119+
}
120+
121+
index_t VectorComponent::dim() const {
122+
return 1;
123+
}
124+
125+
/**************************************************************************/
126+
127+
index_t SignVar::dim() const {
128+
return 0;
129+
}
130+
131+
std::string SignVar::to_string() const {
132+
return name() + ":sign";
133+
}
134+
135+
/**************************************************************************/
136+
137+
Expr::Type Sum::type() const {
138+
return type_;
139+
}
140+
141+
index_t Sum::dim() const {
142+
return dim_;
143+
}
144+
145+
std::string Sum::to_string() const {
146+
std::string result;
147+
for(index_t i=0; i<nb_terms(); ++i) {
148+
result += String::to_string(ith_term(i));
149+
if(i != nb_terms()-1) {
150+
result += " + ";
151+
}
152+
}
153+
return result;
154+
}
155+
156+
void Sum::add_term(Expr* term) {
157+
{
158+
Sum* sum = dynamic_cast<Sum*>(term);
159+
if(sum != nullptr) {
160+
for(index_t i=0; i<sum->nb_terms(); ++i) {
161+
add_term(sum->ith_term(i));
162+
}
163+
return;
164+
}
165+
}
166+
{
167+
Constant* co1 = dynamic_cast<Constant*>(term);
168+
if(co1 != nullptr) {
169+
if(co1->value() == 0.0) {
170+
return;
171+
}
172+
for(index_t i=0; i<nb_terms(); ++i) {
173+
Constant* co2 = dynamic_cast<Constant*>(ith_term(i));
174+
if(co2 != nullptr) {
175+
terms_[i] = new Constant(co1->value() + co2->value());
176+
return;
177+
}
178+
}
179+
}
180+
}
181+
terms_.push_back(term);
182+
}
183+
184+
bool Sum::atomic() const {
185+
return false;
186+
}
187+
188+
/**************************************************************************/
189+
190+
Expr::Type Product::type() const {
191+
return type_;
192+
}
193+
194+
index_t Product::dim() const {
195+
return dim_;
196+
}
197+
198+
std::string Product::to_string() const {
199+
std::string result;
200+
for(index_t i=0; i<nb_factors(); ++i) {
201+
result += String::to_string(ith_factor(i));
202+
if(i != nb_factors()-1) {
203+
result += " * ";
204+
}
205+
}
206+
return result;
207+
}
208+
209+
void Product::mult_factor(Expr* factor) {
210+
{
211+
for(index_t i=0; i<nb_factors(); ++i) {
212+
if(factor == ith_factor(i)) {
213+
factors_[i] = new Pow(factor,2);
214+
return;
215+
}
216+
Pow* pow = dynamic_cast<Pow*>(ith_factor(i));
217+
if(pow != nullptr && pow->arg() == factor) {
218+
factors_[i] = new Pow(factor,pow->exponent()+1);
219+
return;
220+
}
221+
}
222+
}
223+
{
224+
Product* prod = dynamic_cast<Product*>(factor);
225+
if(prod != nullptr) {
226+
for(index_t i=0; i<prod->nb_factors(); ++i) {
227+
mult_factor(prod->ith_factor(i));
228+
}
229+
return;
230+
}
231+
}
232+
{
233+
Constant* co1 = dynamic_cast<Constant*>(factor);
234+
if(co1 != nullptr) {
235+
if(co1->value() == 1.0) {
236+
return;
237+
}
238+
for(index_t i=0; i<nb_factors(); ++i) {
239+
Constant* co2 = dynamic_cast<Constant*>(ith_factor(i));
240+
if(co2 != nullptr) {
241+
factors_[i] = new Constant(co1->value() * co2->value());
242+
return;
243+
}
244+
}
245+
}
246+
}
247+
factors_.push_back(factor);
248+
}
249+
250+
bool Product::atomic() const {
251+
return false;
252+
}
253+
254+
/**************************************************************************/
255+
256+
Expr::Type Pow::type() const {
257+
return type_;
258+
}
259+
260+
index_t Pow::dim() const {
261+
return dim_;
262+
}
263+
264+
std::string Pow::to_string() const {
265+
return String::to_string(arg()) + "^" + String::to_string(exponent());
266+
}
267+
268+
bool Pow::atomic() const {
269+
return false;
270+
}
271+
272+
/**************************************************************************/
273+
}

0 commit comments

Comments
 (0)