-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngineConfiguration.m
More file actions
54 lines (51 loc) · 1.96 KB
/
EngineConfiguration.m
File metadata and controls
54 lines (51 loc) · 1.96 KB
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
classdef EngineConfiguration
properties
engine_type
piston_layout
n_pistons
piston_angles
crank_offsets
counterweight_offsets
counterweight_scale
end
methods
function obj = EngineConfiguration(engine_type,piston_layout,n_pistons,piston_angles,crank_offsets,counterweight_offsets,counterweight_scale,output_path)
arguments
engine_type {mustBeNonzeroLengthText}
piston_layout {mustBeMember(piston_layout,['i','f','v','r'])}
n_pistons {mustBeInteger, mustBeGreaterThan(n_pistons,0)}
piston_angles {mustBeRow, mustBeReal, mustEqualNumPistons(piston_angles,n_pistons)}
crank_offsets {mustBeRow, mustBeReal, mustEqualNumPistons(crank_offsets,n_pistons)}
counterweight_offsets {mustBeRow, mustBeReal, mustEqualNumPistons(counterweight_offsets,n_pistons)}
counterweight_scale {mustBeReal, mustBeInRange(counterweight_scale,0,1)}
output_path {mustBeNonzeroLengthText} = "Engines\"
end
obj.engine_type = engine_type;
obj.piston_layout = piston_layout;
obj.n_pistons = n_pistons;
obj.piston_angles = piston_angles;
obj.crank_offsets = crank_offsets;
obj.counterweight_offsets = counterweight_offsets;
obj.counterweight_scale = counterweight_scale;
makeOutputDir(obj,output_path);
end
end
end
%% Custom Validation Functions
% Validate length of input vectors
function mustEqualNumPistons(v,n)
if ~isequal(length(v),n)
msg = "Length must equal number of pistons";
error(msg)
end
end
% Validate output directoy exists or was successfully created
function makeOutputDir(obj,output_path)
success = isfolder(output_path + obj.engine_type);
if ~success
success = mkdir(output_path + obj.engine_type);
end
if ~success
error("Failed to make output directory")
end
end