-
Notifications
You must be signed in to change notification settings - Fork 338
/
IPoint.hx
87 lines (67 loc) · 1.73 KB
/
IPoint.hx
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
package h3d.col;
using hxd.Math;
class IPoint #if apicheck implements h2d.impl.PointApi.IPointApi<IPoint> #end {
public var x : Int;
public var y : Int;
public var z : Int;
// -- gen api
public inline function new(x=0,y=0,z=0) {
this.x = x;
this.y = y;
this.z = z;
}
public function toString() {
return 'IPoint{$x,$y,$z}';
}
public inline function scaled( v : Int ) {
return new IPoint(x * v, y * v, z * v);
}
public inline function set(x=0, y=0, z=0) {
this.x = x;
this.y = y;
this.z = z;
}
public inline function equals( other : IPoint ) : Bool {
return x == other.x && y == other.y && z == other.z;
}
public inline function load( p : IPoint ) {
this.x = p.x;
this.y = p.y;
this.z = p.z;
}
public inline function distanceSq( p : IPoint ) {
var dx = p.x - x;
var dy = p.y - y;
var dz = p.z - z;
return dx * dx + dy * dy + dz * dz;
}
public inline function distance( p : IPoint ) {
return Math.sqrt(distanceSq(p));
}
public inline function lengthSq() {
return x * x + y * y + z * z;
}
public inline function length() {
return Math.sqrt(x * x + y * y + z * z);
}
public inline function clone() {
return new IPoint(x,y,z);
}
public inline function scale( v : Int ) {
x *= v;
y *= v;
z *= v;
}
public inline function add( p : IPoint ) {
return new IPoint(x + p.x, y + p.y, z + p.z);
}
public inline function sub( p : IPoint ) {
return new IPoint(x - p.x, y - p.y, z - p.z);
}
public inline function dot( p : IPoint ) {
return x * p.x + y * p.y + z * p.z;
}
public inline function cross( p : IPoint ) {
return new IPoint(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
}
}