cgmath
cgmath copied to clipboard
Improve naming of Point::{from_vec, to_vec} to reflect their semantic meaning
The following properties are true for Point::{from_vec, to_vec}:
Point::from_vec(v) - Point::origin() == vPoint::origin() + Point::to_vec(p) == p
This suggests that semantically, these are actually all about displacements from the origin. I'm proposing to do the following renames:
Point::from_vectoPoint::from_displacementPoint::to_vectoPoint::displacement
Another possibility would be:
Point::from_vectoPoint::from_translationPoint::to_vectoPoint::translation
Another option might be to have an Origin marker struct like in CGAL:
struct Origin;
impl<S: BaseNum> Sub<Origin> for Point3<S> {
type Output = Vector3<S>;
#[inline]
fn sub(self, Origin: Origin) -> Vector3<S> {
unsafe { mem::transmute(self) }
}
}
impl<S: BaseNum> Add<Vector3<S>> for Origin {
type Output = Point3<S>;
#[inline]
fn sub(self, displacement: Vector3<S>) -> Point3<S> {
unsafe { mem::transmute(displacement) }
}
}
let displacement = point - Origin;
let point = Origin + displacement;
Am I confused, or does this have to do with #320?
This is to do with the naming of the methods, which #320 doesn't touch yet.
Also notice that rotation/transform API uses the full vector suffix, unlike the subject methods:
rotate_vectortransform_vectorbetween_vectors
So leaving to_vec and from_vec means inconsistency in the API.
I'm in favor of the names from_vec and to_vec, because they're quicker to type, they imply that we're talking about a type conversion (whereas it might be uncertain what a "displacement" is, unless one has read the docs), and they seem like easier names for new users of the library to remember. Lastly, because it would be a breaking change to alter them.