Skip to content

Commit 40372c7

Browse files
committed
Make Geometry::fromExpression() freestanding
The new name is parseGeometry() for symmetry with loadGeometry().
1 parent 86a881a commit 40372c7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

qtcsg/qtcsg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ QVariant parseArgument(const QString &primitive,
316316

317317
} // namespace
318318

319-
Geometry Geometry::fromExpression(QString expression)
319+
Geometry parseGeometry(QString expression)
320320
{
321321
static const auto s_callPattern = QRegularExpression{R"(^(?<name>[a-z]+)\((?<args>[^)]*\))$)"};
322322
static const auto s_argPattern = QRegularExpression{R"(\s*(?<name>[a-z]+)\s*=\s*(?:)"

qtcsg/qtcsg.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ class Geometry
189189
/// by `matrix` applied to all the polygons of this geometry.
190190
[[nodiscard]] Geometry transformed(const QMatrix4x4 &matrix) const;
191191

192-
[[nodiscard]] static Geometry fromExpression(QString expression);
193-
194192
private:
195193
QList<Polygon> m_polygons;
196194
Error m_error;
@@ -261,6 +259,14 @@ class Node
261259
[[nodiscard]] Geometry cylinder(QVector3D start, QVector3D end, float radius = 1, float slices = 16);
262260
[[nodiscard]] Geometry cylinder(QVector3D center = {}, float height = 2, float radius = 1, float slices = 16);
263261

262+
/// Constructs a single geometry from simple expression:
263+
///
264+
/// "cube()" produces a simple cube.
265+
/// "sphere(r=1.3)" produces a sphere of radius 1.3.
266+
///
267+
/// See `testParseGeometry()` for more examples.
268+
[[nodiscard]] Geometry parseGeometry(QString expression);
269+
264270
/// Return a new CSG solid representing space in either this solid or in the
265271
/// solid `csg`. Neither this solid nor the solid `csg` are modified.
266272
///

tests/qtcsgtest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private slots:
327327
QCOMPARE(transformed, expectedResult);
328328
}
329329

330-
void testFromExpression_data()
330+
void testParseGeometry_data()
331331
{
332332
QTest::addColumn<QString>("expression");
333333
QTest::addColumn<Geometry>("expectedGeometry");
@@ -419,7 +419,7 @@ private slots:
419419
R"*("start" and "end" of cylinder primitive)*";
420420
}
421421

422-
void testFromExpression()
422+
void testParseGeometry()
423423
{
424424
const QFETCH(QString, expression);
425425
const QFETCH(Geometry, expectedGeometry);
@@ -428,7 +428,7 @@ private slots:
428428
if (!expectedWarning.isEmpty())
429429
QTest::ignoreMessage(QtWarningMsg, qUtf8Printable(expectedWarning));
430430

431-
const auto parsedGeometry = Geometry::fromExpression(expression);
431+
const auto parsedGeometry = parseGeometry(expression);
432432

433433
QCOMPARE(expectedGeometry.error(), expectedGeometry.error());
434434
QCOMPARE(parsedGeometry.polygons(), expectedGeometry.polygons());

0 commit comments

Comments
 (0)