TrianglesImpl.mesa
Last Edited by: Arnon, July 19, 1985 2:54:46 pm PDT
DIRECTORY
Rope,
Atom,
IO,
Convert,
MathExpr,
MathConstructors,
AlgebraClasses,
FormulaOperators,
Ints,
Reals,
BigRats,
RatIntervals,
Variables,
Polynomials,
Formulas,
AlgebraicNumbers,
ExtensionFields,
SamplePoints,
Points,
Sequences,
Graphs,
CoveringSets,
Triangles;
TrianglesImpl: CEDAR PROGRAM
IMPORTS
EXPORTS Triangles =
BEGIN OPEN AC: AlgebraClasses, BR: BigRats, RI: RatIntervals, VARS: Variables, AN: AlgebraicNumbers, PTS: Points, POL: Polynomials, AN: AlgebraicNumbers, EF: ExtensionFields, SEQ: Sequences, QFF: Formulas, SP: SamplePoints, CS: CoveringSets, Triangles;
Covering Sets and Triangulations
CountTriangles: PUBLIC PROC [in: CS.CoveringSet] RETURNS [number: CARDINAL] ~ {
K, i, j: NAT;
M, I, J: CARDINAL ← 0;
inData: CS.CoveringSetData;
pointsData, columnDataThis, columnDataNext: SEQ.SequenceData;
IF in = NIL THEN RETURN[0];
inData ← NARROW[in.data];
IF inData = NIL THEN RETURN[0];
pointsData ← NARROW[inData.dataPoints.data];
IF pointsData.lengthPlus1-1 = 1 THEN RETURN[0];
number ← 0;
K ← 0;
WHILE K < pointsData.lengthPlus1-1 DO
K ← K + 1;
IF K = pointsData.lengthPlus1-1 THEN EXIT;
columnDataThis ← NARROW[pointsData[K].data];
columnDataNext ← NARROW[pointsData[K+1].data];
I ← columnDataThis.lengthPlus1-1;
J ← columnDataNext.lengthPlus1-1;
IF I < 2 AND J < 2 THEN {
M ← M + I;
LOOP;
};
IF I = 0 OR J = 0 THEN {
M ← M + I;
LOOP;
};
i ← 1; j ← 1;
WHILE i < I AND j < J DO
number ← number + 2;
i ← i+1;
j ← j+1;
ENDLOOP;
WHILE i < I DO
number ← number + 1;
i ← i+1;
ENDLOOP;
WHILE j < J DO
number ← number + 1;
j ← j+1;
ENDLOOP;
M ← M + I;
ENDLOOP;
};
GenerateTriangles: PUBLIC PROC [in: CS.CoveringSet] RETURNS [out: TriangleSeq] ~ {
K, i, j: NAT;
M, I, J: CARDINAL ← 0;
inData: CS.CoveringSetData;
pointsData, columnDataThis, columnDataNext: SEQ.SequenceData;
numTriangles: CARDINAL ← CountTriangles[in];
number: CARDINAL ← 0;
IF numTriangles = 0 THEN RETURN[NIL];
inData ← NARROW[in.data];
out ← NEW[TriangleSeqRec[numTriangles]];
pointsData ← NARROW[inData.dataPoints.data];
K ← 0;
WHILE K < pointsData.lengthPlus1-1 DO
K ← K + 1;
IF K = pointsData.lengthPlus1-1 THEN EXIT;
columnDataThis ← NARROW[pointsData[K].data];
columnDataNext ← NARROW[pointsData[K+1].data];
I ← columnDataThis.lengthPlus1-1;
J ← columnDataNext.lengthPlus1-1;
IF I < 2 AND J < 2 THEN {
M ← M + I;
LOOP;
};
IF I = 0 OR J = 0 THEN {
M ← M + I;
LOOP;
};
i ← 1; j ← 1;
WHILE i < I AND j < J DO
number ← number + 1;
out[number].firstVertex ← M+i;
out[number].secondVertex ← M+i+1;
out[number].thirdVertex ← M+I+j;
i ← i+1;
number ← number + 1;
out[number].firstVertex ← M+I+j;
out[number].secondVertex ← M+i;
out[number].thirdVertex ← M+I+j+1;
j ← j+1;
ENDLOOP;
WHILE i < I DO
number ← number + 1;
out[number].firstVertex ← M+i;
out[number].secondVertex ← M+i+1;
out[number].thirdVertex ← M+I+j;
i ← i+1;
ENDLOOP;
WHILE j < J DO
number ← number + 1;
out[number].firstVertex ← M+I+j;
out[number].secondVertex ← M+i;
out[number].thirdVertex ← M+I+j+1;
j ← j+1;
ENDLOOP;
M ← M + I;
ENDLOOP;
};
END.