lina/
space.rs

1
2/// A semantic geometric space, e.g. model space, world space, view space.
3///
4/// Many types in this library have a generic parameter `S: Space`. This can be
5/// used to treat points, for example, from different spaces as different
6/// types. This is another way to let Rust help catching logic errors by using
7/// strong typing.
8///
9/// For example, consider a 3D application where you load meshes from files. The
10/// loaded points exist in "model space" where the object is usually centered
11/// around the origin. To place it in the world/scene, you will usually
12/// translate, rotate and scale the object. The transformed object (i.e. all
13/// its points) now lives in the "world space". It would **not** make sense to
14/// calculate the distance between a point in model space and a point in world
15/// space. In fact, there is almost no operation that makes sense to deal with
16/// points or vectors from two different spaces.
17///
18/// Also see [`crate::docs::strong_typing`] for more information.
19///
20/// This trait is just a marker trait, not containing anything interesting. Taim
21/// provides a few implementations that might be useful. But you are also
22/// encouraged to create your own spaces if the provided ones don't fit your
23/// use case. Adding a new space is super trivial. I would recommend also
24/// making the space type uninhabited, i.e. `enum Name {}`.
25///
26/// Note that this trait does not necessarily represent any mathematical
27/// concept. Yes, different `Space`s will usually have different basis-vectors,
28/// for example. But understand this trait just as abstraction over "model
29/// space", "world space", "view space" and others.
30pub trait Space: 'static {}
31
32
33/// A space that is model/object-local usually with a single object at the center.
34///
35/// Note that this has no special semantics in `lina` and is just provided for
36/// your convenience, as this is a very common space one wants to distinguish.
37/// The exact semantics are up to you.
38pub enum ModelSpace {}
39impl Space for ModelSpace {}
40
41/// A space containing the whole scene/world with an arbitrary origin.
42///
43/// Note that this has no special semantics in `lina` and is just provided for
44/// your convenience, as this is a very common space one wants to distinguish.
45/// The exact semantics are up to you.
46pub enum WorldSpace {}
47impl Space for WorldSpace {}
48
49/// A camera-centric space with the camera at the origin looking down an axis
50/// (usually z).
51///
52/// Note that this has no special semantics in `lina` and is just provided for
53/// your convenience, as this is a very common space one wants to distinguish.
54/// The exact semantics are up to you.
55pub enum ViewSpace {}
56impl Space for ViewSpace {}
57
58/// A post-projection space with angles and distances distorted.
59///
60/// Note that this has no special semantics in `lina` and is just provided for
61/// your convenience, as this is a very common space one wants to distinguish.
62/// The exact semantics are up to you.
63pub enum ProjSpace {}
64impl Space for ProjSpace {}