/*
	Test whether line (segments) are rendered as expected.
	A select few cells are checked automatically, but we mostly save the geometry for visual inspection.
*/

N2 := 31
c := 5e-9
SetCellSize(c, c, c)
SetGridSize(2*N2 + 1, 2*N2 + 1, 2*N2 + 1)
Msat = 800e3
Aex = 13e-12

shape := Line2D(-20, 0, 10, 5, 8, "infinite").Scale(c, c, c)
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line2D_infinite.ovf")
for z := 0; z < 2*N2 + 1; z++ {
	expect("geom", geom.GetCell(N2-5, N2+3, z), 1, 0) // Inside line segment
	expect("geom", geom.GetCell(N2-26, N2-1, z), 1, 0) // Beyond line segment, but "infinite"
}

shape = Line2D(-20, 0, 10, 5, 8, "round").Scale(c, c, c)
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line2D_round.ovf")
for z := 0; z < 2*N2 + 1; z++ {
	expect("geom", geom.GetCell(N2-5, N2+3, z), 1, 0) // Inside line segment
	expect("geom", geom.GetCell(N2-26, N2-1, z), 0, 0) // Beyond line segment
	expect("geom", geom.GetCell(N2-23, N2-1, z), 1, 0) // Beyond line segment, but within "round"
}

shape = Line2D(-20, 0, 10, 5, 8, "flat").Scale(c, c, c)
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line2D_flat.ovf")
for z := 0; z < 2*N2 + 1; z++ {
	expect("geom", geom.GetCell(N2-5, N2+3, z), 1, 0) // Inside line segment
	expect("geom", geom.GetCell(N2-26, N2-1, z), 0, 0) // Beyond line segment
	expect("geom", geom.GetCell(N2-23, N2-1, z), 0, 0) // Beyond line segment, but within "round"
}

shape = Line2D(-20*c, 0, 10*c, 5*c, 0, "infinite")
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line2D_infinite_d=0.ovf")
for z := 0; z < 2*N2 + 1; z++ {
	expect("geom", geom.GetCell(N2-5, N2+2, z), 1, 0) // Inside line segment
	expect("geom", geom.GetCell(N2-5, N2+1, z), 0, 0) // Next to line segment
	expect("geom", geom.GetCell(N2-26, N2-1, z), 1, 0) // Beyond line segment, but "infinite"
}

shape = Line(-20, 0, 0, 10, 5, 7, 8, "infinite").Scale(c, c, c)
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line_infinite.ovf")
expect("geom", geom.GetCell(N2-5, N2+3, N2+4), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2-5, N2+3, N2+10), 0, 0) // Above line segment
expect("geom", geom.GetCell(N2-26, N2-1, N2-2), 1, 0) // Beyond line segment, but "infinite"

shape = Line(-20, 0, 0, 10, 5, 7, 8, "round").Scale(c, c, c)
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line_round.ovf")
expect("geom", geom.GetCell(N2-20, N2+0, N2+0), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2-20, N2+4, N2+0), 1, 0) // Just barely within segment
expect("geom", geom.GetCell(N2-19, N2+4, N2+0), 1, 0) // Just barely within segment
expect("geom", geom.GetCell(N2-19, N2-4, N2+0), 0, 0) // Just barely not within segment nor "round"
expect("geom", geom.GetCell(N2-20, N2+0, N2+4), 1, 0) // On segment boundary
expect("geom", geom.GetCell(N2-20, N2+0, N2+5), 0, 0) // Just barely outside segment boundary
expect("geom", geom.GetCell(N2-21, N2+0, N2+4), 0, 0) // Just barely outside "round"
expect("geom", geom.GetCell(N2-21, N2+0, N2+3), 1, 0) // Just barely within "round"

shape = Line(-20, 0, 0, 10, 5, 7, 8, "flat").Scale(c, c, c)
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line_flat.ovf")
expect("geom", geom.GetCell(N2-20, N2+0, N2+0), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2-20, N2+4, N2+0), 1, 0) // Just barely within segment
expect("geom", geom.GetCell(N2-19, N2+4, N2+0), 1, 0) // Just barely within segment
expect("geom", geom.GetCell(N2-19, N2-4, N2+0), 0, 0) // Just barely not within segment nor "round"
expect("geom", geom.GetCell(N2-20, N2+0, N2+4), 1, 0) // On segment boundary
expect("geom", geom.GetCell(N2-20, N2+0, N2+5), 0, 0) // Just barely outside segment boundary
expect("geom", geom.GetCell(N2-21, N2+0, N2+4), 0, 0) // Just barely outside "round"
expect("geom", geom.GetCell(N2-21, N2+0, N2+3), 0, 0) // Just barely within "round"
expect("geom", geom.GetCell(N2-5, N2+3, N2+4), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2-5, N2+3, N2+10), 0, 0) // Above line segment
expect("geom", geom.GetCell(N2-26, N2-1, N2-2), 0, 0) // Beyond line segment, but in "infinite"

shape = Line(-20*c, 0, 0, 10*c, 5*c, 7*c, 0, "infinite")
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line_infinite_d=0.ovf")
expect("geom", geom.GetCell(N2-5, N2+2, N2+3), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2-5, N2+1, N2+3), 0, 0) // Next to line segment
expect("geom", geom.GetCell(N2-5, N2+3, N2+3), 1, 0) // Next to line segment, but inside 1e-15 safety check
expect("geom", geom.GetCell(N2-26, N2-1, N2-2), 1, 0) // Beyond line segment, but "infinite"

shape = Line(-20*c, 0, 0, 10*c, 5*c, 7*c, 0, "round")
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line_round_d=0.ovf")
expect("geom", geom.GetCell(N2-5, N2+2, N2+3), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2-5, N2+1, N2+3), 0, 0) // Next to line segment
expect("geom", geom.GetCell(N2-26, N2-1, N2-2), 0, 0) // Beyond line segment

shape = Line(0, 0, 0, 0, 0, 10*c, 0, "round")
SetGeom(shape)
m = Uniform(1, 0, 0)
SaveAs(m, "Line_round_d=0_axisAligned.ovf")
expect("geom", geom.GetCell(N2+0, N2+0, N2+5), 1, 0) // Inside line segment
expect("geom", geom.GetCell(N2+0, N2+1, N2+5), 0, 0) // Next to line segment
