Skip to content

Commit

Permalink
Merge pull request #385 from rustsim/matrix_vec_no_deref
Browse files Browse the repository at this point in the history
Remove the Deref implementation for MatrixVec
  • Loading branch information
sebcrozet committed Feb 3, 2019
2 parents 21c163d + f52bd4b commit d702bf0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Expand Up @@ -35,7 +35,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Implement `Extend<Matrix<...>>` for matrices with dynamic storage. This will concatenate the columns of both matrices.
* Implement `Into<Vec>` for the `MatrixVec` storage.
* Implement `Hash` for all matrices.

* Add a `.len()` method to retrieve the size of a `MatrixVec`.

### Modified
* The orthographic projection no longer require that `bottom < top`, that `left < right`, and that `znear < zfar`. The
only restriction now ith that they must not be equal (in which case the projection would be singular).
Expand All @@ -46,11 +47,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Renamed `.unwrap()` to `.into_inner()` for geometric types that wrap another type.
This is for the case of `Unit`, `Transform`, `Orthographic3`, `Perspective3`, `Rotation`.
* Deprecate several functions at the root of the crate (replaced by methods).


### Removed
* Remove the `Deref` impl for `MatrixVec` as it could cause hard-to-understand compilation errors.

### nalgebra-glm
* Add several alternative projection computations, e.g., `ortho_lh`, `ortho_lh_no`, `perspective_lh`, etc.
* Add features matching those of nalgebra, in particular: `serde-serialize`, `abmonation-serialize`, std` (enabled by default).

## [0.16.0]
All dependencies have been updated to their latest versions.

Expand Down
2 changes: 1 addition & 1 deletion src/base/construction.rs
Expand Up @@ -270,7 +270,7 @@ where DefaultAllocator: Allocator<N, R, C>
/// let vec_ptr = vec.as_ptr();
///
/// let matrix = Matrix::from_vec_generic(Dynamic::new(vec.len()), U1, vec);
/// let matrix_storage_ptr = matrix.data.as_ptr();
/// let matrix_storage_ptr = matrix.data.as_vec().as_ptr();
///
/// // `matrix` is backed by exactly the same `Vec` as it was constructed from.
/// assert_eq!(matrix_storage_ptr, vec_ptr);
Expand Down
21 changes: 9 additions & 12 deletions src/base/vec_storage.rs
@@ -1,6 +1,5 @@
#[cfg(feature = "abomonation-serialize")]
use std::io::{Result as IOResult, Write};
use std::ops::Deref;

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
Expand Down Expand Up @@ -51,15 +50,16 @@ impl<N, R: Dim, C: Dim> VecStorage<N, R, C> {

/// The underlying data storage.
#[inline]
pub fn data(&self) -> &Vec<N> {
pub fn as_vec(&self) -> &Vec<N> {
&self.data
}

/// The underlying mutable data storage.
///
/// This is unsafe because this may cause UB if the vector is modified by the user.
/// This is unsafe because this may cause UB if the size of the vector is changed
/// by the user.
#[inline]
pub unsafe fn data_mut(&mut self) -> &mut Vec<N> {
pub unsafe fn as_vec_mut(&mut self) -> &mut Vec<N> {
&mut self.data
}

Expand All @@ -81,14 +81,11 @@ impl<N, R: Dim, C: Dim> VecStorage<N, R, C> {

self.data
}
}

impl<N, R: Dim, C: Dim> Deref for VecStorage<N, R, C> {
type Target = Vec<N>;

/// The number of elements on the underlying vector.
#[inline]
fn deref(&self) -> &Self::Target {
&self.data
pub fn len(&self) -> usize {
self.data.len()
}
}

Expand Down Expand Up @@ -145,7 +142,7 @@ where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>

#[inline]
fn as_slice(&self) -> &[N] {
&self[..]
&self.data
}
}

Expand Down Expand Up @@ -189,7 +186,7 @@ where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>

#[inline]
fn as_slice(&self) -> &[N] {
&self[..]
&self.data
}
}

Expand Down

0 comments on commit d702bf0

Please sign in to comment.