Skip to content

Commit b7d8063

Browse files
committed
Remove references in function params for Copy types.
1 parent ddbab2d commit b7d8063

12 files changed

+142
-142
lines changed

geo-types/src/algorithms.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ pub trait EuclideanDistance<T, Rhs = Self> {
88
fn euclidean_distance(&self, rhs: &Rhs) -> T;
99
}
1010

11-
fn line_segment_distance<T>(point: &Point<T>, start: &Point<T>, end: &Point<T>) -> T
11+
fn line_segment_distance<T>(point: Point<T>, start: Point<T>, end: Point<T>) -> T
1212
where
1313
T: Float + ToPrimitive,
1414
{
1515
if start == end {
16-
return point.euclidean_distance(start);
16+
return point.euclidean_distance(&start);
1717
}
1818
let dx = end.x() - start.x();
1919
let dy = end.y() - start.y();
2020
let r =
2121
((point.x() - start.x()) * dx + (point.y() - start.y()) * dy) / (dx.powi(2) + dy.powi(2));
2222
if r <= T::zero() {
23-
return point.euclidean_distance(start);
23+
return point.euclidean_distance(&start);
2424
}
2525
if r >= T::one() {
26-
return point.euclidean_distance(end);
26+
return point.euclidean_distance(&end);
2727
}
2828
let s = ((start.y() - point.y()) * dx - (start.x() - point.x()) * dy) / (dx * dx + dy * dy);
2929
s.abs() * (dx * dx + dy * dy).sqrt()
@@ -44,7 +44,7 @@ where
4444
T: Float,
4545
{
4646
fn euclidean_distance(&self, point: &Point<T>) -> T {
47-
line_segment_distance(point, &self.start, &self.end)
47+
line_segment_distance(*point, self.start, self.end)
4848
}
4949
}
5050

geo-types/src/point.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ where
129129
///
130130
/// assert_eq!(p.lng(), 1.234);
131131
/// ```
132-
pub fn lng(&self) -> T {
132+
pub fn lng(self) -> T {
133133
self.x()
134134
}
135135

@@ -160,7 +160,7 @@ where
160160
///
161161
/// assert_eq!(p.lat(), 2.345);
162162
/// ```
163-
pub fn lat(&self) -> T {
163+
pub fn lat(self) -> T {
164164
self.y()
165165
}
166166

@@ -189,11 +189,11 @@ where
189189
/// use geo_types::Point;
190190
///
191191
/// let p = Point::new(1.5, 0.5);
192-
/// let dot = p.dot(&Point::new(2.0, 4.5));
192+
/// let dot = p.dot(Point::new(2.0, 4.5));
193193
///
194194
/// assert_eq!(dot, 5.25);
195195
/// ```
196-
pub fn dot(&self, point: &Point<T>) -> T {
196+
pub fn dot(self, point: Point<T>) -> T {
197197
self.x() * point.x() + self.y() * point.y()
198198
}
199199

@@ -210,11 +210,11 @@ where
210210
/// let p_b = Point::new(3.0,5.0);
211211
/// let p_c = Point::new(7.0,12.0);
212212
///
213-
/// let cross = p_a.cross_prod(&p_b, &p_c);
213+
/// let cross = p_a.cross_prod(p_b, p_c);
214214
///
215215
/// assert_eq!(cross, 2.0)
216216
/// ```
217-
pub fn cross_prod(&self, point_b: &Point<T>, point_c: &Point<T>) -> T
217+
pub fn cross_prod(self, point_b: Point<T>, point_c: Point<T>) -> T
218218
where
219219
T: Float,
220220
{

geo-types/src/polygon.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ where
8989
let prev_1 = self.previous_vertex(&idx);
9090
let prev_2 = self.previous_vertex(&prev_1);
9191
self.exterior.0[prev_2].cross_prod(
92-
&self.exterior.0[prev_1],
93-
&self.exterior.0[idx]
92+
self.exterior.0[prev_1],
93+
self.exterior.0[idx]
9494
)
9595
})
9696
// accumulate and check cross-product result signs in a single pass

geo/src/algorithm/closest_point.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<F: Float> ClosestPoint<F> for Line<F> {
6464
let direction_vector = self.end - self.start;
6565
let to_p = *p - self.start;
6666

67-
let t = to_p.dot(&direction_vector) / direction_vector.dot(&direction_vector);
67+
let t = to_p.dot(direction_vector) / direction_vector.dot(direction_vector);
6868

6969
// check the cases where the closest point is "outside" the line
7070
if t < F::zero() {
@@ -91,7 +91,7 @@ impl<F: Float> ClosestPoint<F> for Line<F> {
9191
/// the `Closest::SinglePoint` which is closest to `p`.
9292
///
9393
/// If the iterator is empty, we get `Closest::Indeterminate`.
94-
fn closest_of<C, F, I>(iter: I, p: &Point<F>) -> Closest<F>
94+
fn closest_of<C, F, I>(iter: I, p: Point<F>) -> Closest<F>
9595
where
9696
F: Float,
9797
I: IntoIterator<Item = C>,
@@ -100,7 +100,7 @@ where
100100
let mut best = Closest::Indeterminate;
101101

102102
for line_segment in iter {
103-
let got = line_segment.closest_point(p);
103+
let got = line_segment.closest_point(&p);
104104
best = got.best_of_two(&best, p);
105105
}
106106

@@ -109,32 +109,32 @@ where
109109

110110
impl<F: Float> ClosestPoint<F> for LineString<F> {
111111
fn closest_point(&self, p: &Point<F>) -> Closest<F> {
112-
closest_of(self.lines(), p)
112+
closest_of(self.lines(), *p)
113113
}
114114
}
115115

116116
impl<F: Float> ClosestPoint<F> for Polygon<F> {
117117
fn closest_point(&self, p: &Point<F>) -> Closest<F> {
118118
let prospectives = self.interiors.iter().chain(iter::once(&self.exterior));
119-
closest_of(prospectives, p)
119+
closest_of(prospectives, *p)
120120
}
121121
}
122122

123123
impl<F: Float> ClosestPoint<F> for MultiPolygon<F> {
124124
fn closest_point(&self, p: &Point<F>) -> Closest<F> {
125-
closest_of(self.0.iter(), p)
125+
closest_of(self.0.iter(), *p)
126126
}
127127
}
128128

129129
impl<F: Float> ClosestPoint<F> for MultiPoint<F> {
130130
fn closest_point(&self, p: &Point<F>) -> Closest<F> {
131-
closest_of(self.0.iter(), p)
131+
closest_of(self.0.iter(), *p)
132132
}
133133
}
134134

135135
impl<F: Float> ClosestPoint<F> for MultiLineString<F> {
136136
fn closest_point(&self, p: &Point<F>) -> Closest<F> {
137-
closest_of(self.0.iter(), p)
137+
closest_of(self.0.iter(), *p)
138138
}
139139
}
140140

geo/src/algorithm/contains.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(crate) enum PositionPoint {
144144
}
145145

146146
/// Calculate the position of `Point` p relative to a linestring
147-
pub(crate) fn get_position<T>(p: &Point<T>, linestring: &LineString<T>) -> PositionPoint
147+
pub(crate) fn get_position<T>(p: Point<T>, linestring: &LineString<T>) -> PositionPoint
148148
where
149149
T: Float,
150150
{
@@ -157,7 +157,7 @@ where
157157
return PositionPoint::Outside;
158158
}
159159
// Point is on linestring
160-
if linestring.contains(p) {
160+
if linestring.contains(&p) {
161161
return PositionPoint::OnBoundary;
162162
}
163163

@@ -188,11 +188,11 @@ where
188188
T: Float,
189189
{
190190
fn contains(&self, p: &Point<T>) -> bool {
191-
match get_position(p, &self.exterior) {
191+
match get_position(*p, &self.exterior) {
192192
PositionPoint::OnBoundary | PositionPoint::Outside => false,
193193
_ => self.interiors
194194
.iter()
195-
.all(|ls| get_position(p, ls) == PositionPoint::Outside),
195+
.all(|ls| get_position(*p, ls) == PositionPoint::Outside),
196196
}
197197
}
198198
}

geo/src/algorithm/convexhull.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn partition<T, F: FnMut(&T) -> bool>(mut slice: &mut [T], mut pred: F) -> usize
4949
// we can compute the cross product AB x AC and check its sign:
5050
// If it's negative, it will be on the "right" side of AB
5151
// (when standing on A and looking towards B). If positive, it will be on the left side
52-
fn point_location<T>(p_a: &Point<T>, p_b: &Point<T>, p_c: &Point<T>) -> bool
52+
fn point_location<T>(p_a: Point<T>, p_b: Point<T>, p_c: Point<T>) -> bool
5353
where
5454
T: Float,
5555
{
@@ -79,11 +79,11 @@ where
7979
mem::swap(point, max);
8080
}
8181
}
82-
let last = partition(&mut points, |p| point_location(max, min, p));
83-
hull_set(max, min, &mut points[..last], &mut hull);
82+
let last = partition(&mut points, |p| point_location(*max, *min, *p));
83+
hull_set(*max, *min, &mut points[..last], &mut hull);
8484
hull.push(*max);
85-
let last = partition(&mut points, |p| point_location(min, max, p));
86-
hull_set(min, max, &mut points[..last], &mut hull);
85+
let last = partition(&mut points, |p| point_location(*min, *max, *p));
86+
hull_set(*min, *max, &mut points[..last], &mut hull);
8787
hull.push(*min);
8888
// close the polygon
8989
let final_element = *hull.first().unwrap();
@@ -92,7 +92,7 @@ where
9292
}
9393

9494
// recursively calculate the convex hull of a subset of points
95-
fn hull_set<T>(p_a: &Point<T>, p_b: &Point<T>, mut set: &mut [Point<T>], hull: &mut Vec<Point<T>>)
95+
fn hull_set<T>(p_a: Point<T>, p_b: Point<T>, mut set: &mut [Point<T>], hull: &mut Vec<Point<T>>)
9696
where
9797
T: Float,
9898
{
@@ -107,7 +107,7 @@ where
107107
let mut furthest_idx = 0;
108108
for (idx, point) in set.iter().enumerate() {
109109
// let current_distance = pseudo_distance(p_a, p_b, point);
110-
let current_distance = point.euclidean_distance(&Line::new(*p_a, *p_b));
110+
let current_distance = point.euclidean_distance(&Line::new(p_a, p_b));
111111
if current_distance > furthest_distance {
112112
furthest_distance = current_distance;
113113
furthest_idx = idx
@@ -116,12 +116,12 @@ where
116116
// move Point at furthest_point from set into hull
117117
let furthest_point = swap_remove_to_first(&mut set, furthest_idx);
118118
// points over PB
119-
let last = partition(set, |p| point_location(furthest_point, p_b, p));
120-
hull_set(furthest_point, p_b, &mut set[..last], hull);
119+
let last = partition(set, |p| point_location(*furthest_point, p_b, *p));
120+
hull_set(*furthest_point, p_b, &mut set[..last], hull);
121121
hull.push(*furthest_point);
122122
// points over AP
123-
let last = partition(set, |p| point_location(p_a, furthest_point, p));
124-
hull_set(p_a, furthest_point, &mut set[..last], hull);
123+
let last = partition(set, |p| point_location(p_a, *furthest_point, *p));
124+
hull_set(p_a, *furthest_point, &mut set[..last], hull);
125125
}
126126

127127
pub trait ConvexHull<T> {

geo/src/algorithm/euclidean_distance.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,22 @@ pub trait EuclideanDistance<T, Rhs = Self> {
7575
/// Minimum distance between a Point and a Line segment
7676
/// This is a helper for Point-to-LineString and Point-to-Polygon distance
7777
/// Adapted from https://github.com/OSGeo/geos/blob/master/src/algorithm/CGAlgorithms.cpp#L191
78-
fn line_segment_distance<T>(point: &Point<T>, start: &Point<T>, end: &Point<T>) -> T
78+
fn line_segment_distance<T>(point: Point<T>, start: Point<T>, end: Point<T>) -> T
7979
where
8080
T: Float + ToPrimitive,
8181
{
8282
if start == end {
83-
return point.euclidean_distance(start);
83+
return point.euclidean_distance(&start);
8484
}
8585
let dx = end.x() - start.x();
8686
let dy = end.y() - start.y();
8787
let r =
8888
((point.x() - start.x()) * dx + (point.y() - start.y()) * dy) / (dx.powi(2) + dy.powi(2));
8989
if r <= T::zero() {
90-
return point.euclidean_distance(start);
90+
return point.euclidean_distance(&start);
9191
}
9292
if r >= T::one() {
93-
return point.euclidean_distance(end);
93+
return point.euclidean_distance(&end);
9494
}
9595
let s = ((start.y() - point.y()) * dx - (start.x() - point.x()) * dy) / (dx * dx + dy * dy);
9696
s.abs() * dx.hypot(dy)
@@ -151,7 +151,7 @@ where
151151
polygon
152152
.exterior
153153
.lines()
154-
.map(|line| line_segment_distance(self, &line.start, &line.end))
154+
.map(|line| line_segment_distance(*self, line.start, line.end))
155155
.fold(T::max_value(), |accum, val| accum.min(val)),
156156
)
157157
}
@@ -226,7 +226,7 @@ where
226226
}
227227
linestring
228228
.lines()
229-
.map(|line| line_segment_distance(self, &line.start, &line.end))
229+
.map(|line| line_segment_distance(*self, line.start, line.end))
230230
.fold(T::max_value(), |accum, val| accum.min(val))
231231
}
232232
}
@@ -247,7 +247,7 @@ where
247247
{
248248
/// Minimum distance from a Line to a Point
249249
fn euclidean_distance(&self, point: &Point<T>) -> T {
250-
line_segment_distance(point, &self.start, &self.end)
250+
line_segment_distance(*point, self.start, self.end)
251251
}
252252
}
253253

@@ -279,7 +279,7 @@ where
279279
/// is disjoint because it's contained in the inner ring
280280
/// we work around this by checking that Polygons with inner rings don't
281281
/// contain a point from the candidate Polygon's outer shell in their simple representations
282-
fn ring_contains_point<T>(poly: &Polygon<T>, p: &Point<T>) -> bool
282+
fn ring_contains_point<T>(poly: &Polygon<T>, p: Point<T>) -> bool
283283
where
284284
T: Float,
285285
{
@@ -319,7 +319,7 @@ where
319319
fn euclidean_distance(&self, other: &Polygon<T>) -> T {
320320
if self.intersects(other) || other.contains(self) {
321321
T::zero()
322-
} else if !other.interiors.is_empty() && ring_contains_point(other, &self.0[0]) {
322+
} else if !other.interiors.is_empty() && ring_contains_point(other, self.0[0]) {
323323
// check each ring distance, returning the minimum
324324
let mut mindist: T = Float::max_value();
325325
for ring in &other.interiors {
@@ -434,14 +434,14 @@ where
434434
return T::zero();
435435
}
436436
// Containment check
437-
if !self.interiors.is_empty() && ring_contains_point(self, &poly2.exterior.0[0]) {
437+
if !self.interiors.is_empty() && ring_contains_point(self, poly2.exterior.0[0]) {
438438
// check each ring distance, returning the minimum
439439
let mut mindist: T = Float::max_value();
440440
for ring in &self.interiors {
441441
mindist = mindist.min(nearest_neighbour_distance(&poly2.exterior, ring))
442442
}
443443
return mindist;
444-
} else if !poly2.interiors.is_empty() && ring_contains_point(poly2, &self.exterior.0[0]) {
444+
} else if !poly2.interiors.is_empty() && ring_contains_point(poly2, self.exterior.0[0]) {
445445
let mut mindist: T = Float::max_value();
446446
for ring in &poly2.interiors {
447447
mindist = mindist.min(nearest_neighbour_distance(&self.exterior, ring))
@@ -495,17 +495,17 @@ mod test {
495495
let p1 = Point::new(7.2, 2.0);
496496
let p2 = Point::new(6.0, 1.0);
497497

498-
let dist = line_segment_distance(&o1, &p1, &p2);
499-
let dist2 = line_segment_distance(&o2, &p1, &p2);
500-
let dist3 = line_segment_distance(&o3, &p1, &p2);
501-
let dist4 = line_segment_distance(&o4, &p1, &p2);
498+
let dist = line_segment_distance(o1, p1, p2);
499+
let dist2 = line_segment_distance(o2, p1, p2);
500+
let dist3 = line_segment_distance(o3, p1, p2);
501+
let dist4 = line_segment_distance(o4, p1, p2);
502502
// Results agree with Shapely
503503
assert_relative_eq!(dist, 2.0485900789263356);
504504
assert_relative_eq!(dist2, 1.118033988749895);
505505
assert_relative_eq!(dist3, 1.4142135623730951);
506506
assert_relative_eq!(dist4, 1.5811388300841898);
507507
// Point is on the line
508-
let zero_dist = line_segment_distance(&p1, &p1, &p2);
508+
let zero_dist = line_segment_distance(p1, p1, p2);
509509
assert_relative_eq!(zero_dist, 0.0);
510510
}
511511
#[test]

0 commit comments

Comments
 (0)