Skip to content

Commit 0ce0d9d

Browse files
committed
[types] Remove TryFrom constraint from HasGeoPoint
This way we don't have to pollute the code in the algorithm module with this, though it does mean more constraint repitition elsewhere.
1 parent c47f978 commit 0ce0d9d

3 files changed

Lines changed: 16 additions & 19 deletions

File tree

src/algorithm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type Result<T> = std::result::Result<T, AlgorithmError>;
6161
pub fn karney_interception<P>(segment: &GeoSegment<P>, point: &P) -> Result<GeoPoint>
6262
where
6363
P: HasGeoPoint,
64-
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
6564
{
6665
// Start with an initial guess of an intercept at the geodesic's midpoint:
6766
let mut intercept = geodesic_direct(
@@ -237,15 +236,15 @@ where
237236
pub trait FromGeoPoints<P>
238237
where
239238
Self: Sized,
240-
P: HasGeoPoint,
239+
P: HasGeoPoint + TryFrom<GeoPoint>,
241240
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
242241
{
243242
fn from_geo_points(start: P, end: P) -> std::result::Result<Self, GeographicError>;
244243
}
245244

246245
impl<P> FromGeoPoints<P> for GeoSegment<P>
247246
where
248-
P: HasGeoPoint,
247+
P: HasGeoPoint + TryFrom<GeoPoint>,
249248
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
250249
{
251250
fn from_geo_points(point1: P, point2: P) -> std::result::Result<Self, GeographicError> {

src/course.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub type CourseSetBuilder = CourseSetBuilderImpl<GeoPoint>;
107107

108108
pub struct CourseSetBuilderImpl<P>
109109
where
110-
P: HasGeoPoint + Send + Sync,
110+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
111111
<P as TryFrom<GeoPoint>>::Error: Send,
112112
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
113113
{
@@ -120,7 +120,7 @@ where
120120
impl<P> CourseSetBuilderImpl<P>
121121
where
122122
Self: SolveIntercept<P>,
123-
P: HasGeoPoint + Send + Sync,
123+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
124124
<P as TryFrom<GeoPoint>>::Error: Send,
125125
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
126126
{
@@ -296,7 +296,7 @@ where
296296

297297
pub trait SolveIntercept<P>
298298
where
299-
P: HasGeoPoint + Send + Sync,
299+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
300300
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
301301
{
302302
fn solve_intercept(
@@ -471,7 +471,8 @@ impl CourseBuilder {
471471
/// parameter `P` (such as [`XyzPoint`]).
472472
fn segment<P>(self) -> Result<SegmentedCourseBuilder<P>>
473473
where
474-
P: HasGeoPoint + Send + Sync,
474+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
475+
GeoSegment<P>: FromGeoPoints<P>,
475476
<P as TryFrom<GeoPoint>>::Error: Send,
476477
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
477478
{
@@ -496,7 +497,7 @@ impl CourseBuilder {
496497
.collect::<Vec<_>>();
497498

498499
Ok(SegmentedCourseBuilder {
499-
route_points: self.route_points,
500+
route_points: ps,
500501
segments_and_distances,
501502
name: self.name,
502503
course_points: Vec::new(),
@@ -515,11 +516,12 @@ impl CourseBuilder {
515516
/// course points.
516517
struct SegmentedCourseBuilder<P>
517518
where
518-
P: HasGeoPoint + Send + Sync,
519+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
520+
GeoSegment<P>: FromGeoPoints<P>,
519521
<P as TryFrom<GeoPoint>>::Error: Send,
520522
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
521523
{
522-
route_points: Vec<GeoPoint>,
524+
route_points: Vec<P>,
523525
segments_and_distances: Vec<(GeoSegment<P>, Meter<f64>)>,
524526
name: Option<String>,
525527
course_points: Vec<CoursePoint>,
@@ -528,7 +530,8 @@ where
528530

529531
impl<P> SegmentedCourseBuilder<P>
530532
where
531-
P: HasGeoPoint + Send + Sync,
533+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
534+
GeoSegment<P>: FromGeoPoints<P>,
532535
<P as TryFrom<GeoPoint>>::Error: Send,
533536
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
534537
{
@@ -551,7 +554,7 @@ where
551554
}
552555
if let Some(rp) = self.route_points.last() {
553556
records.push(Record {
554-
point: *rp,
557+
point: *rp.geo(),
555558
cumulative_distance: total_distance,
556559
})
557560
}
@@ -598,7 +601,7 @@ pub struct Record {
598601
/// along the course and lacks a known course distance.
599602
pub struct Waypoint<P>
600603
where
601-
P: HasGeoPoint + Send + Sync,
604+
P: HasGeoPoint + TryFrom<GeoPoint> + Send + Sync,
602605
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
603606
{
604607
/// Position of the waypoint.

src/types.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use approx::{AbsDiffEq, RelativeEq, abs_diff_eq, relative_eq};
22
use dimensioned::si::{M, Meter};
33
use thiserror::Error;
44

5-
use crate::course::CourseError;
65
use crate::measure::{DEG, Degree};
76

87
#[derive(Error, Debug)]
@@ -138,7 +137,6 @@ pub struct GeoAndXyzPoint {
138137
pub struct GeoSegment<P>
139138
where
140139
P: HasGeoPoint,
141-
CourseError: From<<P as TryFrom<GeoPoint>>::Error>,
142140
{
143141
/// The segment's start point.
144142
pub start: P,
@@ -153,10 +151,7 @@ where
153151
pub start_azimuth: Degree<f64>,
154152
}
155153

156-
pub trait HasGeoPoint: PartialEq + TryFrom<GeoPoint> + Copy
157-
where
158-
<Self as TryFrom<GeoPoint>>::Error: Into<CourseError>,
159-
{
154+
pub trait HasGeoPoint: PartialEq + Copy {
160155
fn geo(&self) -> &GeoPoint;
161156
}
162157

0 commit comments

Comments
 (0)