Skip to content

Commit d8e9acb

Browse files
committed
Add scalar constructors for Segment3d and document 2D convention
1 parent c9b07af commit d8e9acb

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

cpp/solvcon/universe/coord.hpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ enum class Axis : uint8_t
3434
/**
3535
* Point in three-dimensional space.
3636
*
37+
* A pad of ndim 2 stores and reports z as zero, and a segment or point read
38+
* back from it carries that zero. Plane code is meant to ignore it, not to
39+
* work around it.
40+
*
3741
* @tparam T floating-point type
3842
*
3943
* @ingroup group_geometry
@@ -271,6 +275,10 @@ using Point3dFp64 = Point3d<double>;
271275
* Coordinates are stored as separate per-axis arrays (x, y, and, for
272276
* three dimensions, z), so the layout is structure-of-arrays. The
273277
* dimensionality (2 or 3) is fixed at construction and cannot change.
278+
*
279+
* A pad of ndim 2 stores and reports z as zero, and a segment or point read
280+
* back from it carries that zero. Plane code is meant to ignore it, not to
281+
* work around it.
274282
*
275283
* @tparam T floating-point type
276284
*
@@ -751,6 +759,10 @@ union Segment3dData
751759

752760
/**
753761
* Segment in three-dimensional space.
762+
*
763+
* A pad of ndim 2 stores and reports z as zero, and a segment or point read
764+
* back from it carries that zero. Plane code is meant to ignore it, not to
765+
* work around it.
754766
*
755767
* @tparam T floating-point type
756768
*
@@ -773,6 +785,16 @@ class Segment3d
773785
{
774786
}
775787

788+
Segment3d(T x0, T y0, T x1, T y1)
789+
: m_data{{x0, x1, y0, y1, 0.0, 0.0}}
790+
{
791+
}
792+
793+
Segment3d(T x0, T y0, T z0, T x1, T y1, T z1)
794+
: m_data{{x0, x1, y0, y1, z0, z1}}
795+
{
796+
}
797+
776798
Segment3d() = default;
777799
Segment3d(Segment3d const &) = default;
778800
Segment3d & operator=(Segment3d const &) = default;
@@ -904,9 +926,9 @@ using Segment3dFp64 = Segment3d<double>;
904926
/**
905927
* Container of line segments in two- or three-dimensional space.
906928
*
907-
* Each segment is stored as a pair of endpoints, held in two PointPad
908-
* objects (one for each endpoint). The dimensionality (2 or 3) comes
909-
* from the underlying point pads.
929+
* A pad of ndim 2 stores and reports z as zero, and a segment or point read
930+
* back from it carries that zero. Plane code is meant to ignore it, not to
931+
* work around it.
910932
*
911933
* @tparam T floating-point type
912934
*

cpp/solvcon/universe/pymod/wrap_shape1d.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ WrapSegment3d<T> & WrapSegment3d<T>::wrap_management()
6262
.def(py::init<point_type const &, point_type const &>(),
6363
py::arg("p0"),
6464
py::arg("p1"))
65+
.def(py::init<value_type, value_type, value_type, value_type>(),
66+
py::arg("x0"),
67+
py::arg("y0"),
68+
py::arg("x1"),
69+
py::arg("y1"))
70+
.def(py::init<value_type, value_type, value_type, value_type, value_type, value_type>(),
71+
py::arg("x0"),
72+
py::arg("y0"),
73+
py::arg("z0"),
74+
py::arg("x1"),
75+
py::arg("y1"),
76+
py::arg("z1"))
6577
//
6678
;
6779

tests/test_universe_shape1d.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def test_construct(self):
2121
self.assertEqual(tuple(s.p0), (0.0, 0.0, 0.0))
2222
self.assertEqual(tuple(s.p1), (1.0, 1.0, 1.0))
2323

24+
s_6scalar = Segment(x0=0, y0=0, z0=0, x1=1, y1=1, z1=1)
25+
self.assertEqual(s_6scalar, s)
26+
27+
s.z1 = 0.0
28+
s_4scalar = Segment(x0=0, y0=0, x1=1, y1=1)
29+
self.assertEqual(s_4scalar, s)
30+
2431
s.p0 = Point(x=3, y=7, z=0)
2532
s.p1 = Point(x=-1, y=-4, z=9)
2633
self.assertEqual(s.x0, 3)

0 commit comments

Comments
 (0)