Improve docs and use unix line endings (#2)

* use unix line endings
* improving some docs
* add mddoc dep
This commit is contained in:
guzba 2020-03-05 19:44:26 -06:00 committed by GitHub
parent b84d23be05
commit c212d3d95b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 481 additions and 481 deletions

View file

@ -34,4 +34,3 @@ jobs:
echo $PATH
nimble install -y
nim c src/vmath.nim

View file

@ -1,8 +1,9 @@
# VMath
Collection of math rutines that for 2d and 3d graphics.
Collection of math routines for 2d and 3d graphics.
Has functions for Vec2, Vec3, Vec4, Mat3, Mat4 and Quat.
Has functinos for Vec2, Vec3, Vec4, Mat3, Mat4 and Quat.
# API: vmath
```nim
@ -11,7 +12,7 @@ import vmath
## **proc** clamp
Clamps n to min or max if its over.
Clamps n to min, else returns max if n is higher.
```nim
proc clamp(n, min, max: float32): float32
@ -27,7 +28,7 @@ proc sign(v: float32): float32
## **proc** quantize
Makes v be multipe of n. Rounding to intger quantize by 1.0.
Makes v be multipe of n. Rounding to integer quantize by 1.0.
```nim
proc quantize(v: float32; n: float32): float32
@ -271,7 +272,7 @@ proc fixAngle(angle: float32): float32
## **proc** angle
Angle of a vec2.
Angle of a Vec2.
```nim
proc angle(a: Vec2): float32
@ -279,7 +280,7 @@ proc angle(a: Vec2): float32
## **proc** angleBetween
Angle between 2 vec
Angle between 2 Vec2.
```nim
proc angleBetween(a: Vec2; b: Vec2): float32
@ -287,7 +288,7 @@ proc angleBetween(a: Vec2; b: Vec2): float32
## **proc** angleBetween
Angle between angle a and angle b
Angle between angle a and angle b.
```nim
proc angleBetween(a, b: float32): float32
@ -295,7 +296,7 @@ proc angleBetween(a, b: float32): float32
## **proc** turnAngle
Move from angle a to angle b with step of v
Move from angle a to angle b with step of v.
```nim
proc turnAngle(a, b, speed: float32): float32
@ -588,7 +589,7 @@ proc almostEquals(a, b: Vec3; precision = 1e-006): bool
## **proc** randVec3
Generates a random vector based on: <a class="reference external" href="http://mathworld.wolfram.com/SpherePointPicking.html">http://mathworld.wolfram.com/SpherePointPicking.html</a> .
Generates a random vector based on <a class="reference external" href="http://mathworld.wolfram.com/SpherePointPicking.html">http://mathworld.wolfram.com/SpherePointPicking.html</a>
```nim
proc randVec3(): Vec3
@ -1106,7 +1107,7 @@ proc xyz=(q: var Quat; v: Vec3)
## **proc** `*`
Multiply the quaternion by a quaternion
Multiply the quaternion by a quaternion.
```nim
proc `*`(a, b: Quat): Quat
@ -1114,7 +1115,7 @@ proc `*`(a, b: Quat): Quat
## **proc** `*`
Multiply the quaternion by a float32
Multiply the quaternion by a float32.
```nim
proc `*`(q: Quat; v: float32): Quat
@ -1122,7 +1123,7 @@ proc `*`(q: Quat; v: float32): Quat
## **proc** `*`
Multiply the quaternion by a vector
Multiply the quaternion by a vector.
```nim
proc `*`(q: Quat; v: Vec3): Vec3
@ -1261,7 +1262,7 @@ proc rect(pos, size: Vec2): Rect
## **proc** xy
Gets the xy as a vec2
Gets the xy as a Vec2.
```nim
proc xy(rect: Rect): Vec2
@ -1269,7 +1270,7 @@ proc xy(rect: Rect): Vec2
## **proc** xy=
Sets the xy from vec2
Sets the xy from Vec2.
```nim
proc xy=(rect: var Rect; v: Vec2)
@ -1277,7 +1278,7 @@ proc xy=(rect: var Rect; v: Vec2)
## **proc** wh
Gets the wh as a vec2
Gets the wh as a Vec2.
```nim
proc wh(rect: Rect): Vec2
@ -1285,7 +1286,7 @@ proc wh(rect: Rect): Vec2
## **proc** wh=
Sets the wh from vec2
Sets the wh from Vec2.
```nim
proc wh=(rect: var Rect; v: Vec2)
@ -1294,7 +1295,7 @@ proc wh=(rect: var Rect; v: Vec2)
## **proc** `*`
* all elements of a rect
* all elements of a Rect.
@ -1304,7 +1305,7 @@ proc `*`(r: Rect; v: float): Rect
## **proc** `/`
/ all elements of a rect
/ all elements of a Rect.
```nim
proc `/`(r: Rect; v: float): Rect
@ -1312,7 +1313,7 @@ proc `/`(r: Rect; v: float): Rect
## **proc** intersects
Checks if point is inside the rectangle
Checks if pos is inside rect.
```nim
proc intersects(rect: Rect; pos: Vec2): bool
@ -1324,4 +1325,3 @@ proc intersects(rect: Rect; pos: Vec2): bool
```nim
proc `$`(a: Rect): string
```

View file

@ -5,7 +5,7 @@ export math
proc clamp*(n, min, max: float32): float32 =
## Clamps n to min or max if its over.
## Clamps n to min, else returns max if n is higher.
if n < min:
return min
if n > max:
@ -19,7 +19,7 @@ proc sign*(v: float32): float32 =
return -1.0
proc quantize*(v: float32, n: float32): float32 =
## Makes v be multipe of n. Rounding to intger quantize by 1.0.
## Makes v be multipe of n. Rounding to integer quantize by 1.0.
result = sign(v) * floor(abs(v) / n) * n
proc lerp*(a: float32, b: float32, v: float32): float32 =
@ -161,19 +161,19 @@ proc fixAngle*(angle: float32): float32 =
return angle
proc angle*(a: Vec2): float32 =
## Angle of a vec2.
## Angle of a Vec2.
math.arctan2(a.y, a.x)
proc angleBetween*(a: Vec2, b: Vec2): float32 =
## Angle between 2 vec
## Angle between 2 Vec2.
fixAngle(math.arctan2(a.y - b.y, a.x - b.x))
proc angleBetween*(a, b: float32): float32 =
## Angle between angle a and angle b
## Angle between angle a and angle b.
(b - a).fixAngle
proc turnAngle*(a, b, speed: float32): float32 =
## Move from angle a to angle b with step of v
## Move from angle a to angle b with step of v.
var
turn = fixAngle(b - a)
if abs(turn) < speed:
@ -349,7 +349,7 @@ proc almostEquals*(a, b: Vec3, precision = 1e-6): bool =
return abs(c.x) < precision and abs(c.y) < precision and abs(c.z) < precision
proc randVec3*(): Vec3 =
## Generates a random vector based on: http://mathworld.wolfram.com/SpherePointPicking.html .
## Generates a random vector based on http://mathworld.wolfram.com/SpherePointPicking.html
let
u = rand(0.0 .. 1.0)
v = rand(0.0 .. 1.0)
@ -596,7 +596,7 @@ proc scale*(a: Mat3, v: Vec3): Mat3 =
proc rotationMat3*(angle: float32): Mat3 =
# create a matrix from an angle
# Create a matrix from an angle.
let
sin = sin(angle)
cos = cos(angle)
@ -614,7 +614,7 @@ proc rotationMat3*(angle: float32): Mat3 =
proc rotate*(a: Mat3, angle: float32): Mat3 =
# rotates a matrix by an angle
# Rotates a matrix by an angle.
a * rotationMat3(angle)
@ -964,7 +964,7 @@ proc hrp*(m: Mat4): Vec3 =
heading = arctan2(m[2], m[10])
pitch = PI / 2
roll = 0
elif m[1] < -0.998: # singularity at sresulth pole
elif m[1] < -0.998: # singularity at south pole
heading = arctan2(m[2], m[10])
pitch = -PI / 2
roll = 0
@ -1187,7 +1187,7 @@ proc `xyz=`*(q: var Quat, v: Vec3) =
proc `*`*(a, b: Quat): Quat =
## Multiply the quaternion by a quaternion
## Multiply the quaternion by a quaternion.
#[
var q = quat(0,0,0,0)
q.w = dot(a.xyz, b.xyz)
@ -1205,7 +1205,7 @@ proc `*`*(a, b: Quat): Quat =
result.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z
proc `*`*(q: Quat, v: float32): Quat =
## Multiply the quaternion by a float32
## Multiply the quaternion by a float32.
result.x = q.x * v
result.y = q.y * v
result.z = q.z * v
@ -1213,7 +1213,7 @@ proc `*`*(q: Quat, v: float32): Quat =
proc `*`*(q: Quat, v: Vec3): Vec3 =
## Multiply the quaternion by a vector
## Multiply the quaternion by a vector.
var
x = v.x
y = v.y
@ -1446,33 +1446,33 @@ proc rect*(pos, size: Vec2): Rect =
result.h = size.y
proc xy*(rect: Rect): Vec2 =
## Gets the xy as a vec2
## Gets the xy as a Vec2.
vec2(rect.x, rect.y)
proc `xy=`*(rect: var Rect, v: Vec2) =
## Sets the xy from vec2
## Sets the xy from Vec2.
rect.x = v.x
rect.y = v.y
proc wh*(rect: Rect): Vec2 =
## Gets the wh as a vec2
## Gets the wh as a Vec2.
vec2(rect.w, rect.h)
proc `wh=`*(rect: var Rect, v: Vec2) =
## Sets the wh from vec2
## Sets the wh from Vec2.
rect.w = v.x
rect.h = v.y
proc `*`*(r: Rect, v: float): Rect =
## * all elements of a rect
## * all elements of a Rect.
rect(r.x * v, r.y * v, r.w * v, r.h * v)
proc `/`*(r: Rect, v: float): Rect =
## / all elements of a rect
## / all elements of a Rect.
rect(r.x / v, r.y / v, r.w / v, r.h / v)
proc intersects*(rect: Rect, pos: Vec2): bool =
## Checks if point is inside the rectangle
## Checks if pos is inside rect.
(rect.x <= pos.x and pos.x <= rect.x + rect.w) and (
rect.y <= pos.y and pos.y <= rect.y + rect.h)

View file

@ -9,3 +9,4 @@ srcDir = "src"
# Dependencies
requires "nim >= 0.19.1"
requires "mddoc >= 0.0.2"