Commit 1ff170bf authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Trigo: adjust definition domains on operation change

parent 89d34483
......@@ -173,4 +173,33 @@ describe("Class Trigo: ", () => {
expect(trig.calculatedParam.symbol).toBe("Y");
});
it ("definition domains depending on operation", () => {
const nub = new Trigo(new TrigoParams(1.5, 1));
nub.calculatedParam = nub.prms.Y;
nub.unit = TrigoUnit.RAD;
// RAD / COS (COS is default operation)
expect(nub.prms.Y.domain.interval.min).toBe(-1);
expect(nub.prms.Y.domain.interval.max).toBe(1);
// RAD / TAN
nub.operation = TrigoOperation.TAN;
expect(nub.prms.Y.domain.interval.min).toBe(-Infinity);
expect(nub.prms.Y.domain.interval.max).toBe(Infinity);
// RAD / SIN
nub.operation = TrigoOperation.SIN;
expect(nub.prms.Y.domain.interval.min).toBe(-1);
expect(nub.prms.Y.domain.interval.max).toBe(1);
// RAD / SINH
nub.operation = TrigoOperation.SINH;
expect(nub.prms.Y.domain.interval.min).toBe(-Infinity);
expect(nub.prms.Y.domain.interval.max).toBe(Infinity);
// RAD / TANH
nub.operation = TrigoOperation.TANH;
expect(nub.prms.Y.domain.interval.min).toBe(-0.99999999);
expect(nub.prms.Y.domain.interval.max).toBe(0.99999999);
// RAD / COSH
nub.operation = TrigoOperation.COSH;
expect(nub.prms.Y.domain.interval.min).toBe(1);
expect(nub.prms.Y.domain.interval.max).toBe(Infinity);
});
});
import { CalculatorType } from "./compute-node";
import { Nub } from "./nub";
import { ParamCalculability } from "./param/param-definition";
import { ParamDomainValue } from "./param/param-domain";
import { ParamDomain, ParamDomainValue } from "./param/param-domain";
import { TrigoParams } from "./trigo_params";
import { Interval } from "./util/interval";
import { Observer } from "./util/observer";
import { Result } from "./util/result";
......@@ -132,19 +131,18 @@ export class Trigo extends Nub implements Observer {
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));
this.prms.Y.setDomain(new ParamDomain(ParamDomainValue.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));
this.prms.Y.setDomain(new ParamDomain(ParamDomainValue.INTERVAL, -0.99999999, 0.99999999));
break;
case TrigoOperation.TAN:
case TrigoOperation.SINH:
......@@ -153,7 +151,7 @@ export class Trigo extends Nub implements Observer {
break;
case TrigoOperation.COSH:
// [1,+∞[
this.prms.Y.domain.interval.setInterval(new Interval(1, Infinity));
this.prms.Y.setDomain(new ParamDomain(ParamDomainValue.INTERVAL, 1, Infinity));
break;
}
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment