package d2isometricimg

import (
	
	

	
	
)

// The source page reserves its upper-right corner for a fold. Give that
// corner a real inclined surface, within the same source footprint, so light,
// occlusion and the object outline describe the fold instead of a printed glyph.
func ( *meshBuilder) ( d2isometric.Node,  labelSurface,  *image.RGBA,  *Material, , ,  float64,  []Vec) {
	,  := .Position.X+.Size.X/2+, .Position.Z-.Size.Z/2+
	var  []Vec
	 := -1
	// The source contour traverses the top edge, rounded fold, then right
	// edge. Use those actual vertices, including source coordinate rounding.
	// Clamping the corner to half the page height truncates short pages.
	for ,  := range  {
		if math.Abs(.Z-) < 1e-8 {
			 = 
		}
		if  >= 0 &&  >  && math.Abs(.X-) < 1e-8 {
			 = [ : +1]
			break
		}
	}
	if len() < 2 {
		return
	}
	// The fold attaches directly to the source's rounded diagonal. A
	// separate slab above this edge creates two competing rims and leaves
	// an acute ink spike where its top edge meets the page perimeter.
	,  := -[0].X, [len()-1].Z-
	 := nv(-*.90, +math.Min(, )*.62, +*.90)
	 := *
	if  != nil {
		 = *nativeMaterial("white", .68, 0, .Opacity)
		.Texture, .Vector = , nativeVectorForTexture(.ctx, )
	}
	// Paper thickness is below the outline width. One inclined sheet gives
	// the fold its own lighting and shadow without a second free-edge rim.
	for  := 1;  < len(); ++ {
		,  := [-1], []
		 := nunit(ncross(nsub(, ), nsub(, )))
		 := func( Vec) Vertex {
			return Vertex{Position: , Normal: ,
				U: (.X-.center.X)/.width + .5,
				V: (.Z-.center.Z)/.depth + .5}
		}
		.triangle((), (), (), &, true)
	}
}

// The second source Page path draws the flat fold and repeats an inset
// perimeter. The physical fold replaces that glyph; the outer source path
// continues to carry authored dash, width and border-label aperture.
func nativeRemovePageGlyph( *d2scene.Node) {
	 := 0
	var  func(*d2scene.Node)
	 = func( *d2scene.Node) {
		if  == nil {
			return
		}
		if ,  := .Primitive.(d2scene.Path);  && .Stroke != nil {
			if  == 1 {
				.Stroke = nil
				.Primitive = 
			}
			++
		}
		for ,  := range .Children {
			()
		}
	}
	// nativeFaceSource creates exactly one undecorated Page shape. Its
	// ordinary paths have no IDs; their stroked order is outer, inner glyph.
	// Pattern overlays between them carry fill only.
	()
}