Skip to content

Commit 2c0a3cc

Browse files
committed
Rename look_at -> look_to for Matrix2 and related
Rename functions look_at* to look_to* on Matrix2 and related rotation transforms.
1 parent 609dada commit 2c0a3cc

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/matrix.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,29 @@ impl<S> Matrix2<S> {
101101
impl<S: BaseFloat> Matrix2<S> {
102102
/// Create a transformation matrix that will cause `unit_x()` to point at
103103
/// `dir`. `unit_y()` will be perpendicular to `dir`, and the closest to `up`.
104+
#[deprecated = "Use Matrix2::look_to"]
104105
pub fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Matrix2<S> {
105-
Matrix2::look_at_stable(dir, up.x * dir.y >= up.y * dir.x)
106+
Matrix2::look_to(dir, up)
106107
}
107108

108109
/// Crate a transformation that will cause `unit_x()` to point at
109-
/// `dir`. This is similar to `look_at`, but does not take an `up` vector.
110+
/// `dir`. This is similar to `look_to`, but does not take an `up` vector.
110111
/// This will not cause `unit_y()` to flip when `dir` crosses over the `up` vector.
112+
#[deprecated = "Use Matrix2::look_to_stable"]
111113
pub fn look_at_stable(dir: Vector2<S>, flip: bool) -> Matrix2<S> {
114+
Matrix2::look_to_stable(dir, flip)
115+
}
116+
117+
/// Create a transformation matrix that will cause `unit_x()` to point at
118+
/// `dir`. `unit_y()` will be perpendicular to `dir`, and the closest to `up`.
119+
pub fn look_to(dir: Vector2<S>, up: Vector2<S>) -> Matrix2<S> {
120+
Matrix2::look_to_stable(dir, up.x * dir.y >= up.y * dir.x)
121+
}
122+
123+
/// Crate a transformation that will cause `unit_x()` to point at
124+
/// `dir`. This is similar to `look_to`, but does not take an `up` vector.
125+
/// This will not cause `unit_y()` to flip when `dir` crosses over the `up` vector.
126+
pub fn look_to_stable(dir: Vector2<S>, flip: bool) -> Matrix2<S> {
112127
let basis1 = dir.normalize();
113128
let basis2 = if flip {
114129
Vector2::new(basis1.y, -basis1.x)
@@ -1093,17 +1108,17 @@ impl<S: BaseFloat> Transform<Point2<S>> for Matrix3<S> {
10931108

10941109
fn look_at(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> {
10951110
let dir = center - eye;
1096-
Matrix3::from(Matrix2::look_at(dir, up))
1111+
Matrix3::from(Matrix2::look_to(dir, up))
10971112
}
10981113

10991114
fn look_at_lh(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> {
11001115
let dir = center - eye;
1101-
Matrix3::from(Matrix2::look_at(dir, up))
1116+
Matrix3::from(Matrix2::look_to(dir, up))
11021117
}
11031118

11041119
fn look_at_rh(eye: Point2<S>, center: Point2<S>, up: Vector2<S>) -> Matrix3<S> {
11051120
let dir = eye - center;
1106-
Matrix3::from(Matrix2::look_at(dir, up))
1121+
Matrix3::from(Matrix2::look_to(dir, up))
11071122
}
11081123

11091124
fn transform_vector(&self, vec: Vector2<S>) -> Vector2<S> {

src/rotation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ pub struct Basis2<S> {
148148
}
149149

150150
impl<S: BaseFloat> Basis2<S> {
151-
pub fn look_at_stable(dir: Vector2<S>, flip: bool) -> Basis2<S> {
151+
pub fn look_to_stable(dir: Vector2<S>, flip: bool) -> Basis2<S> {
152152
Basis2 {
153-
mat: Matrix2::look_at_stable(dir, flip),
153+
mat: Matrix2::look_to_stable(dir, flip),
154154
}
155155
}
156156
}
@@ -187,7 +187,7 @@ impl<S: BaseFloat> Rotation<Point2<S>> for Basis2<S> {
187187
#[inline]
188188
fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Basis2<S> {
189189
Basis2 {
190-
mat: Matrix2::look_at(dir, up),
190+
mat: Matrix2::look_to(dir, up),
191191
}
192192
}
193193

tests/matrix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,18 @@ pub mod matrix2 {
190190
}
191191

192192
#[test]
193-
fn test_look_at() {
193+
fn test_look_to() {
194194
// rot should rotate unit_x() to look at the input vector
195-
let rot = Matrix2::look_at(V, Vector2::unit_y());
195+
let rot = Matrix2::look_to(V, Vector2::unit_y());
196196
assert_eq!(rot * Vector2::unit_x(), V.normalize());
197197
let new_up = Vector2::new(-V.y, V.x).normalize();
198198
assert_eq!(rot * Vector2::unit_y(), new_up);
199199

200-
let rot_down = Matrix2::look_at(V, -1.0 * Vector2::unit_y());
200+
let rot_down = Matrix2::look_to(V, -1.0 * Vector2::unit_y());
201201
assert_eq!(rot_down * Vector2::unit_x(), V.normalize());
202202
assert_eq!(rot_down * Vector2::unit_y(), -1.0 * new_up);
203203

204-
let rot2 = Matrix2::look_at(-V, Vector2::unit_y());
204+
let rot2 = Matrix2::look_to(-V, Vector2::unit_y());
205205
assert_eq!(rot2 * Vector2::unit_x(), (-V).normalize());
206206
}
207207
}

0 commit comments

Comments
 (0)