Mercury Geometry and Math Library
Revisão | 41d171250634ca20db35cab679afc6c030af30ae (tree) |
---|---|
Hora | 2022-04-18 04:04:53 |
Autor | AlaskanEmily <emily@alas...> |
Commiter | AlaskanEmily |
Move the entire library into its own module
@@ -4,25 +4,25 @@ | ||
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module geometry. | |
7 | +:- module mmath.geometry. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | :- interface. |
11 | 11 | %==============================================================================% |
12 | 12 | |
13 | -:- import_module vector. | |
13 | +:- import_module mmath.vector. | |
14 | 14 | |
15 | 15 | %------------------------------------------------------------------------------% |
16 | 16 | |
17 | -:- include_module geometry.triangle. | |
18 | -:- include_module geometry.segment. | |
19 | -:- include_module geometry.plane. | |
17 | +:- include_module mmath.geometry.triangle. | |
18 | +:- include_module mmath.geometry.segment. | |
19 | +:- include_module mmath.geometry.plane. | |
20 | 20 | |
21 | 21 | %------------------------------------------------------------------------------% |
22 | 22 | |
23 | -:- import_module geometry.triangle. | |
24 | -:- import_module geometry.segment. | |
25 | -:- import_module geometry.plane. | |
23 | +:- import_module mmath.geometry.triangle. | |
24 | +:- import_module mmath.geometry.segment. | |
25 | +:- import_module mmath.geometry.plane. | |
26 | 26 | |
27 | 27 | %------------------------------------------------------------------------------% |
28 | 28 |
@@ -59,7 +59,7 @@ | ||
59 | 59 | |
60 | 60 | :- import_module float. |
61 | 61 | |
62 | -:- import_module vector.vector3. | |
62 | +:- import_module mmath.vector.vector3. | |
63 | 63 | |
64 | 64 | %------------------------------------------------------------------------------% |
65 | 65 |
@@ -4,14 +4,14 @@ | ||
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module geometry.plane. | |
7 | +:- module mmath.geometry.plane. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % Geometric operations related to a 3D plane. |
11 | 11 | :- interface. |
12 | 12 | %==============================================================================% |
13 | 13 | |
14 | -:- import_module vector. | |
14 | +:- import_module mmath.vector. | |
15 | 15 | |
16 | 16 | %------------------------------------------------------------------------------% |
17 | 17 |
@@ -55,8 +55,8 @@ | ||
55 | 55 | |
56 | 56 | :- use_module math. |
57 | 57 | |
58 | -:- import_module vector.vector3. | |
59 | -:- import_module vector.vector4. | |
58 | +:- import_module mmath.vector.vector3. | |
59 | +:- import_module mmath.vector.vector4. | |
60 | 60 | |
61 | 61 | %------------------------------------------------------------------------------% |
62 | 62 |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module geometry.segment. | |
7 | +:- module mmath.geometry.segment. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % Geometric operations related to a segment. This is parametric on the vector |
@@ -12,9 +12,10 @@ | ||
12 | 12 | :- interface. |
13 | 13 | %==============================================================================% |
14 | 14 | |
15 | -:- import_module vector. | |
16 | 15 | :- import_module pair. |
17 | 16 | |
17 | +:- import_module mmath.vector. | |
18 | + | |
18 | 19 | %------------------------------------------------------------------------------% |
19 | 20 | |
20 | 21 | :- type segment(V) ---> segment(p1::V, p2::V). |
@@ -82,7 +83,8 @@ | ||
82 | 83 | %==============================================================================% |
83 | 84 | |
84 | 85 | :- import_module float. |
85 | -:- import_module vector.vector2. | |
86 | + | |
87 | +:- import_module mmath.vector.vector2. | |
86 | 88 | |
87 | 89 | %------------------------------------------------------------------------------% |
88 | 90 |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module geometry.triangle. | |
7 | +:- module mmath.geometry.triangle. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % Geometric operations related to a triangle. This is parametric on the vector |
@@ -12,7 +12,7 @@ | ||
12 | 12 | :- interface. |
13 | 13 | %==============================================================================% |
14 | 14 | |
15 | -:- import_module vector. | |
15 | +:- import_module mmath.vector. | |
16 | 16 | |
17 | 17 | %------------------------------------------------------------------------------% |
18 | 18 |
@@ -33,8 +33,8 @@ | ||
33 | 33 | |
34 | 34 | %------------------------------------------------------------------------------% |
35 | 35 | |
36 | -:- pragma type_spec(collinear/5, V = vector.vector2). | |
37 | -:- pragma type_spec(collinear/5, V = vector.vector3). | |
36 | +:- pragma type_spec(collinear/5, V = mmath.vector.vector2). | |
37 | +:- pragma type_spec(collinear/5, V = mmath.vector.vector3). | |
38 | 38 | |
39 | 39 | %==============================================================================% |
40 | 40 | :- implementation. |
@@ -1,21 +1,22 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module geometry2d. | |
7 | +:- module mmath.geometry2d. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | :- interface. |
11 | 11 | %==============================================================================% |
12 | 12 | |
13 | 13 | :- import_module list. |
14 | -:- import_module vector. | |
14 | + | |
15 | +:- import_module mmath.vector. | |
15 | 16 | |
16 | 17 | %------------------------------------------------------------------------------% |
17 | 18 | |
18 | -:- include_module geometry2d.rtree. | |
19 | +:- include_module mmath.geometry2d.rtree. | |
19 | 20 | |
20 | 21 | %------------------------------------------------------------------------------% |
21 | 22 |
@@ -224,10 +225,10 @@ | ||
224 | 225 | :- use_module math. |
225 | 226 | :- import_module float. |
226 | 227 | |
227 | -:- use_module geometry. | |
228 | -:- use_module geometry.segment. | |
229 | -:- use_module multi_math. | |
230 | -:- import_module vector.vector2. | |
228 | +:- use_module mmath.geometry. | |
229 | +:- use_module mmath.geometry.segment. | |
230 | +:- use_module mmath.multi_math. | |
231 | +:- import_module mmath.vector.vector2. | |
231 | 232 | |
232 | 233 | %------------------------------------------------------------------------------% |
233 | 234 |
@@ -284,8 +285,8 @@ rectangle_intersection(rectangle(X1, Y1, W1, H1), | ||
284 | 285 | rectangle(X2, Y2, W2, H2), |
285 | 286 | rectangle(Left + 0.0, Top + 0.0, OutW, OutH)) :- |
286 | 287 | |
287 | - multi_math.sub(Right, Left, OutW), | |
288 | - multi_math.sub(Bottom, Top, OutH), | |
288 | + mmath.multi_math.sub(Right, Left, OutW), | |
289 | + mmath.multi_math.sub(Bottom, Top, OutH), | |
289 | 290 | |
290 | 291 | % Logically required for an intersection to have occurred |
291 | 292 | Bottom >= Top, |
@@ -307,8 +308,8 @@ rectangle_union(rectangle(X1, Y1, W1, H1), | ||
307 | 308 | rectangle(X2, Y2, W2, H2), |
308 | 309 | rectangle(Left + 0.0, Top + 0.0, OutW, OutH)) :- |
309 | 310 | |
310 | - multi_math.sub(Right, Left, OutW), | |
311 | - multi_math.sub(Bottom, Top, OutH), | |
311 | + mmath.multi_math.sub(Right, Left, OutW), | |
312 | + mmath.multi_math.sub(Bottom, Top, OutH), | |
312 | 313 | |
313 | 314 | Left = min(X1, X2), |
314 | 315 | Top = min(Y1, Y2), |
@@ -388,8 +389,8 @@ collide_segments(S1, S2, Point) :- | ||
388 | 389 | S1 = segment(S1X1, S1Y1, S1X2, S1Y2), |
389 | 390 | S2 = segment(S2X1, S2Y1, S2X2, S2Y2), |
390 | 391 | |
391 | - Box1 = grow_rectangle(float.epsilon, geometry2d.bounding_box(S1)), | |
392 | - Box2 = grow_rectangle(float.epsilon, geometry2d.bounding_box(S2)), | |
392 | + Box1 = grow_rectangle(float.epsilon, mmath.geometry2d.bounding_box(S1)), | |
393 | + Box2 = grow_rectangle(float.epsilon, mmath.geometry2d.bounding_box(S2)), | |
393 | 394 | rectangle_intersection(Box1, Box2, IntersectedBox), |
394 | 395 | grow_rectangle(float.epsilon, IntersectedBox, GrownIntersectedBox), |
395 | 396 | point_inside(GrownIntersectedBox, Point), |
@@ -585,7 +586,7 @@ triangle_intersects_segments(Triangle, Segments, OutPoint) :- | ||
585 | 586 | |
586 | 587 | %------------------------------------------------------------------------------% |
587 | 588 | |
588 | -point_to_vector(geometry2d.point(X, Y)) = vector.vector2.vector(X, Y). | |
589 | +point_to_vector(geometry2d.point(X, Y)) = vector(X, Y). | |
589 | 590 | |
590 | 591 | %------------------------------------------------------------------------------% |
591 | 592 |
@@ -659,8 +660,8 @@ point_to_vector(geometry2d.point(X, Y)) = vector.vector2.vector(X, Y). | ||
659 | 660 | (bounding_box(point(X, Y)) = rectangle(X, Y, 0.0, 0.0)), |
660 | 661 | (point_inside(P, P)), |
661 | 662 | (translate(point(XT, YT), point(XIn, YIn), point(XOut, YOut)) :- |
662 | - multi_math.add(XT, XIn, XOut), | |
663 | - multi_math.add(YT, YIn, YOut)), | |
663 | + mmath.multi_math.add(XT, XIn, XOut), | |
664 | + mmath.multi_math.add(YT, YIn, YOut)), | |
664 | 665 | (convex(Point, 0.0, [Point|[]])), |
665 | 666 | scale(ScaleX, ScaleY, point(X, Y)) = point(ScaleX*X, ScaleY*Y) |
666 | 667 | ]. |
@@ -678,26 +679,26 @@ point_to_vector(geometry2d.point(X, Y)) = vector.vector2.vector(X, Y). | ||
678 | 679 | H = max(max(Y1, Y2), Y3) - Y), |
679 | 680 | (point_inside(triangle(X1, Y1, X2, Y2, X3, Y3), point(PX, PY)) :- |
680 | 681 | % Find the side of the point for each segment |
681 | - Pos = vector.vector2.vector(PX, PY), | |
682 | - Vector1 = vector.vector2.vector(X1, Y1), | |
683 | - Vector2 = vector.vector2.vector(X2, Y2), | |
684 | - Vector3 = vector.vector2.vector(X3, Y3), | |
685 | - Segment1 = geometry.segment.segment(Vector1, Vector2), | |
686 | - Segment2 = geometry.segment.segment(Vector2, Vector3), | |
687 | - Segment3 = geometry.segment.segment(Vector3, Vector1), | |
682 | + Pos = vector(PX, PY), | |
683 | + Vector1 = vector(X1, Y1), | |
684 | + Vector2 = vector(X2, Y2), | |
685 | + Vector3 = vector(X3, Y3), | |
686 | + Segment1 = mmath.geometry.segment.segment(Vector1, Vector2), | |
687 | + Segment2 = mmath.geometry.segment.segment(Vector2, Vector3), | |
688 | + Segment3 = mmath.geometry.segment.segment(Vector3, Vector1), | |
688 | 689 | |
689 | - Side1 = geometry.segment.side(Segment1, Pos), | |
690 | - Side2 = geometry.segment.side(Segment2, Pos), | |
691 | - Side3 = geometry.segment.side(Segment3, Pos), | |
690 | + Side1 = mmath.geometry.segment.side(Segment1, Pos), | |
691 | + Side2 = mmath.geometry.segment.side(Segment2, Pos), | |
692 | + Side3 = mmath.geometry.segment.side(Segment3, Pos), | |
692 | 693 | |
693 | 694 | % Either the point must be colinear, or we must be on the same side of |
694 | 695 | % all three segments. |
695 | 696 | ( |
696 | - Side1 = geometry.segment.colinear | |
697 | + Side1 = mmath.geometry.segment.colinear | |
697 | 698 | ; |
698 | - Side2 = geometry.segment.colinear | |
699 | + Side2 = mmath.geometry.segment.colinear | |
699 | 700 | ; |
700 | - Side3 = geometry.segment.colinear | |
701 | + Side3 = mmath.geometry.segment.colinear | |
701 | 702 | ; |
702 | 703 | Side1 = Side2, |
703 | 704 | Side2 = Side3 |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2018-2020 AlaskanEmily | |
1 | +% Copyright (C) 2018-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module geometry2d.rtree. | |
7 | +:- module mmath.geometry2d.rtree. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % Implements rtree typeclass for the geometry2d.rectangle type |
@@ -16,20 +16,20 @@ | ||
16 | 16 | |
17 | 17 | %------------------------------------------------------------------------------% |
18 | 18 | |
19 | -:- instance rtree.region(geometry2d.rectangle). | |
19 | +:- instance rtree.region(rectangle). | |
20 | 20 | |
21 | 21 | %------------------------------------------------------------------------------% |
22 | 22 | |
23 | -:- type geometry2d.rtree.rtree(T) == rtree.rtree(geometry2d.rectangle, T). | |
23 | +:- type geometry2d.rtree.rtree(T) == rtree.rtree(rectangle, T). | |
24 | 24 | |
25 | 25 | %------------------------------------------------------------------------------% |
26 | 26 | |
27 | -:- pred find(rtree.rtree(geometry2d.rectangle, T), geometry2d.point, T). | |
27 | +:- pred find(rtree.rtree(rectangle, T), point, T). | |
28 | 28 | :- mode find(in, in, out) is semidet. |
29 | 29 | |
30 | 30 | %------------------------------------------------------------------------------% |
31 | 31 | |
32 | -:- pred find_all(rtree.rtree(geometry2d.rectangle, T), geometry2d.point, list(T)). | |
32 | +:- pred find_all(rtree.rtree(rectangle, T), point, list(T)). | |
33 | 33 | :- mode find_all(in, in, out) is semidet. |
34 | 34 | |
35 | 35 | %==============================================================================% |
@@ -44,15 +44,15 @@ find(Tree, Point, Out) :- find_all(Tree, Point, [Out|_]). | ||
44 | 44 | |
45 | 45 | %------------------------------------------------------------------------------% |
46 | 46 | |
47 | -find_all(Tree, geometry2d.point(X, Y), | |
48 | - rtree.search_contains(Tree, geometry2d.rectangle(X, Y, 1.0, 1.0))). | |
47 | +find_all(Tree, point(X, Y), | |
48 | + rtree.search_contains(Tree, rectangle(X, Y, 1.0, 1.0))). | |
49 | 49 | |
50 | 50 | %------------------------------------------------------------------------------% |
51 | 51 | |
52 | 52 | :- instance rtree.region(rectangle) where [ |
53 | - (intersects(R1, R2) :- geometry2d.rectangles_intersect(R1, R2)), | |
54 | - rtree.bounding_region(R1, R2) = geometry2d.rectangle_union(R1, R2), | |
55 | - (contains(R1, R2) :- geometry2d.rectangle_contains(R1, R2)), | |
53 | + (intersects(R1, R2) :- rectangles_intersect(R1, R2)), | |
54 | + rtree.bounding_region(R1, R2) = rectangle_union(R1, R2), | |
55 | + (contains(R1, R2) :- rectangle_contains(R1, R2)), | |
56 | 56 | rtree.size(rectangle(_, _, W, H)) = (W * H), |
57 | 57 | (rtree.bounding_region_size( |
58 | 58 | rectangle(X1, Y1, W1, H1), |
@@ -12,17 +12,9 @@ | ||
12 | 12 | :- interface. |
13 | 13 | %==============================================================================% |
14 | 14 | |
15 | -% This exists to satisfy the 2019-10-16 rotd, which had a bug/unintended-feature | |
16 | -% that prevented a module that only did imports from working. | |
17 | -:- pred dummy(T::in) is semidet. | |
15 | +:- include_module mmath.vector. | |
16 | +:- include_module mmath.geometry. | |
17 | +:- include_module mmath.matrix. | |
18 | +:- include_module mmath.geometry2d. | |
19 | +:- include_module mmath.multi_math. | |
18 | 20 | |
19 | -:- implementation. | |
20 | - | |
21 | -:- import_module vector. | |
22 | -:- import_module geometry. | |
23 | -:- import_module matrix. | |
24 | -:- import_module geometry2d. | |
25 | -:- import_module multi_math. | |
26 | - | |
27 | -:- pragma no_inline(dummy/1). | |
28 | -dummy(_). |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module matrix.invert. | |
7 | +:- module mmath.matrix.invert. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % Inversion operations on matrices. |
@@ -21,8 +21,8 @@ | ||
21 | 21 | :- implementation. |
22 | 22 | %==============================================================================% |
23 | 23 | |
24 | -:- import_module vector. | |
25 | -:- import_module vector.vector4. | |
24 | +:- import_module mmath.vector. | |
25 | +:- import_module mmath.vector.vector4. | |
26 | 26 | |
27 | 27 | % Input |
28 | 28 | % 0-A 1-B 2-C 3-D |
@@ -39,7 +39,7 @@ | ||
39 | 39 | invert(In) = matrix(OutA * Det, OutB * Det, OutC * Det, OutD * Det) :- |
40 | 40 | |
41 | 41 | % Compute the determinant. |
42 | - Det = (1.0 / vector.dot(column_a(In), OutA)), | |
42 | + Det = (1.0 / dot(column_a(In), OutA)), | |
43 | 43 | |
44 | 44 | % Calculate the cofactors for the first two rows |
45 | 45 | A = (In ^ c ^ z) * (In ^ d ^ w), % 0 |
@@ -56,7 +56,7 @@ invert(In) = matrix(OutA * Det, OutB * Det, OutC * Det, OutD * Det) :- | ||
56 | 56 | L = (In ^ b ^ z) * (In ^ a ^ w), % 11 |
57 | 57 | |
58 | 58 | % Calculate the first two rows using the cofactors. |
59 | - OutA = vector.vector4.vector( | |
59 | + OutA = mmath.vector.vector4.vector( | |
60 | 60 | (A * In ^ b ^ y) + (D * In ^ c ^ y) + (E * In ^ d ^ y) |
61 | 61 | -((B * In ^ b ^ y) + (C * In ^ c ^ y) + (F * In ^ d ^ y)), |
62 | 62 | (B * In ^ a ^ y) + (G * In ^ c ^ y) + (J * In ^ d ^ y) |
@@ -66,7 +66,7 @@ invert(In) = matrix(OutA * Det, OutB * Det, OutC * Det, OutD * Det) :- | ||
66 | 66 | (F * In ^ a ^ y) + (I * In ^ b ^ y) + (L * In ^ c ^ y) |
67 | 67 | -((E * In ^ a ^ y) + (J * In ^ b ^ y) + (K * In ^ c ^ y))), |
68 | 68 | |
69 | - OutB = vector.vector4.vector( | |
69 | + OutB = mmath.vector.vector4.vector( | |
70 | 70 | (B * In ^ b ^ x) + (C * In ^ c ^ x) + (F * In ^ d ^ x) |
71 | 71 | -((A * In ^ b ^ x) + (D * In ^ c ^ x) + (E * In ^ d ^ x)), |
72 | 72 | (A * In ^ a ^ x) + (H * In ^ c ^ x) + (I * In ^ d ^ x) |
@@ -90,7 +90,7 @@ invert(In) = matrix(OutA * Det, OutB * Det, OutC * Det, OutD * Det) :- | ||
90 | 90 | W = (In ^ a ^ x) * (In ^ b ^ y), % 10 |
91 | 91 | X = (In ^ b ^ x) * (In ^ a ^ y), % 11 |
92 | 92 | |
93 | - OutC = vector.vector4.vector( | |
93 | + OutC = mmath.vector.vector4.vector( | |
94 | 94 | (M * In ^ b ^ w) + (P * In ^ c ^ w) + (Q * In ^ d ^ w) |
95 | 95 | -((N * In ^ b ^ w) + (O * In ^ c ^ w) + (R * In ^ d ^ w)), |
96 | 96 | (N * In ^ a ^ w) + (S * In ^ c ^ w) + (V * In ^ d ^ w) |
@@ -100,7 +100,7 @@ invert(In) = matrix(OutA * Det, OutB * Det, OutC * Det, OutD * Det) :- | ||
100 | 100 | (R * In ^ a ^ w) + (U * In ^ b ^ w) + (X * In ^ c ^ w) |
101 | 101 | -((Q * In ^ a ^ w) + (V * In ^ b ^ w) + (W * In ^ c ^ w))), |
102 | 102 | |
103 | - OutD = vector.vector4.vector( | |
103 | + OutD = mmath.vector.vector4.vector( | |
104 | 104 | (N * In ^ b ^ z) + (O * In ^ c ^ z) + (R * In ^ d ^ z) |
105 | 105 | -((M * In ^ b ^ z) + (P * In ^ c ^ z) + (Q * In ^ d ^ z)), |
106 | 106 | (M * In ^ a ^ z) + (T * In ^ c ^ z) + (U * In ^ d ^ z) |
@@ -1,27 +1,27 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module matrix. | |
7 | +:- module mmath.matrix. | |
8 | 8 | |
9 | 9 | %=============================================================================% |
10 | 10 | :- interface. |
11 | 11 | %=============================================================================% |
12 | 12 | |
13 | -:- use_module vector. | |
13 | +:- use_module mmath.vector. | |
14 | 14 | |
15 | -:- include_module matrix.invert. | |
16 | -:- use_module matrix.invert. | |
15 | +:- include_module mmath.matrix.invert. | |
16 | +:- use_module mmath.matrix.invert. | |
17 | 17 | |
18 | 18 | %-----------------------------------------------------------------------------% |
19 | 19 | |
20 | 20 | :- type matrix ---> matrix( |
21 | - a::vector.vector4, | |
22 | - b::vector.vector4, | |
23 | - c::vector.vector4, | |
24 | - d::vector.vector4). | |
21 | + a::mmath.vector.vector4, | |
22 | + b::mmath.vector.vector4, | |
23 | + c::mmath.vector.vector4, | |
24 | + d::mmath.vector.vector4). | |
25 | 25 | |
26 | 26 | %-----------------------------------------------------------------------------% |
27 | 27 | % frustum(Left, Right, Top, Bottom, Near, Far) = Frustum. |
@@ -34,23 +34,39 @@ | ||
34 | 34 | %-----------------------------------------------------------------------------% |
35 | 35 | |
36 | 36 | :- func translate(float, float, float) = matrix. |
37 | +:- mode translate(in, in, in) = (out) is det. | |
38 | +:- mode translate(di, di, di) = (uo) is det. | |
39 | +:- mode translate(mdi, mdi, mdi) = (muo) is det. | |
37 | 40 | |
38 | 41 | %-----------------------------------------------------------------------------% |
39 | 42 | |
40 | -:- func translate(vector.vector3) = matrix. | |
43 | +:- func translate(mmath.vector.vector3) = matrix. | |
44 | +:- mode translate(in) = (out) is det. | |
45 | +:- mode translate(di) = (uo) is det. | |
46 | +:- mode translate(mdi) = (muo) is det. | |
41 | 47 | |
42 | 48 | %-----------------------------------------------------------------------------% |
43 | 49 | |
44 | 50 | :- func scale(float, float, float) = matrix. |
51 | +:- mode scale(in, in, in) = (out) is det. | |
52 | +:- mode scale(di, di, di) = (uo) is det. | |
53 | +:- mode scale(mdi, mdi, mdi) = (muo) is det. | |
45 | 54 | |
46 | 55 | %-----------------------------------------------------------------------------% |
47 | 56 | |
48 | -:- func scale(vector.vector3) = matrix. | |
57 | +:- func scale(mmath.vector.vector3) = matrix. | |
58 | +:- mode scale(in) = (out) is det. | |
59 | +:- mode scale(di) = (uo) is det. | |
60 | +:- mode scale(mdi) = (muo) is det. | |
49 | 61 | |
50 | 62 | %-----------------------------------------------------------------------------% |
51 | 63 | |
52 | -:- func rotate(float::in, vector.vector3::in) = (matrix::uo) is det. | |
53 | -:- func rotate_old(float::in, vector.vector3::in) = (matrix::uo) is det. | |
64 | +:- func rotate(float, mmath.vector.vector3) = matrix. | |
65 | +:- mode rotate(in, in) = (uo) is det. | |
66 | +:- mode rotate(di, di) = (uo) is det. | |
67 | +:- mode rotate(mdi, mdi) = (muo) is det. | |
68 | + | |
69 | +:- func rotate_old(float::in, mmath.vector.vector3::in) = (matrix::uo) is det. | |
54 | 70 | |
55 | 71 | %-----------------------------------------------------------------------------% |
56 | 72 |
@@ -59,6 +75,9 @@ | ||
59 | 75 | %-----------------------------------------------------------------------------% |
60 | 76 | |
61 | 77 | :- func transpose(matrix) = matrix. |
78 | +:- mode transpose(in) = (out) is det. | |
79 | +:- mode transpose(di) = (uo) is det. | |
80 | +:- mode transpose(mdi) = (muo) is det. | |
62 | 81 | |
63 | 82 | %-----------------------------------------------------------------------------% |
64 | 83 |
@@ -73,11 +92,11 @@ | ||
73 | 92 | |
74 | 93 | %-----------------------------------------------------------------------------% |
75 | 94 | |
76 | -:- func (matrix::in) * (vector.vector4::in) = (vector.vector4::uo) is det. | |
95 | +:- func (matrix::in) * (mmath.vector.vector4::in) = (mmath.vector.vector4::uo) is det. | |
77 | 96 | |
78 | 97 | %-----------------------------------------------------------------------------% |
79 | 98 | |
80 | -:- func transform(matrix::in, vector.vector4::in) = (vector.vector4::uo) is det. | |
99 | +:- func transform(matrix::in, mmath.vector.vector4::in) = (mmath.vector.vector4::uo) is det. | |
81 | 100 | |
82 | 101 | %-----------------------------------------------------------------------------% |
83 | 102 |
@@ -103,10 +122,10 @@ | ||
103 | 122 | |
104 | 123 | %-----------------------------------------------------------------------------% |
105 | 124 | |
106 | -:- func column_a(matrix::in) = (vector.vector4::uo) is det. | |
107 | -:- func column_b(matrix::in) = (vector.vector4::uo) is det. | |
108 | -:- func column_c(matrix::in) = (vector.vector4::uo) is det. | |
109 | -:- func column_d(matrix::in) = (vector.vector4::uo) is det. | |
125 | +:- func column_a(matrix::in) = (mmath.vector.vector4::uo) is det. | |
126 | +:- func column_b(matrix::in) = (mmath.vector.vector4::uo) is det. | |
127 | +:- func column_c(matrix::in) = (mmath.vector.vector4::uo) is det. | |
128 | +:- func column_d(matrix::in) = (mmath.vector.vector4::uo) is det. | |
110 | 129 | |
111 | 130 | %-----------------------------------------------------------------------------% |
112 | 131 |
@@ -131,8 +150,8 @@ | ||
131 | 150 | :- import_module int. |
132 | 151 | :- use_module math. |
133 | 152 | |
134 | -:- import_module vector.vector3. | |
135 | -:- import_module vector.vector4. | |
153 | +:- import_module mmath.vector.vector3. | |
154 | +:- import_module mmath.vector.vector4. | |
136 | 155 | |
137 | 156 | %-----------------------------------------------------------------------------% |
138 | 157 |
@@ -192,7 +211,7 @@ rotate(A, Vec) = matrix( | ||
192 | 211 | vector(Y*X*(1.0-C)+Z*S, Y*Y*(1.0-C)+C, Y*Z*(1.0-C)-X*S, 0.0), |
193 | 212 | vector(Z*X*(1.0-C)-Y*S, Z*Y*(1.0-C)+X*S, Z*Z*(1.0-C)+C, 0.0), |
194 | 213 | vector(0.0, 0.0, 0.0, 1.0)) :- |
195 | - vector(X, Y, Z) = vector.normalize(Vec), | |
214 | + vector(X, Y, Z) = mmath.vector.normalize(Vec), | |
196 | 215 | S = math.sin(A), |
197 | 216 | C = math.cos(A). |
198 | 217 |
@@ -207,7 +226,7 @@ identity = matrix( | ||
207 | 226 | %-----------------------------------------------------------------------------% |
208 | 227 | |
209 | 228 | (matrix(V1, V2, V3, V4)) * (V) = |
210 | - vector(vector.dot(V, V1), vector.dot(V, V2), vector.dot(V, V3), vector.dot(V, V4)). | |
229 | + vector(mmath.vector.dot(V, V1), mmath.vector.dot(V, V2), mmath.vector.dot(V, V3), mmath.vector.dot(V, V4)). | |
211 | 230 | |
212 | 231 | %-----------------------------------------------------------------------------% |
213 | 232 |
@@ -234,10 +253,10 @@ transpose( | ||
234 | 253 | %-----------------------------------------------------------------------------% |
235 | 254 | |
236 | 255 | multiply(matrix(A, B, C, D), matrix(AIn, BIn, CIn, DIn)) = matrix( |
237 | - vector(vector.dot(A, E), vector.dot(A, F), vector.dot(A, G), vector.dot(A, H)), | |
238 | - vector(vector.dot(B, E), vector.dot(B, F), vector.dot(B, G), vector.dot(B, H)), | |
239 | - vector(vector.dot(C, E), vector.dot(C, F), vector.dot(C, G), vector.dot(C, H)), | |
240 | - vector(vector.dot(D, E), vector.dot(D, F), vector.dot(D, G), vector.dot(D, H))) :- | |
256 | + vector(mmath.vector.dot(A, E), mmath.vector.dot(A, F), mmath.vector.dot(A, G), mmath.vector.dot(A, H)), | |
257 | + vector(mmath.vector.dot(B, E), mmath.vector.dot(B, F), mmath.vector.dot(B, G), mmath.vector.dot(B, H)), | |
258 | + vector(mmath.vector.dot(C, E), mmath.vector.dot(C, F), mmath.vector.dot(C, G), mmath.vector.dot(C, H)), | |
259 | + vector(mmath.vector.dot(D, E), mmath.vector.dot(D, F), mmath.vector.dot(D, G), mmath.vector.dot(D, H))) :- | |
241 | 260 | E = vector(AIn ^ x, BIn ^ x, CIn ^ x, DIn ^ x), |
242 | 261 | F = vector(AIn ^ y, BIn ^ y, CIn ^ y, DIn ^ y), |
243 | 262 | G = vector(AIn ^ z, BIn ^ z, CIn ^ z, DIn ^ z), |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2018-2020 AlaskanEmily | |
1 | +% Copyright (C) 2018-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module multi_math. | |
7 | +:- module mmath.multi_math. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | :- interface. |
@@ -1,28 +1,28 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module vector. | |
7 | +:- module mmath.vector. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | :- interface. |
11 | 11 | %==============================================================================% |
12 | 12 | |
13 | -:- include_module vector.vector2. | |
14 | -:- include_module vector.vector3. | |
15 | -:- include_module vector.vector4. | |
13 | +:- include_module mmath.vector.vector2. | |
14 | +:- include_module mmath.vector.vector3. | |
15 | +:- include_module mmath.vector.vector4. | |
16 | 16 | |
17 | -:- use_module vector.vector2. | |
18 | -:- use_module vector.vector3. | |
19 | -:- use_module vector.vector4. | |
17 | +:- use_module mmath.vector.vector2. | |
18 | +:- use_module mmath.vector.vector3. | |
19 | +:- use_module mmath.vector.vector4. | |
20 | 20 | |
21 | 21 | %------------------------------------------------------------------------------% |
22 | 22 | |
23 | -:- type vector2 == vector.vector2.vector. | |
24 | -:- type vector3 == vector.vector3.vector. | |
25 | -:- type vector4 == vector.vector4.vector. | |
23 | +:- type vector2 == mmath.vector.vector2.vector. | |
24 | +:- type vector3 == mmath.vector.vector3.vector. | |
25 | +:- type vector4 == mmath.vector.vector4.vector. | |
26 | 26 | |
27 | 27 | %------------------------------------------------------------------------------% |
28 | 28 |
@@ -4,20 +4,18 @@ | ||
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module vector.vector2. | |
7 | +:- module mmath.vector.vector2. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % 2D vector implementation. |
11 | 11 | :- interface. |
12 | 12 | %==============================================================================% |
13 | 13 | |
14 | -:- use_module vector. | |
15 | - | |
16 | 14 | :- type vector ---> vector(x::float, y::float). |
17 | 15 | |
18 | 16 | %------------------------------------------------------------------------------% |
19 | 17 | |
20 | -:- instance vector.vector(vector2). | |
18 | +:- instance vector(vector2). | |
21 | 19 | |
22 | 20 | %------------------------------------------------------------------------------% |
23 | 21 |
@@ -132,7 +130,7 @@ cross(vector(X1, Y1), vector(X2, Y2)) = (X1 * Y2) - (Y1 * X2). | ||
132 | 130 | |
133 | 131 | %------------------------------------------------------------------------------% |
134 | 132 | |
135 | -:- instance vector.vector(vector2) where [ | |
133 | +:- instance vector(vector2) where [ | |
136 | 134 | magnitude_squared(vector(X, Y)) = ((X*X) + (Y*Y)), |
137 | 135 | scale(vector(X, Y), S) = vector(X*S, Y*S), |
138 | 136 | multiply(vector(X1, Y1), vector(X2, Y2)) = vector(X1*X2, Y1*Y2), |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module vector.vector3. | |
7 | +:- module mmath.vector.vector3. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % 3D vector implementation. |
@@ -1,10 +1,10 @@ | ||
1 | -% Copyright (C) 2017-2020 AlaskanEmily | |
1 | +% Copyright (C) 2017-2022 AlaskanEmily | |
2 | 2 | % |
3 | 3 | % This Source Code Form is subject to the terms of the Mozilla Public |
4 | 4 | % License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | % file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | |
7 | -:- module vector.vector4. | |
7 | +:- module mmath.vector.vector4. | |
8 | 8 | |
9 | 9 | %==============================================================================% |
10 | 10 | % 4D vector implementation. |