1 /*skeleton.d by Ruby The Roobster*/
2 /*Version 1.0 Release*/
3 /*Module for representing skeletons in the D Programming Language 2.0*/
4 /*This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
16 /** Copyright: 2021, Ruby The Roobster*/
17 /**Author: Ruby The Roobster, michaeleverestc79@gmail.com*/
18 /**Date: October 1, 2021*/
19 /** License:  GPL-3.0*/
20 module dutils.skeleton;
21 /**Struct for representing a point.*/
22 public struct Point	{ //Point structure...
23 	///Point.x is the 'x' coordinate of the point.
24 	real x;
25 	///Point.y is the 'y' coordinate of the point.
26 	real y;
27 	///Point.z is the 'z' coordinate of the point.
28 	real z;
29 	this(real x, real y, real z)	{
30 		this.x = x;
31 		this.y = y;
32 		this.z = z;
33 	}
34 	void opAssign(Point rhs)	{
35 		this.x = rhs.x;
36 		this.y = rhs.y;
37 		this.z = rhs.z;
38 	}
39 	void opOpAssign(string op)(Point rhs)	{
40 		mixin("this.x " ~ op ~ "= rhs.x;");
41 		mixin("this.y " ~ op ~ "= rhs.y;");
42 		mixin("this.z " ~ op ~ "= rhs.z;");
43 	}
44 }
45 /**Struct for representing a face of a skeleton that is made out of lines.*/
46 public struct Face	{ //Face(of a 3D shape) structure...
47 	///Face.lines is an array of all the lines that connect to form the face.
48 	Line[] lines;
49 	///Face.center is the center point of the face.
50 	Point center;
51 	void opAssign(Face rhs)	{
52 		this.lines.length = rhs.lines.length;
53 		foreach(i;0 .. this.lines.length)	{
54 			this.lines[i] = rhs.lines[i];
55 		}
56 	}
57 }
58 /**Struct for representing a 3D skeleton.*/
59 public struct Skeleton	{ //Skeleton of a 3D structure...
60 	///Skeleton.faces is an array of the faces that make up the Skeleton.
61 	Face[] faces;
62 	///Skeleton.center is the center point of the skeleton.
63 	Point center;
64 	void opAssign(Skeleton rhs)	{
65 		this.faces.length = rhs.faces.length;
66 		foreach(i;0 .. this.faces.length)	{
67 			this.faces[i] = rhs.faces[i];
68 		}
69 		this.center = rhs.center;
70 	}
71 }
72 
73 /**Struct for representing a line composed of at least a starting point and an end point.
74   *Notes:
75   *This struct doesn't check to make sure that the line made is an actual line and assumes the user knows what they are doing.
76 */
77 public struct Line	{ //Line struct...
78 	///Line.mid_points is an array containing all of the points that are neither start nor end points.
79 	Point[] mid_points;
80 	///Line.start is the start point of the line.
81 	Point start;
82 	///Line.end is the end point of the line.
83 	Point stop;
84 	void opAssign(Line rhs)	{
85 		this.start = rhs.start;
86 		this.stop = rhs.stop;
87 		this.mid_points.length = rhs.mid_points.length;
88 		foreach(i;0 .. this.mid_points.length)	{
89 			this.mid_points[i] = rhs.mid_points[i];
90 		}
91 	}
92 }