Skip to content

Commit 17b357f

Browse files
authored
Merge pull request #614 from tigercosmos/follow_up_1027
Use `mirror` function in SVG GUI and fix the SVG classes docstrings format
2 parents bb6cefd + c01fbbf commit 17b357f

File tree

4 files changed

+197
-88
lines changed

4 files changed

+197
-88
lines changed

cpp/modmesh/universe/bezier.hpp

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,21 @@ class Point3d
181181
value_type calc_length2() const { return m_coord[0] * m_coord[0] + m_coord[1] * m_coord[1] + m_coord[2] * m_coord[2]; }
182182
value_type calc_length() const { return std::sqrt(calc_length2()); }
183183

184-
void mirror_x() { m_coord[0] = -m_coord[0]; }
185-
void mirror_y() { m_coord[1] = -m_coord[1]; }
186-
void mirror_z() { m_coord[2] = -m_coord[2]; }
184+
void mirror_x()
185+
{
186+
m_coord[1] = -m_coord[1];
187+
m_coord[2] = -m_coord[2];
188+
}
189+
void mirror_y()
190+
{
191+
m_coord[0] = -m_coord[0];
192+
m_coord[2] = -m_coord[2];
193+
}
194+
void mirror_z()
195+
{
196+
m_coord[0] = -m_coord[0];
197+
m_coord[1] = -m_coord[1];
198+
}
187199

188200
void mirror(Axis axis)
189201
{
@@ -546,17 +558,31 @@ class PointPad
546558

547559
void mirror_x()
548560
{
549-
for (size_t i = 0; i < m_x.size(); ++i)
561+
for (size_t i = 0; i < m_y.size(); ++i)
550562
{
551-
m_x[i] = -m_x[i];
563+
m_y[i] = -m_y[i];
564+
}
565+
if (m_ndim == 3)
566+
{
567+
for (size_t i = 0; i < m_z.size(); ++i)
568+
{
569+
m_z[i] = -m_z[i];
570+
}
552571
}
553572
}
554573

555574
void mirror_y()
556575
{
557-
for (size_t i = 0; i < m_y.size(); ++i)
576+
for (size_t i = 0; i < m_x.size(); ++i)
558577
{
559-
m_y[i] = -m_y[i];
578+
m_x[i] = -m_x[i];
579+
}
580+
if (m_ndim == 3)
581+
{
582+
for (size_t i = 0; i < m_z.size(); ++i)
583+
{
584+
m_z[i] = -m_z[i];
585+
}
560586
}
561587
}
562588

@@ -566,9 +592,13 @@ class PointPad
566592
{
567593
throw std::out_of_range(Formatter() << "PointPad::mirror_z: ndim must be 3 but is " << int(m_ndim));
568594
}
569-
for (size_t i = 0; i < m_z.size(); ++i)
595+
for (size_t i = 0; i < m_x.size(); ++i)
596+
{
597+
m_x[i] = -m_x[i];
598+
}
599+
for (size_t i = 0; i < m_y.size(); ++i)
570600
{
571-
m_z[i] = -m_z[i];
601+
m_y[i] = -m_y[i];
572602
}
573603
}
574604

@@ -714,20 +744,26 @@ class Segment3d
714744

715745
void mirror_x()
716746
{
717-
m_data.f.x0 = -m_data.f.x0;
718-
m_data.f.x1 = -m_data.f.x1;
747+
m_data.f.y0 = -m_data.f.y0;
748+
m_data.f.y1 = -m_data.f.y1;
749+
m_data.f.z0 = -m_data.f.z0;
750+
m_data.f.z1 = -m_data.f.z1;
719751
}
720752

721753
void mirror_y()
722754
{
723-
m_data.f.y0 = -m_data.f.y0;
724-
m_data.f.y1 = -m_data.f.y1;
755+
m_data.f.x0 = -m_data.f.x0;
756+
m_data.f.x1 = -m_data.f.x1;
757+
m_data.f.z0 = -m_data.f.z0;
758+
m_data.f.z1 = -m_data.f.z1;
725759
}
726760

727761
void mirror_z()
728762
{
729-
m_data.f.z0 = -m_data.f.z0;
730-
m_data.f.z1 = -m_data.f.z1;
763+
m_data.f.x0 = -m_data.f.x0;
764+
m_data.f.x1 = -m_data.f.x1;
765+
m_data.f.y0 = -m_data.f.y0;
766+
m_data.f.y1 = -m_data.f.y1;
731767
}
732768

733769
void mirror(Axis axis)
@@ -1121,8 +1157,13 @@ class SegmentPad
11211157
size_t const nseg = size();
11221158
for (size_t i = 0; i < nseg; ++i)
11231159
{
1124-
x0(i) = -x0(i);
1125-
x1(i) = -x1(i);
1160+
y0(i) = -y0(i);
1161+
y1(i) = -y1(i);
1162+
if (ndim() == 3)
1163+
{
1164+
z0(i) = -z0(i);
1165+
z1(i) = -z1(i);
1166+
}
11261167
}
11271168
}
11281169

@@ -1131,8 +1172,13 @@ class SegmentPad
11311172
size_t const nseg = size();
11321173
for (size_t i = 0; i < nseg; ++i)
11331174
{
1134-
y0(i) = -y0(i);
1135-
y1(i) = -y1(i);
1175+
x0(i) = -x0(i);
1176+
x1(i) = -x1(i);
1177+
if (ndim() == 3)
1178+
{
1179+
z0(i) = -z0(i);
1180+
z1(i) = -z1(i);
1181+
}
11361182
}
11371183
}
11381184

@@ -1146,8 +1192,10 @@ class SegmentPad
11461192
size_t const nseg = size();
11471193
for (size_t i = 0; i < nseg; ++i)
11481194
{
1149-
z0(i) = -z0(i);
1150-
z1(i) = -z1(i);
1195+
x0(i) = -x0(i);
1196+
x1(i) = -x1(i);
1197+
y0(i) = -y0(i);
1198+
y1(i) = -y1(i);
11511199
}
11521200
}
11531201

@@ -1272,29 +1320,41 @@ class Bezier3d
12721320
std::shared_ptr<SegmentPad<T>> sample(size_t nlocus) const;
12731321

12741322
void mirror_x()
1275-
{
1276-
x0() = -x0();
1277-
x1() = -x1();
1278-
x2() = -x2();
1279-
x3() = -x3();
1280-
}
1281-
1282-
void mirror_y()
12831323
{
12841324
y0() = -y0();
12851325
y1() = -y1();
12861326
y2() = -y2();
12871327
y3() = -y3();
1328+
z0() = -z0();
1329+
z1() = -z1();
1330+
z2() = -z2();
1331+
z3() = -z3();
12881332
}
12891333

1290-
void mirror_z()
1334+
void mirror_y()
12911335
{
1336+
x0() = -x0();
1337+
x1() = -x1();
1338+
x2() = -x2();
1339+
x3() = -x3();
12921340
z0() = -z0();
12931341
z1() = -z1();
12941342
z2() = -z2();
12951343
z3() = -z3();
12961344
}
12971345

1346+
void mirror_z()
1347+
{
1348+
x0() = -x0();
1349+
x1() = -x1();
1350+
x2() = -x2();
1351+
x3() = -x3();
1352+
y0() = -y0();
1353+
y1() = -y1();
1354+
y2() = -y2();
1355+
y3() = -y3();
1356+
}
1357+
12981358
void mirror(Axis axis)
12991359
{
13001360
switch (axis)

modmesh/pilot/_svg_gui.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,13 @@ def _load_svg_file(self, filename):
9999
world = core.WorldFp64()
100100

101101
for spad in spads:
102-
# mirror with respect to x-axis: (x, y) -> (x, -y)
103-
spad.y0.ndarray[:] = -spad.y0.ndarray
104-
spad.y1.ndarray[:] = -spad.y1.ndarray
102+
# Flip against the X axis for GUI coordinate system
103+
spad.mirror(axis='x')
105104
world.add_segments(pad=spad)
106105

107106
for cpad in cpads:
108-
# mirror with respect to x-axis: (x, y) -> (x, -y)
109-
cpad.y0.ndarray[:] = -cpad.y0.ndarray
110-
cpad.y1.ndarray[:] = -cpad.y1.ndarray
111-
cpad.y2.ndarray[:] = -cpad.y2.ndarray
112-
cpad.y3.ndarray[:] = -cpad.y3.ndarray
107+
# Flip against the X axis for GUI coordinate system
108+
cpad.mirror(axis='x')
113109
world.add_beziers(pad=cpad)
114110

115111
wid = self._mgr.add3DWidget()

modmesh/plot/svg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343

4444

4545
class SvgParser(object):
46-
"""The SVG parser to extract SegmentPad and CurvePad from SVG file.
46+
"""
47+
The SVG parser to extract SegmentPad and CurvePad from SVG file.
4748
4849
Internally uses PathParser and ShapeParser to parse <path> and
4950
shape elements respectively.
@@ -464,7 +465,8 @@ def get_cmds(self):
464465

465466

466467
class PathParser(object):
467-
"""The SVG <path> element parser to extract SegmentPad and CurvePad.
468+
"""
469+
The SVG <path> element parser to extract SegmentPad and CurvePad.
468470
469471
Parse <path> elements from the SVG file and convert them into
470472
SegmentPad and CurvePad objects.
@@ -700,7 +702,8 @@ def _calculate(self):
700702

701703

702704
class ShapeParser(object):
703-
"""Parse basic shapes from an SVG file to extract SegmentPad and CurvePad.
705+
"""
706+
Parse basic shapes from an SVG file to extract SegmentPad and CurvePad.
704707
705708
Parses the basic shapes, including <circle>, <rect>, <ellipse>,
706709
<line>, <polyline>, and <polygon>, but excludes <path>.

0 commit comments

Comments
 (0)