Conversation
modmesh/plot/plane_layer.py
Outdated
| # POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
|
|
||
| class ManhattanDeltaCodec: |
There was a problem hiding this comment.
Write I/O code in C++. Python is too slow to be taken seriously for I/O.
Name it modmesh::OasisDevice for now.
tests/test_plane_layer.py
Outdated
| from modmesh.plot import plane_layer | ||
|
|
||
|
|
||
| class ManhattanDeltaCodecTC(unittest.TestCase): |
There was a problem hiding this comment.
Unit tests for the OASIS I/O should be in Python.
8a2d55c to
eb97718
Compare
|
Hi @yungyuc,
Done.
I'm concern that it will have too much diff in this PR if we want to output OASIS file. Althought we have geometry record now, we don't have some necessary OASIS header like magic bytes, START and END. I would like to confirm that this PR should support OASIS file output or we can just test Manhatten 1-delta work properly with unit tests? |
|
Linter did not pass. Please fix code format and then request for review again. |
cpp/modmesh/oasis/oasis_device.hpp
Outdated
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| using bytes = std::vector<uint8_t>; |
There was a problem hiding this comment.
Do not make an intrusive alias like this. It is horrible to maintain.
There is nothing wrong with using std::vector<uint8)_t>? Just spell out the type.
It is horrible to add an alias in the global name space. Unacceptable almost always.
| static void append_1_delta(bytes & segment, int value); | ||
|
|
||
| public: | ||
| OasisDevice() = default; |
cpp/modmesh/oasis/oasis_device.hpp
Outdated
|
|
||
| public: | ||
| OasisDevice() = default; | ||
| static bytes writer(std::vector<int32_t> & values); |
There was a problem hiding this comment.
Name it write, not writer, which is not a verb.
|
@tigercosmos @KHLee529 please help review |
71b53ff to
d3e62a3
Compare
| namespace python | ||
| { | ||
|
|
||
| using namespace modmesh::oasis; // NOLINT(google-build-using-namespace) |
There was a problem hiding this comment.
I recommend remove this. Namespace is important for reading the code.
There was a problem hiding this comment.
Good catch. modmesh::oasis namespace is not necessary and should be removed.
And, never using namespace unless it is in a very limited scope and can resolve extreme pain.
cpp/modmesh/oasis/oasis_device.cpp
Outdated
|
|
||
| void OasisDevice::append_1_delta(std::vector<uint8_t> & segment, int value) | ||
| { | ||
| int dir_bit = value < 0 ? 1 : 0; |
There was a problem hiding this comment.
Please add const for all the places if applicable.
| namespace oasis | ||
| { | ||
|
|
||
| class OasisDevice |
There was a problem hiding this comment.
Please add document comments for classes and functions.
cpp/modmesh/oasis/oasis_device.cpp
Outdated
| } | ||
| } | ||
|
|
||
| std::vector<uint8_t> OasisDevice::write(std::vector<int32_t> & values) |
There was a problem hiding this comment.
const std::vector<int32_t> & values
cpp/modmesh/oasis/oasis_device.cpp
Outdated
| namespace oasis | ||
| { | ||
|
|
||
| void OasisDevice::append_1_delta(std::vector<uint8_t> & segment, int value) |
There was a problem hiding this comment.
This can be a local function in cpp only.
| while (payload >= 1) | ||
| { | ||
| int first_bit = payload >= 128 ? 1 : 0; | ||
| segment.push_back((first_bit << 7) | (payload % 128)); |
There was a problem hiding this comment.
Please add comments to explain the algorithm. Including source doucment is even better.
modmesh/plot/plane_layer.py
Outdated
| # POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
|
|
||
| class ManhattanDeltaCodec: |
| device = modmesh.OasisDevice() | ||
| seg = device.writer([+340, +200, -340, -40, +300, -120, -300]) | ||
|
|
||
| self.assertEqual(seg, [0xD0, 0x0A, 0xA0, 0x06, 0xD2, |
There was a problem hiding this comment.
It will be nice if you can explain what you try to test in the comments.
yungyuc
left a comment
There was a problem hiding this comment.
Points to address:
- Do not use namespace
modmesh::oasis. - Add very concise code comments for the key points in unit tests.
| namespace python | ||
| { | ||
|
|
||
| using namespace modmesh::oasis; // NOLINT(google-build-using-namespace) |
There was a problem hiding this comment.
Good catch. modmesh::oasis namespace is not necessary and should be removed.
And, never using namespace unless it is in a very limited scope and can resolve extreme pain.
| namespace modmesh | ||
| { | ||
|
|
||
| namespace oasis |
There was a problem hiding this comment.
Do not use namespace modmesh::oasis.
| device = modmesh.OasisDevice() | ||
| seg = device.writer([+340, +200, -340, -40, +300, -120, -300]) | ||
|
|
||
| self.assertEqual(seg, [0xD0, 0x0A, 0xA0, 0x06, 0xD2, |
012b646 to
5607f69
Compare
In this PR, I added OASIS device. This device support writer only currently. This writer implement manhattan delta format by OASIS spec.
For example, if we expected +340 for N/S direction, it will be encoded with
0xD0 0x0A, and -340 will be0xD2 0x0A.I added some test to make sure it work properly, and I add some edge case to make sure it will not buggy when met edge case.