Read:
PUBLIC
AC.ReadOp ~ {
coveringSetStructureData: CoveringSetStructureData ← NARROW[structure.instanceData];
dimension: NAT ← coveringSetStructureData.ambientSpaceDimension;
token: Rope.ROPE ← in.GetID[];
pointStructure: AC.Structure ← PTS.MakePointStructure[Reals.Reals, dimension]; -- currently assume data points have real-valued coordinates
boundingBoxStructure: AC.Structure ← PTS.MakePointStructure[Reals.Reals, 2*dimension];
columnStructure: AC.Structure ← SEQ.MakeSequenceStructure[pointStructure];
dataPointsStructure: AC.Structure ← SEQ.MakeSequenceStructure[columnStructure];
pointList, pointListTail: LIST OF AC.Object;
columnList, columnListTail: LIST OF AC.Object ← NIL;
column, dataPoints: SEQ.Sequence;
point: PTS.Point;
pointData: PTS.PointData;
boundingBox: PTS.Point;
outData: CoveringSetData;
xVal, yVal, zVal: REAL;
minX, minY, minZ: REAL ← 1500000.0;
maxX, maxY, maxZ: REAL ← -1500000.0;
IF Rope.Equal[token, "NILCOVERINGSET"]
THEN
RETURN[NEW[AC.ObjectRec ← [structure: structure, data: NIL] ] ];
WHILE Rope.Equal[token, "
BEGINCOLUMN"]
DO
[]← in.SkipWhitespace[];
pointList ← pointListTail ← NIL;
WHILE in.PeekChar[]='(
DO
point ← PTS.Read[in, pointStructure];
IF pointList=
NIL
THEN pointList ← pointListTail ←
LIST[point]
ELSE
pointListTail ← pointListTail.rest ← LIST[point];
pointData ← NARROW[point.data];
xVal ← NARROW[pointData[1].data, Reals.RealData]^;
IF xVal < minX THEN minX ← xVal;
IF xVal > maxX THEN maxX ← xVal;
IF dimension > 1
THEN {
yVal ← NARROW[pointData[2].data, Reals.RealData]^;
IF yVal < minY THEN minY ← yVal;
IF yVal > maxY THEN maxY ← yVal;
};
IF dimension > 2
THEN {
zVal ← NARROW[pointData[3].data, Reals.RealData]^;
IF zVal < minZ THEN minZ ← zVal;
IF zVal > maxZ THEN maxZ ← zVal;
};
[]← in.SkipWhitespace[];
ENDLOOP;
token ← in.GetID[];
IF NOT Rope.Equal[token, "ENDCOLUMN"] THEN ERROR;
column ← SEQ.MakeSeq[pointList, columnStructure];
IF columnList=
NIL
THEN columnList ← columnListTail ←
LIST[column]
ELSE
columnListTail ← columnListTail.rest ← LIST[column];
token ← in.GetID[];
ENDLOOP;
IF NOT Rope.Equal[token, "ENDCOVERINGSET"] THEN ERROR;
dataPoints ← SEQ.MakeSeq[columnList, dataPointsStructure]; -- assumes length >=1
SELECT dimension
FROM
1 => boundingBox ←
PTS.MakePt[
LIST[
Reals.FromREAL[minX], Reals.FromREAL[maxX]
], boundingBoxStructure];
2 => boundingBox ←
PTS.MakePt[
LIST[
Reals.FromREAL[minX], Reals.FromREAL[maxX],
Reals.FromREAL[minY], Reals.FromREAL[maxY]
], boundingBoxStructure];
3 => boundingBox ←
PTS.MakePt[
LIST[
Reals.FromREAL[minX], Reals.FromREAL[maxX],
Reals.FromREAL[minY], Reals.FromREAL[maxY],
Reals.FromREAL[minZ], Reals.FromREAL[maxZ]
], boundingBoxStructure];
ENDCASE;
outData ←
NEW[CoveringSetDataRec ← [
stepSize: BR.FromLC[0],
numDecimalPlaces: Ints.FromINT[0],
reach: Ints.FromINT[0],
boundingBox: boundingBox,
dataPoints: dataPoints] ];
RETURN[NEW[AC.ObjectRec ← [structure: structure, data: outData] ] ];
};
ToRope:
PUBLIC
AC.ToRopeOp ~ {
inData: CoveringSetData;
pointsData, columnData: SEQ.SequenceData;
IF in = NIL THEN RETURN[NIL];
inData ← NARROW[in.data];
IF inData = NIL THEN RETURN[NIL];
pointsData ← NARROW[inData.dataPoints.data];
out ← "";
out ← Rope.Concat[out, "BEGINCOVERINGSET\n"];
FOR i:
NAT
IN [1..pointsData.lengthPlus1-1]
DO
out ← Rope.Concat[out, "BEGINCOLUMN\n"];
columnData ← NARROW[pointsData[i].data];
FOR j:
NAT
IN [1..columnData.lengthPlus1-1]
DO
point: AC.Object ← NARROW[columnData[j] ];
out ← Rope.Cat[out, point.structure.class.toRope[point], "\n"];
ENDLOOP;
out ← Rope.Concat[out, "ENDCOLUMN\n"];
ENDLOOP;
out ← Rope.Concat[out, "ENDCOVERINGSET\n"];
};