aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/examples/sokol/particles/modules/particle/vec2/vec2.v
blob: ec41485662e53cfae0a8561274e7f6a3a313a9a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright(C) 2019 Lars Pontoppidan. All rights reserved.
// Use of this source code is governed by an MIT license file distributed with this software package
module vec2

pub struct Vec2 {
pub mut:
	x f64
	y f64
}

pub fn (mut v Vec2) zero() {
	v.x = 0.0
	v.y = 0.0
}

pub fn (mut v Vec2) from(src Vec2) {
	v.x = src.x
	v.y = src.y
}

// * Addition
// + operator overload. Adds two vectors
pub fn (v1 Vec2) + (v2 Vec2) Vec2 {
	return Vec2{v1.x + v2.x, v1.y + v2.y}
}

pub fn (v Vec2) add(vector Vec2) Vec2 {
	return Vec2{v.x + vector.x, v.y + vector.y}
}

pub fn (v Vec2) add_f64(scalar f64) Vec2 {
	return Vec2{v.x + scalar, v.y + scalar}
}

pub fn (mut v Vec2) plus(vector Vec2) {
	v.x += vector.x
	v.y += vector.y
}

pub fn (mut v Vec2) plus_f64(scalar f64) {
	v.x += scalar
	v.y += scalar
}

// * Subtraction
pub fn (v1 Vec2) - (v2 Vec2) Vec2 {
	return Vec2{v1.x - v2.x, v1.y - v2.y}
}

pub fn (v Vec2) sub(vector Vec2) Vec2 {
	return Vec2{v.x - vector.x, v.y - vector.y}
}

pub fn (v Vec2) sub_f64(scalar f64) Vec2 {
	return Vec2{v.x - scalar, v.y - scalar}
}

pub fn (mut v Vec2) subtract(vector Vec2) {
	v.x -= vector.x
	v.y -= vector.y
}

pub fn (mut v Vec2) subtract_f64(scalar f64) {
	v.x -= scalar
	v.y -= scalar
}

// * Multiplication
pub fn (v1 Vec2) * (v2 Vec2) Vec2 {
	return Vec2{v1.x * v2.x, v1.y * v2.y}
}

pub fn (v Vec2) mul(vector Vec2) Vec2 {
	return Vec2{v.x * vector.x, v.y * vector.y}
}

pub fn (v Vec2) mul_f64(scalar f64) Vec2 {
	return Vec2{v.x * scalar, v.y * scalar}
}

pub fn (mut v Vec2) multiply(vector Vec2) {
	v.x *= vector.x
	v.y *= vector.y
}

pub fn (mut v Vec2) multiply_f64(scalar f64) {
	v.x *= scalar
	v.y *= scalar
}