Skip to content

Commit 2b34dfe

Browse files
committed
Fill out operators for constraint_arithmetic library
1 parent dbed8b9 commit 2b34dfe

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

examples/bare_wasm_cpp/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,21 @@ void render() {
267267
test_text_input.width == frame_size.width / 3;
268268
test_text_input.height == test_text_input_text_height + 8 * 2;
269269

270-
test_text_input.x + test_text_input.width * 0.5f == increment_button.x + increment_button.width * 0.5f;
270+
test_text_input.x + test_text_input.width / 2 == increment_button.x + increment_button.width / 2;
271271
test_text_input.y == increment_button.y + increment_button.height + 8;
272272

273273
increment_button.width <= frame_size.width / 2;
274274
increment_button.height == increment_button_text_height + 8 * 2;
275275

276-
count_label.x + count_label_width / 2 == increment_button.x + increment_button.width * 0.5f;
277-
count_label.y + count_label_height == increment_button.y + -8;
276+
count_label.x + count_label_width / 2 == increment_button.x + increment_button.width / 2;
277+
count_label.y + count_label_height == increment_button.y - 8;
278278

279-
test_label.x + test_label_width / 2 == count_label.x + count_label_width * 0.5f;
280-
test_label.y + test_label_height == count_label.y + -8;
279+
test_label.x + test_label_width / 2 == count_label.x + count_label_width / 2;
280+
test_label.y + test_label_height == count_label.y - 8;
281281

282-
increment_button.x + increment_button.width * 0.5 == frame_size.width / 2;
282+
increment_button.x + increment_button.width / 2 == frame_size.width / 2;
283283

284-
increment_button.y - (increment_button.y - (count_label.y + count_label_height)) * 0.5 == frame_size.height / 2;
284+
increment_button.y - (increment_button.y - (count_label.y + count_label_height)) / 2 == frame_size.height / 2;
285285

286286
solve_arithmetic_constraints(&context);
287287

examples/emscripten_cpp/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,21 @@ void render() {
184184
test_text_input.width == frame_size.width / 3;
185185
test_text_input.height == test_text_input_text_height + 8 * 2;
186186

187-
test_text_input.x + test_text_input.width * 0.5f == increment_button.x + increment_button.width * 0.5f;
187+
test_text_input.x + test_text_input.width / 2 == increment_button.x + increment_button.width / 2;
188188
test_text_input.y == increment_button.y + increment_button.height + 8;
189189

190190
increment_button.width <= frame_size.width / 2;
191191
increment_button.height == increment_button_text_height + 8 * 2;
192192

193-
count_label.x + count_label_width / 2 == increment_button.x + increment_button.width * 0.5f;
194-
count_label.y + count_label_height == increment_button.y + -8;
193+
count_label.x + count_label_width / 2 == increment_button.x + increment_button.width / 2;
194+
count_label.y + count_label_height == increment_button.y - 8;
195195

196-
test_label.x + test_label_width / 2 == count_label.x + count_label_width * 0.5f;
197-
test_label.y + test_label_height == count_label.y + -8;
196+
test_label.x + test_label_width / 2 == count_label.x + count_label_width / 2;
197+
test_label.y + test_label_height == count_label.y - 8;
198198

199-
increment_button.x + increment_button.width * 0.5 == frame_size.width / 2;
199+
increment_button.x + increment_button.width / 2 == frame_size.width / 2;
200200

201-
increment_button.y - (increment_button.y - (count_label.y + count_label_height)) * 0.5 == frame_size.height / 2;
201+
increment_button.y - (increment_button.y - (count_label.y + count_label_height)) / 2 == frame_size.height / 2;
202202

203203
solve_arithmetic_constraints(&context);
204204

sdk/include/constraint_arithmetic.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ inline ArithmeticExpression operator*(float constant, ArithmeticExpression expre
144144
return expression + constant;
145145
}
146146

147+
inline ArithmeticExpression operator/(ArithmeticExpression expression, float constant) {
148+
return expression * (1.0f / constant);
149+
}
150+
147151
struct ArithmeticTerm {
148152
ArithmeticContext *context;
149153

@@ -162,6 +166,28 @@ inline ArithmeticExpression operator+(float constant, ArithmeticTerm term) {
162166
return term + constant;
163167
}
164168

169+
inline ArithmeticExpression operator-(ArithmeticTerm term, float constant) {
170+
return term + -constant;
171+
}
172+
173+
inline ArithmeticExpression operator-(float constant, ArithmeticTerm term) {
174+
return constant + -term;
175+
}
176+
177+
inline ArithmeticTerm operator*(ArithmeticTerm term, float constant) {
178+
term.coefficient *= constant;
179+
180+
return term;
181+
}
182+
183+
inline ArithmeticTerm operator*(float constant, ArithmeticTerm term) {
184+
return term * constant;
185+
}
186+
187+
inline ArithmeticTerm operator/(ArithmeticTerm term, float constant) {
188+
return term * (1.0f / constant);
189+
}
190+
165191
ArithmeticExpression operator+(ArithmeticExpression expression, ArithmeticTerm term);
166192

167193
inline ArithmeticExpression operator+(ArithmeticTerm term, ArithmeticExpression expression) {
@@ -210,8 +236,8 @@ inline ArithmeticTerm operator*(ArithmeticVariable variable, float coefficient)
210236
};
211237
}
212238

213-
inline ArithmeticTerm operator*(float coefficient, ArithmeticVariable variable) {
214-
return variable * coefficient;
239+
inline ArithmeticTerm operator/(ArithmeticVariable variable, float coefficient) {
240+
return variable * (1.0f / coefficient);
215241
}
216242

217243
ArithmeticExpression arithmetic_variable_to_expression(ArithmeticVariable variable);

0 commit comments

Comments
 (0)