Skip to content

Commit

Permalink
Handle missing flags in 3D conformal
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Nov 9, 2024
1 parent 9137ade commit 7a43fea
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/validation/extensions/NgaGpmValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2010,35 +2010,36 @@ export class NgaGpmValidator implements Validator<any> {
const flagsPath = path + "/flags";

// The flags MUST be an array of 7 boolean values
if (
!BasicValidator.validateArray(
flagsPath,
"flags",
flags,
7,
7,
"boolean",
context
)
) {
const flagsValid = BasicValidator.validateArray(
flagsPath,
"flags",
flags,
7,
7,
"boolean",
context
);
if (!flagsValid) {
result = false;
}

// The subsequent constraints imply that there must be at least
// one flag being set to 'true'. Check this explicitly.

// Compute the number of flags that are set to 'true'
const numTrueFlags = flags.reduce(
(n: number, f: boolean) => n + (f ? 1 : 0),
0
);
if (numTrueFlags === 0) {
const message =
`At least one of the flags of the threeDimensionalConformal ` +
`must be set to 'true'`;
const issue = JsonValidationIssues.VALUE_NOT_IN_RANGE(path, message);
context.addIssue(issue);
result = false;
if (flagsValid) {
const numTrueFlags = flags.reduce(
(n: number, f: boolean) => n + (f ? 1 : 0),
0
);
if (numTrueFlags === 0) {
const message =
`At least one of the flags of the threeDimensionalConformal ` +
`must be set to 'true'`;
const issue = JsonValidationIssues.VALUE_NOT_IN_RANGE(path, message);
context.addIssue(issue);
result = false;
}
}

// Validate the recentering
Expand Down

0 comments on commit 7a43fea

Please sign in to comment.