1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 12:50:04 -04:00

Add misc documentation

This commit is contained in:
Emil Ernerfeldt
2022-01-22 08:56:36 +01:00
parent 8138a073e7
commit 199bbef77b
11 changed files with 46 additions and 13 deletions

View File

@@ -8,6 +8,12 @@
//! * X+ is right and Y+ is down.
//! * (0,0) is left top.
//! * Dimension order is always `x y`
//!
//! ## Integrating with other math libraries.
//! `emath` does not strive to become a general purpose or all-powerful math library.
//!
//! For that, use something else ([`glam`](https://docs.rs/glam), [`nalgebra`](https://docs.rs/nalgebra), …)
//! and enable the `mint` feature flag in `emath` to enable implicit conversion to/from `emath`.
// Forbid warnings in release builds:
#![cfg_attr(not(debug_assertions), deny(warnings))]

View File

@@ -13,12 +13,14 @@ use crate::*;
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Pos2 {
/// How far to the right.
pub x: f32,
/// How far down.
pub y: f32,
// implicit w = 1
}
/// `pos2(x,y) == Pos2::new(x, y)`
/// `pos2(x, y) == Pos2::new(x, y)`
#[inline(always)]
pub const fn pos2(x: f32, y: f32) -> Pos2 {
Pos2 { x, y }
@@ -91,6 +93,7 @@ impl From<&Pos2> for (f32, f32) {
#[cfg(feature = "mint")]
impl From<mint::Point2<f32>> for Pos2 {
#[inline(always)]
fn from(v: mint::Point2<f32>) -> Self {
Self::new(v.x, v.y)
}
@@ -98,6 +101,7 @@ impl From<mint::Point2<f32>> for Pos2 {
#[cfg(feature = "mint")]
impl From<Pos2> for mint::Point2<f32> {
#[inline(always)]
fn from(v: Pos2) -> Self {
Self { x: v.x, y: v.y }
}

View File

@@ -11,11 +11,13 @@ use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Vec2 {
/// Rightwards. Width.
pub x: f32,
/// Downwards. Height.
pub y: f32,
}
/// `vec2(x,y) == Vec2::new(x, y)`
/// `vec2(x, y) == Vec2::new(x, y)`
#[inline(always)]
pub const fn vec2(x: f32, y: f32) -> Vec2 {
Vec2 { x, y }
@@ -88,6 +90,7 @@ impl From<&Vec2> for (f32, f32) {
#[cfg(feature = "mint")]
impl From<mint::Vector2<f32>> for Vec2 {
#[inline]
fn from(v: mint::Vector2<f32>) -> Self {
Self::new(v.x, v.y)
}
@@ -95,6 +98,7 @@ impl From<mint::Vector2<f32>> for Vec2 {
#[cfg(feature = "mint")]
impl From<Vec2> for mint::Vector2<f32> {
#[inline]
fn from(v: Vec2) -> Self {
Self { x: v.x, y: v.y }
}