Skip to content

Commit

Permalink
Fix Line conversion and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Sep 3, 2020
1 parent d2abdb0 commit 035615f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/conversion/from_geo_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
{
vec![
create_point_type(&line_string.start_point()),
create_point_type(&line_string.start_point()),
create_point_type(&line_string.end_point()),
]
}

Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {
use crate::{Geometry, Value};
use geo_types;
use geo_types::{
GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
GeometryCollection, LineString, Line, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
};

#[test]
Expand Down Expand Up @@ -316,6 +316,24 @@ mod tests {
}
}

#[test]
fn geo_line_conversion_test() {
let p1 = Point::new(40.02f64, 116.34f64);
let p2 = Point::new(13.02f64, 24.34f64);

let geo_line = Line::new(p1, p2);
let geojson_line_point = Value::from(&geo_line);

if let Value::LineString(c) = geojson_line_point {
assert_almost_eq!(p1.x(), c[0][0], 1e-6);
assert_almost_eq!(p1.y(), c[0][1], 1e-6);
assert_almost_eq!(p2.x(), c[1][0], 1e-6);
assert_almost_eq!(p2.y(), c[1][1], 1e-6);
} else {
panic!("Not valid geometry {:?}", geojson_line_point);
}
}

#[test]
fn geo_multi_line_string_conversion_test() {
let p1 = Point::new(40.02f64, 116.34f64);
Expand Down

0 comments on commit 035615f

Please sign in to comment.