Trajectories
LastPoint:
PUBLIC
PROC[t: Trajectory]
RETURNS[x, y:
REAL] ~ {
RETURN[t.lp.x, t.lp.y];
};
LastPointP:
PUBLIC
PROC[t: Trajectory]
RETURNS[Pair] ~ {
RETURN[t.lp];
};
MoveTo:
PUBLIC
PROC[x, y:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[move] ← [prev: NIL, lp: [x, y], variant: move[]]]];
};
MoveToP:
PUBLIC
PROC[p: Pair]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[move] ← [prev: NIL, lp: p, variant: move[]]]];
};
LineTo:
PUBLIC
PROC[t: Trajectory, x, y:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[line] ← [prev: t, lp: [x, y], variant: line[]]]];
};
LineToP:
PUBLIC
PROC[t: Trajectory, p: Pair]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[line] ← [prev: t, lp: p, variant: line[]]]];
};
LineToX:
PUBLIC
PROC[t: Trajectory, x:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[line] ← [prev: t, lp: [x, t.lp.y], variant: line[]]]];
};
LineToY:
PUBLIC
PROC[t: Trajectory, y:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[line] ← [prev: t, lp: [t.lp.x, y], variant: line[]]]];
};
CurveTo:
PUBLIC
PROC[t: Trajectory, x1, y1, x2, y2, x3, y3:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[curve] ← [prev: t, lp: [x3, y3], variant: curve[[x1, y1], [x2, y2]]]]];
};
CurveToP:
PUBLIC
PROC[t: Trajectory, p1, p2, p3: Pair]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[curve] ← [prev: t, lp: p3, variant: curve[p1, p2]]]];
};
ConicTo:
PUBLIC
PROC[t: Trajectory, x1, y1, x2, y2:
REAL, r:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[conic] ← [prev: t, lp: [x2, y2], variant: conic[[x1, y1], r]]]];
};
ConicToP:
PUBLIC
PROC[t: Trajectory, p1, p2: Pair, r:
REAL]
RETURNS[Trajectory] ~ {
RETURN[NEW[TrajectoryRep[conic] ← [prev: t, lp: p2, variant: conic[p1, r]]]];
};
ArcTo:
PUBLIC
PROC[t: Trajectory, x1, y1, x2, y2:
REAL]
RETURNS[Trajectory] ~ {
conic: PROC[p1, p2: Pair, r: REAL] ~ {t ← ConicToP[t, p1, p2, r]};
ImagerConic.FromArc[t.lp, [x1, y1], [x2, y2], conic];
RETURN[t];
};
ArcToP:
PUBLIC
PROC[t: Trajectory, p1, p2: Pair]
RETURNS[Trajectory] ~ {
conic: PROC[p1, p2: Pair, r: REAL] ~ {t ← ConicToP[t, p1, p2, r]};
ImagerConic.FromArc[t.lp, p1, p2, conic];
RETURN[t];
};
PathProc: TYPE ~ PROC[
data: REF,
moveTo: PROC[x, y: REAL],
lineTo: PROC[x, y: REAL],
curveTo: PROC[x1, y1, x2, y2, x3, y3: REAL],
conicTo: PROC[x1, y1, x2, y2: REAL, r: REAL],
arcTo: PROC[x1, y1, x2, y2: REAL]
];
MapTrajectory:
PUBLIC PathProc ~ {
WITH data
SELECT
FROM
end: Trajectory => {
move[end.lp];
FOR t: Trajectory ← end, t.prev
UNTIL t.prev=
NIL
DO
p0: Pair ~ t.prev.lp;
WITH t
SELECT
FROM
t: REF TrajectoryRep[move] => ERROR; -- should have had t.prev=NIL
t: REF TrajectoryRep[line] => line[p0];
t: REF TrajectoryRep[curve] => curve[t.p2, t.p1, p0];
t: REF TrajectoryRep[conic] => conic[t.p1, p0, t.r];
t: REF TrajectoryRep[arc] => arc[t.p1, p0];
ENDCASE => ERROR; -- unknown variant
ENDLOOP;
};
ENDCASE => ERROR; -- data is wrong type or NIL
};
MapTrajectoryList:
PUBLIC PathProc ~ {
WITH data
SELECT
FROM
head: TrajectoryList => {
FOR list: TrajectoryList ← head, list.rest
UNTIL list=
NIL
DO
t: Trajectory ~ list.first;
MapTrajectory[t, move, line, curve, conic];
ENDLOOP;
};
ENDCASE => ERROR; -- data is wrong type or NIL
};
Strokes
SetStrokeWidth:
PUBLIC
PROC[context: Context, strokeWidth:
REAL] ~ {
context.class.SetStrokeWidth[context, strokeWidth];
};
SetStrokeEnd:
PUBLIC
PROC[context: Context, strokeEnd: StrokeEnd] ~ {
context.class.SetStrokeEnd[context, strokeEnd];
};
MaskStroke:
PUBLIC
PROC[context: Context, stroke:
REF] ~ {
WITH stroke
SELECT
FROM
t: Trajectory => context.class.MaskStroke[context, MapTrajectory, t];
tlist: TrajectoryList => context.class.MaskStroke[context, MapTrajectoryList, tlist];
path: PATH => context.class.MaskStroke[context, MapPath, path];
ENDCASE => ERROR Error[$InvalidStroke]; -- stroke is wrong type or NIL
};
MaskStrokeClosed:
PUBLIC
PROC[context: Context, stroke:
REF] ~ {
WITH stroke
SELECT
FROM
t: Trajectory => context.class.MaskStrokeClosed[context, MapTrajectory, t];
tlist: TrajectoryList => context.class.MaskStrokeClosed[context, MapTrajectoryList, tlist];
path: PATH => context.class.MaskStrokeClosed[context, MapPath, path];
ENDCASE => ERROR Error[$InvalidStroke]; -- stroke is wrong type or NIL
};
MaskStrokePath:
PUBLIC
PROC[
context: Context, pathProc: PathProc, pathData: REF ← NIL] ~ {
context.class.MaskStroke[context, pathProc, pathData];
};
MaskStrokeClosedPath:
PUBLIC
PROC[
context: Context, pathProc: PathProc, pathData: REF ← NIL] ~ {
context.class.MaskStrokeClosed[context, pathProc, pathData];
};
Rectangles and vectors
MaskRectangle:
PUBLIC
PROC[context: Context, x, y, w, h:
REAL] ~ {
context.class.MaskRectangle[context: context, x: x, y: y, w: w, h: h];
};
MaskBox:
PUBLIC
PROC[context: Context, box: Box] ~ {
context.class.MaskRectangle[context: context,
x: box.xmin, y: box.ymin, w: box.xmax-box.xmin, h: box.ymax-box.ymin];
};
MaskVector:
PUBLIC
PROC[context: Context, x1, y1, x2, y2:
REAL] ~ {
context.class.MaskVector[context: context, x1: x1, y1: y1, x2: x2, y2: y2];
};
MaskVectorP:
PUBLIC
PROC[context: Context, p1, p2: Pair] ~ {
context.class.MaskVector[context: context, x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y];
};