Skip to content

Commit

Permalink
fix format questions
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwen-sun committed Sep 22, 2023
1 parent 69e7907 commit 42f0442
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ci/images/tugraph-runtime-centos7-Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RUN wget https://tugraph-web.oss-cn-beijing.aliyuncs.com/tugraph/deps/boost_1_68
&& tar xf boost_1_68_0.tar.gz && cd boost_1_68_0 \
&& ./bootstrap.sh --with-libraries=system,random,thread,filesystem,chrono,atomic,date_time,regex,stacktrace,log \
&& ./b2 -j4 cxxflags="-std=c++14 -fPIC" install && rm -rf /boost_*

# install maven
# if it is not accessible, replace it with the link below
# https://dlcdn.apache.org/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz
Expand Down
16 changes: 8 additions & 8 deletions include/lgraph/lgraph_spatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* @file lgraph_spatial.h
* @brief Implemnets the Spatial, SpatialBase and SpatialDerive classes.
*
* TODO:
* 1. 进一步通过测试样例检查ParseStringToValueOfFieldType与TryFieldDataToValueOfFieldType
* 实现的正确性(空间数据与string数据的转换);
* 2. EWKB的压缩格式, 空间数据在schema层面的压缩存储, 如果易于计算;
* 3. 更完善易读的注释;
* 4. 利用FieldType2CType更简洁实现空间数据相关功能;
*/
* TODO(shw):
* 1. add more tests for the conversion between string type and spatial type in
* funciton ParseStringToValueOfFieldType and TryFieldDataToValueOfFieldType.
* 2. support the compression of EWKB, which is now the format of spatial type storage.
* 3. more comprehensive and readable comments.
* 4. use FieldType2CType to simplify the realization of spatial data function;
*/

#pragma once

Expand All @@ -40,7 +40,7 @@ namespace bg = boost::geometry;

typedef bg::cs::cartesian Cartesian;
typedef bg::cs::geographic<bg::degree> Wgs84;
typedef std::vector<boost::uint8_t> byte_vector;
typedef std::vector<boost::uint8_t> ByteVector;

/**
* @brief now support three types of spatial data, they are all two-dimensional;
Expand Down
30 changes: 16 additions & 14 deletions include/lgraph/lgraph_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,10 @@ struct FieldData {
static inline FieldData String(std::string&& str) { return FieldData(std::move(str)); }
static inline FieldData String(const char* str) { return FieldData(str); }
static inline FieldData String(const char* p, size_t s) { return FieldData(p, s); }

static inline FieldData PointCartesian(const ::lgraph_api::Point<Cartesian>& p) {
return FieldData(p); }
static inline FieldData PointWGS84(const ::lgraph_api::Point<Wgs84>& p) {return FieldData(p); }
return FieldData(p);
}
static inline FieldData PointWgs84(const ::lgraph_api::Point<Wgs84>& p) { return FieldData(p); }
static inline FieldData Point(const std::string& str) {
switch (::lgraph_api::ExtractSRID(str)) {
case ::lgraph_api::SRID::NUL:
Expand All @@ -551,11 +551,12 @@ struct FieldData {
throw InputError("Unsupported SRID!");
}
}

static inline FieldData LineStringCartesian(const ::lgraph_api::LineString<Cartesian>& l) {
return FieldData(l); }
static inline FieldData LineStringWGS84(const ::lgraph_api::LineString<Wgs84>& l) {
return FieldData(l); }
return FieldData(l);
}
static inline FieldData LineStringWgs84(const ::lgraph_api::LineString<Wgs84>& l) {
return FieldData(l);
}
static inline FieldData LineString(const std::string& str) {
switch (::lgraph_api::ExtractSRID(str)) {
case ::lgraph_api::SRID::NUL:
Expand All @@ -568,11 +569,12 @@ struct FieldData {
throw InputError("Unsupported SRID!");
}
}

static inline FieldData PolygonCartesian(const ::lgraph_api::Polygon<Cartesian>& p) {
return FieldData(p); }
static inline FieldData PolygonWGS84(const ::lgraph_api::Polygon<Wgs84>& p) {
return FieldData(p); }
return FieldData(p);
}
static inline FieldData PolygonWgs84(const ::lgraph_api::Polygon<Wgs84>& p) {
return FieldData(p);
}
static inline FieldData Polygon(const std::string& str) {
switch (::lgraph_api::ExtractSRID(str)) {
case ::lgraph_api::SRID::NUL:
Expand All @@ -585,10 +587,10 @@ struct FieldData {
throw InputError("Unsupported SRID!");
}
}

static inline FieldData Spatial(const ::lgraph_api::Spatial<Cartesian>& s) {
return FieldData(s); }
static inline FieldData Spatial(const ::lgraph_api::Spatial<Wgs84>& s) {return FieldData(s); }
return FieldData(s);
}
static inline FieldData Spatial(const ::lgraph_api::Spatial<Wgs84>& s) { return FieldData(s); }

//-------------------------
// Constructs blobs.
Expand Down
18 changes: 9 additions & 9 deletions src/core/lgraph_spatial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool TryDecodeWKB(const std::string& WKB, SpatialType type) {
return false;
case SpatialType::POINT: {
Point Point_;
byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(WKB, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), Point_)) {
Expand All @@ -250,7 +250,7 @@ bool TryDecodeWKB(const std::string& WKB, SpatialType type) {

case SpatialType::LINESTRING: {
bg::model::linestring<Point> line_;
byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(WKB, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), line_)) {
Expand All @@ -261,7 +261,7 @@ bool TryDecodeWKB(const std::string& WKB, SpatialType type) {

case SpatialType::POLYGON: {
bg::model::polygon<Point> Polygon_;
byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(WKB, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), Polygon_)) {
Expand Down Expand Up @@ -394,7 +394,7 @@ Point<SRID_Type>::Point(SRID srid, SpatialType type, int construct_type, std::st
// first, tranfer the big endian into little endian;
if (!Endian(content))
WkbEndianTransfer(content);
byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(content, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), Point_)) {
Expand Down Expand Up @@ -441,7 +441,7 @@ Point<SRID_Type>::Point(const std::string& EWKB_)
EWKB = EWKB_;
std::string WKB = EWKB.substr(0, 10) + EWKB.substr(18);
WKB[8] = '0';
byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(WKB, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), Point_)) {
Expand Down Expand Up @@ -489,7 +489,7 @@ int construct_type, std::string& content)
if (construct_type == 0) {
if (!Endian(content))
WkbEndianTransfer(content);
byte_vector wkb_;
ByteVector wkb_;
if (!bg::hex2wkb(content, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), line_)) {
throw InputError("wrong wkb format: " + content);
Expand Down Expand Up @@ -529,7 +529,7 @@ LineString<SRID_Type>::LineString(const std::string& EWKB_)
EWKB = EWKB_;
std::string WKB = EWKB.substr(0, 10) + EWKB.substr(18);
WKB[8] = '0';
byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(WKB, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), line_)) {
Expand Down Expand Up @@ -575,7 +575,7 @@ Polygon<SRID_Type>::Polygon(SRID srid, SpatialType type, int construct_type, std
if (construct_type == 0) {
if (!Endian(content))
WkbEndianTransfer(content);
byte_vector wkb_;
ByteVector wkb_;
bg::hex2wkb(content, std::back_inserter(wkb_));
if (!bg::hex2wkb(content, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), Polygon_)) {
Expand Down Expand Up @@ -620,7 +620,7 @@ Polygon<SRID_Type>::Polygon(const std::string& EWKB_)
std::string WKB = EWKB.substr(0, 10) + EWKB.substr(18);
WKB[8] = '0';

byte_vector wkb_;
ByteVector wkb_;

if (!bg::hex2wkb(WKB, std::back_inserter(wkb_)) ||
!bg::read_wkb(wkb_.begin(), wkb_.end(), Polygon_)) {
Expand Down

0 comments on commit 42f0442

Please sign in to comment.