Xiaolin Wu's line algorithm: Difference between revisions

Content added Content deleted
(→‎{{header|J}}: give wd example for J8)
(Updated D entry)
Line 184: Line 184:
double x1, double y1,
double x1, double y1,
double x2, double y2,
double x2, double y2,
in Color color) /*pure*/ nothrow {
in Color color) /*pure*/ nothrow @safe {
// Straight translation of Wikipedia pseudocode.
// Straight translation of Wikipedia pseudocode.
static double round(in double x) pure nothrow {
static double round(in double x) pure nothrow {
Line 190: Line 190:
}
}


static double fpart(in double x) pure nothrow {
static double fpart(in double x) pure nothrow @safe {
return x - x.floor;
return x - x.floor;
}
}


static double rfpart(in double x) pure nothrow {
static double rfpart(in double x) pure nothrow @safe {
return 1 - fpart(x);
return 1 - fpart(x);
}
}
Line 204: Line 204:


static Color mixColors(in Color c1, in Color c2, in double p)
static Color mixColors(in Color c1, in Color c2, in double p)
pure nothrow {
pure nothrow @safe @nogc {
static if (is(Color == RGB))
static if (is(Color == RGB))
return Color(cast(ubyte)(c1.r * p + c2.r * (1 - p)),
return Color(cast(ubyte)(c1.r * p + c2.r * (1 - p)),
Line 216: Line 216:
// Plot function set here to handle the two cases of slope.
// Plot function set here to handle the two cases of slope.
void delegate(ref Image!Color img, in int, in int, in double)
void delegate(ref Image!Color img, in int, in int, in double)
pure nothrow plot;
pure nothrow @safe @nogc plot;


if (ax < ay) {
if (ax < ay) {