Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
cassiopee
jalhyd
Commits
ad8ee303
Commit
ad8ee303
authored
Oct 30, 2019
by
Mathias Chouet
🍝
Browse files
#161
- add module Trigo
parent
1323023a
Changes
7
Hide whitespace changes
Inline
Side-by-side
spec/fuzzing.spec.ts
View file @
ad8ee303
...
...
@@ -9,6 +9,7 @@ import { Props } from "../src/props";
import
{
SectionNub
}
from
"
../src/section/section_nub
"
;
import
{
CreateStructure
}
from
"
../src/structure/factory_structure
"
;
import
{
ParallelStructure
}
from
"
../src/structure/parallel_structure
"
;
import
{
Trigo
}
from
"
../src/trigo
"
;
import
{
checkResultConsistency
,
SetJasmineCurrentSpec
}
from
"
./test_func
"
;
/**
...
...
@@ -100,6 +101,16 @@ function setRandomSection(sn: SectionNub) {
sn
.
setSection
(
newSect
);
}
function
setRandomOperation
(
sn
:
Trigo
)
{
const
op
=
Math
.
floor
(
Math
.
random
()
*
6
);
sn
.
operation
=
op
;
}
function
setRandomTrigoUnit
(
sn
:
Trigo
)
{
const
un
=
Math
.
floor
(
Math
.
random
()
*
2
);
sn
.
unit
=
un
;
}
function
setPab
(
pab
:
Pab
,
nClMax
=
30
,
nStMax
=
3
)
{
const
nCl
=
Math
.
floor
(
Math
.
random
()
*
nClMax
)
+
1
;
for
(
let
i
=
0
;
i
<
nCl
;
i
++
)
{
...
...
@@ -149,6 +160,10 @@ function CreateTestNub(iCalType: number): Nub {
if
(
iCalType
===
CalculatorType
.
Bief
)
{
setRandomSection
(
n
as
SectionNub
);
}
if
(
iCalType
===
CalculatorType
.
Trigo
)
{
setRandomOperation
(
n
as
Trigo
);
setRandomTrigoUnit
(
n
as
Trigo
);
}
for
(
const
p
of
n
.
parameterIterator
)
{
if
(
p
.
visible
)
{
randomizeParameter
(
p
);
...
...
spec/trigo.spec.ts
0 → 100644
View file @
ad8ee303
import
{
Session
}
from
"
../src/session
"
;
import
{
CreateStructure
}
from
"
../src/structure/factory_structure
"
;
import
{
ParallelStructure
}
from
"
../src/structure/parallel_structure
"
;
import
{
ParallelStructureParams
}
from
"
../src/structure/parallel_structure_params
"
;
import
{
LoiDebit
}
from
"
../src/structure/structure_props
"
;
import
{
Trigo
,
TrigoOperation
,
TrigoUnit
}
from
"
../src/trigo
"
;
import
{
TrigoParams
}
from
"
../src/trigo_params
"
;
describe
(
"
Class Trigo:
"
,
()
=>
{
describe
(
"
Calc Y with degrees:
"
,
()
=>
{
it
(
"
Y = cos(X) should be 0.985
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
DEG
;
nub
.
operation
=
TrigoOperation
.
COS
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.985
,
3
);
});
it
(
"
Y = sin(X) should be 0.174
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
DEG
;
nub
.
operation
=
TrigoOperation
.
SIN
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.174
,
3
);
});
it
(
"
Y = tan(X) should be 0.176
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
DEG
;
nub
.
operation
=
TrigoOperation
.
TAN
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.176
,
3
);
});
it
(
"
Y = cosh(X) should be 1.015
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
DEG
;
nub
.
operation
=
TrigoOperation
.
COSH
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
1.015
,
3
);
});
it
(
"
Y = sinh(X) should be 0.175
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
DEG
;
nub
.
operation
=
TrigoOperation
.
SINH
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.175
,
3
);
});
it
(
"
Y = tanh(X) should be 0.173
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
DEG
;
nub
.
operation
=
TrigoOperation
.
TANH
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.173
,
3
);
});
});
describe
(
"
Calc Y with radians:
"
,
()
=>
{
it
(
"
Y = cos(X) should be 0.540
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
1
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
RAD
;
nub
.
operation
=
TrigoOperation
.
COS
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.540
,
3
);
});
it
(
"
Y = sin(X) should be 0.841
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
1
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
RAD
;
nub
.
operation
=
TrigoOperation
.
SIN
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.841
,
3
);
});
it
(
"
Y = tan(X) should be 1.557
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
1
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
RAD
;
nub
.
operation
=
TrigoOperation
.
TAN
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
1.557
,
3
);
});
it
(
"
Y = cosh(X) should be 1.543
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
1
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
RAD
;
nub
.
operation
=
TrigoOperation
.
COSH
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
1.543
,
3
);
});
it
(
"
Y = sinh(X) should be 1.175
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
1
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
RAD
;
nub
.
operation
=
TrigoOperation
.
SINH
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
1.175
,
3
);
});
it
(
"
Y = tanh(X) should be 0.762
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
1.5
,
1
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
TrigoUnit
.
RAD
;
nub
.
operation
=
TrigoOperation
.
TANH
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
0.762
,
3
);
});
});
describe
(
"
Calc X:
"
,
()
=>
{
for
(
const
un
of
[
TrigoUnit
.
DEG
,
TrigoUnit
.
RAD
])
{
for
(
const
op
of
[
TrigoOperation
.
COS
,
TrigoOperation
.
SIN
,
TrigoOperation
.
TAN
,
TrigoOperation
.
COSH
,
TrigoOperation
.
SINH
,
TrigoOperation
.
TANH
])
{
it
(
"
X = acos(Y = cos(X)) should be X
"
,
()
=>
{
const
nub
=
new
Trigo
(
new
TrigoParams
(
0
,
1.5
));
nub
.
calculatedParam
=
nub
.
prms
.
Y
;
nub
.
unit
=
un
;
nub
.
operation
=
op
;
nub
.
CalcSerie
();
nub
.
prms
.
Y
.
singleValue
=
nub
.
result
.
vCalc
;
nub
.
prms
.
X
.
singleValue
=
666
;
nub
.
calculatedParam
=
nub
.
prms
.
X
;
nub
.
CalcSerie
();
expect
(
nub
.
result
.
vCalc
).
toBeCloseTo
(
1.5
,
5
);
});
}
}
});
describe
(
"
Link:
"
,
()
=>
{
it
(
"
all parameters must be linkable to Y and X in both ways
"
,
()
=>
{
const
trig
=
new
Trigo
(
new
TrigoParams
(
1.5
,
10
));
const
lo
=
new
ParallelStructure
(
new
ParallelStructureParams
(
1.2
,
102
,
101
));
lo
.
addChild
(
CreateStructure
(
LoiDebit
.
GateCem88d
,
lo
));
Session
.
getInstance
().
clear
();
Session
.
getInstance
().
registerNubs
([
trig
,
lo
]);
// each YAXB param should be linkable to all ParallelStructures params
expect
(
Session
.
getInstance
().
getLinkableValues
(
trig
.
prms
.
Y
).
length
).
toBe
(
7
);
expect
(
Session
.
getInstance
().
getLinkableValues
(
trig
.
prms
.
X
).
length
).
toBe
(
7
);
// each ParallelStructures param should be linkable to all YAXB params
for
(
const
p
of
lo
.
parameterIterator
)
{
expect
(
Session
.
getInstance
().
getLinkableValues
(
p
).
length
).
toBe
(
2
);
}
});
});
});
src/compute-node.ts
View file @
ad8ee303
...
...
@@ -31,7 +31,8 @@ export enum CalculatorType {
Pente
,
Bief
,
Solveur
,
// Nub qui résout des chaînes de Nubs par dichotomie
YAXB
// Y = A.X + B
YAXB
,
// Y = A.X + B
Trigo
}
/**
...
...
src/devalaison/grille.ts
View file @
ad8ee303
...
...
@@ -3,6 +3,7 @@ import { Nub } from "../nub";
import
{
ParamCalculability
}
from
"
../param/param-definition
"
;
import
{
Interval
}
from
"
../util/interval
"
;
import
{
Message
,
MessageCode
}
from
"
../util/message
"
;
import
{
Observer
}
from
"
../util/observer
"
;
import
{
Result
}
from
"
../util/result
"
;
import
{
GrilleParams
}
from
"
./grille_params
"
;
...
...
@@ -17,7 +18,7 @@ export enum GrilleType {
Inclined
}
export
class
Grille
extends
Nub
{
export
class
Grille
extends
Nub
implements
Observer
{
constructor
(
prms
:
GrilleParams
,
dbg
:
boolean
=
false
)
{
super
(
prms
,
dbg
);
...
...
src/session.ts
View file @
ad8ee303
...
...
@@ -22,6 +22,8 @@ import { CourbeRemous } from "./remous/remous";
import
{
SectionParametree
}
from
"
./section/section_parametree
"
;
import
{
Solveur
}
from
"
./solveur/solveur
"
;
import
{
SolveurParams
}
from
"
./solveur/solveur_params
"
;
import
{
Trigo
,
TrigoOperation
}
from
"
./trigo
"
;
import
{
TrigoParams
}
from
"
./trigo_params
"
;
import
{
YAXB
}
from
"
./yaxb
"
;
import
{
YAXBParams
}
from
"
./yaxb_params
"
;
...
...
@@ -580,7 +582,6 @@ export class Session {
break
;
case
CalculatorType
.
Solveur
:
// const nubToCalc: BiefRegime = params.getPropValue("nubToCalculate");
nub
=
new
Solveur
(
new
SolveurParams
(
undefined
)
);
...
...
@@ -598,6 +599,17 @@ export class Session {
);
break
;
case
CalculatorType
.
Trigo
:
const
trigoOp
:
TrigoOperation
=
params
.
getPropValue
(
"
trigoOperation
"
);
nub
=
new
Trigo
(
new
TrigoParams
(
0.985
,
// Y
10
// X
),
dbg
);
break
;
default
:
throw
new
Error
(
`Session.createNub() : type de module '
${
CalculatorType
[
calcType
]}
' non pris en charge`
...
...
src/trigo.ts
0 → 100644
View file @
ad8ee303
import
{
CalculatorType
}
from
"
./compute-node
"
;
import
{
Nub
}
from
"
./nub
"
;
import
{
ParamCalculability
}
from
"
./param/param-definition
"
;
import
{
TrigoParams
}
from
"
./trigo_params
"
;
import
{
Interval
}
from
"
./util/interval
"
;
import
{
Observer
}
from
"
./util/observer
"
;
import
{
Result
}
from
"
./util/result
"
;
import
{
ParamDomain
,
ParamDomainValue
}
from
"
./param/param-domain
"
;
export
enum
TrigoOperation
{
COS
,
SIN
,
TAN
,
COSH
,
SINH
,
TANH
}
export
enum
TrigoUnit
{
DEG
,
// Degrees
RAD
// Radians
}
/**
* cos, sin, tan, cosh, sinh, tanh
*/
export
class
Trigo
extends
Nub
implements
Observer
{
constructor
(
prms
:
TrigoParams
,
dbg
:
boolean
=
false
)
{
super
(
prms
,
dbg
);
this
.
_calcType
=
CalculatorType
.
Trigo
;
this
.
_defaultCalculatedParam
=
prms
.
Y
;
this
.
resetDefaultCalculatedParam
();
this
.
properties
.
addObserver
(
this
);
this
.
properties
.
setPropValue
(
"
trigoOperation
"
,
TrigoOperation
.
COS
);
this
.
properties
.
setPropValue
(
"
trigoUnit
"
,
TrigoUnit
.
DEG
);
}
/** paramètres castés au bon type */
get
prms
():
TrigoParams
{
return
this
.
_prms
as
TrigoParams
;
}
public
get
operation
():
TrigoOperation
{
return
this
.
properties
.
getPropValue
(
"
trigoOperation
"
);
}
public
set
operation
(
o
:
TrigoOperation
)
{
this
.
properties
.
setPropValue
(
"
trigoOperation
"
,
o
);
}
public
get
unit
():
TrigoUnit
{
return
this
.
properties
.
getPropValue
(
"
trigoUnit
"
);
}
public
set
unit
(
u
:
TrigoUnit
)
{
this
.
properties
.
setPropValue
(
"
trigoUnit
"
,
u
);
}
public
Equation
(
sVarCalc
:
string
):
Result
{
let
v
:
number
;
switch
(
sVarCalc
)
{
case
"
Y
"
:
let
xv
=
this
.
prms
.
X
.
v
;
if
(
this
.
unit
===
TrigoUnit
.
DEG
)
{
xv
=
xv
*
Math
.
PI
/
180
;
}
switch
(
this
.
operation
)
{
case
TrigoOperation
.
COS
:
v
=
Math
.
cos
(
xv
);
break
;
case
TrigoOperation
.
SIN
:
v
=
Math
.
sin
(
xv
);
break
;
case
TrigoOperation
.
TAN
:
v
=
Math
.
tan
(
xv
);
break
;
case
TrigoOperation
.
COSH
:
v
=
Math
.
cosh
(
xv
);
break
;
case
TrigoOperation
.
SINH
:
v
=
Math
.
sinh
(
xv
);
break
;
case
TrigoOperation
.
TANH
:
v
=
Math
.
tanh
(
xv
);
break
;
default
:
throw
new
Error
(
"
Trigo.Equation() : invalid operation
"
+
this
.
operation
);
}
break
;
case
"
X
"
:
const
yv
=
this
.
prms
.
Y
.
v
;
switch
(
this
.
operation
)
{
case
TrigoOperation
.
COS
:
v
=
Math
.
acos
(
yv
);
break
;
case
TrigoOperation
.
SIN
:
v
=
Math
.
asin
(
yv
);
break
;
case
TrigoOperation
.
TAN
:
v
=
Math
.
atan
(
yv
);
break
;
case
TrigoOperation
.
COSH
:
v
=
Math
.
acosh
(
yv
);
break
;
case
TrigoOperation
.
SINH
:
v
=
Math
.
asinh
(
yv
);
break
;
case
TrigoOperation
.
TANH
:
v
=
Math
.
atanh
(
yv
);
break
;
default
:
throw
new
Error
(
"
Trigo.Equation() : invalid operation
"
+
this
.
operation
);
}
if
(
this
.
unit
===
TrigoUnit
.
DEG
)
{
v
=
v
/
Math
.
PI
*
180
;
}
break
;
default
:
throw
new
Error
(
"
Trigo.Equation() : invalid variable name
"
+
sVarCalc
);
}
return
new
Result
(
v
,
this
);
}
// interface Observer
public
update
(
sender
:
any
,
data
:
any
)
{
if
(
data
.
action
===
"
propertyChange
"
)
{
switch
(
data
.
name
)
{
case
"
trigoOperation
"
:
case
"
trigoUnit
"
:
// adjust definition domains
const
un
=
this
.
unit
;
switch
(
this
.
operation
)
{
case
TrigoOperation
.
COS
:
case
TrigoOperation
.
SIN
:
// [-1,1]
this
.
prms
.
Y
.
domain
.
interval
.
setInterval
(
new
Interval
(
-
1
,
1
));
break
;
case
TrigoOperation
.
TANH
:
// ]-1,1[
// @TODO manage boundaries exclusion in Interval
this
.
prms
.
Y
.
domain
.
interval
.
setInterval
(
new
Interval
(
-
0.99999999
,
0.99999999
));
break
;
case
TrigoOperation
.
TAN
:
case
TrigoOperation
.
SINH
:
// R
this
.
prms
.
Y
.
setDomain
(
ParamDomainValue
.
ANY
);
break
;
case
TrigoOperation
.
COSH
:
// [1,+∞[
this
.
prms
.
Y
.
domain
.
interval
.
setInterval
(
new
Interval
(
1
,
Infinity
));
break
;
}
}
}
}
/** paramétrage de la calculabilité des paramètres */
protected
setParametersCalculability
()
{
this
.
prms
.
Y
.
calculability
=
ParamCalculability
.
EQUATION
;
this
.
prms
.
X
.
calculability
=
ParamCalculability
.
EQUATION
;
}
}
src/trigo_params.ts
0 → 100644
View file @
ad8ee303
import
{
ParamDefinition
,
ParamFamily
}
from
"
./param/param-definition
"
;
import
{
ParamDomainValue
}
from
"
./param/param-domain
"
;
import
{
ParamsEquation
}
from
"
./param/params-equation
"
;
/**
* Y = f(X)
*/
export
class
TrigoParams
extends
ParamsEquation
{
/** Y */
private
_Y
:
ParamDefinition
;
/** X */
private
_X
:
ParamDefinition
;
constructor
(
rY
:
number
,
rX
:
number
)
{
super
();
this
.
_Y
=
new
ParamDefinition
(
this
,
"
Y
"
,
ParamDomainValue
.
ANY
,
undefined
,
rY
,
ParamFamily
.
ANY
);
this
.
_X
=
new
ParamDefinition
(
this
,
"
X
"
,
ParamDomainValue
.
ANY
,
undefined
,
rX
,
ParamFamily
.
ANY
);
this
.
addParamDefinition
(
this
.
_Y
);
this
.
addParamDefinition
(
this
.
_X
);
}
get
Y
()
{
return
this
.
_Y
;
}
get
X
()
{
return
this
.
_X
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment