// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT.

//go:build (darwin && amd64) || (darwin && arm64) || (freebsd && amd64) || (linux && amd64) || (linux && arm64) || (linux && loong64) || (linux && ppc64le) || (linux && riscv64) || (linux && s390x) || (netbsd && amd64) || (openbsd && amd64) || (openbsd && arm64) || (windows && (amd64 || arm64))

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

// C documentation
//
//	/*
//	** Add a single segment and its associated events.
//	*/
func _geopolyAddOneSegment(tls *libc.TLS, p uintptr, x0 TGeoCoord, y0 TGeoCoord, x1 TGeoCoord, y1 TGeoCoord, side uint8, idx uint32) {
	var pEvent, pSeg uintptr
	var t TGeoCoord
	_, _, _ = pEvent, pSeg, t
	if x0 == x1 {
		return
	} /* Ignore vertical segments */
	if x0 > x1 {
		t = x0
		x0 = x1
		x1 = t
		t = y0
		y0 = y1
		y1 = t
	}
	pSeg = (*TGeoOverlap)(unsafe.Pointer(p)).FaSegment + uintptr((*TGeoOverlap)(unsafe.Pointer(p)).FnSegment)*48
	(*TGeoOverlap)(unsafe.Pointer(p)).FnSegment = (*TGeoOverlap)(unsafe.Pointer(p)).FnSegment + 1
	(*TGeoSegment)(unsafe.Pointer(pSeg)).FC = float64((y1 - y0) / (x1 - x0))
	(*TGeoSegment)(unsafe.Pointer(pSeg)).FB = float64(y1) - float64(float64(x1)*(*TGeoSegment)(unsafe.Pointer(pSeg)).FC)
	(*TGeoSegment)(unsafe.Pointer(pSeg)).Fy0 = y0
	(*TGeoSegment)(unsafe.Pointer(pSeg)).Fside = side
	(*TGeoSegment)(unsafe.Pointer(pSeg)).Fidx = idx
	pEvent = (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr((*TGeoOverlap)(unsafe.Pointer(p)).FnEvent)*32
	(*TGeoOverlap)(unsafe.Pointer(p)).FnEvent = (*TGeoOverlap)(unsafe.Pointer(p)).FnEvent + 1
	(*TGeoEvent)(unsafe.Pointer(pEvent)).Fx = float64(x0)
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FeType = 0
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FpSeg = pSeg
	pEvent = (*TGeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr((*TGeoOverlap)(unsafe.Pointer(p)).FnEvent)*32
	(*TGeoOverlap)(unsafe.Pointer(p)).FnEvent = (*TGeoOverlap)(unsafe.Pointer(p)).FnEvent + 1
	(*TGeoEvent)(unsafe.Pointer(pEvent)).Fx = float64(x1)
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FeType = int32(1)
	(*TGeoEvent)(unsafe.Pointer(pEvent)).FpSeg = pSeg
}

// C documentation
//
//	/*
//	** SQL Function:      geopoly_xform(poly, A, B, C, D, E, F)
//	**
//	** Transform and/or translate a polygon as follows:
//	**
//	**      x1 = A*x0 + B*y0 + E
//	**      y1 = C*x0 + D*y0 + F
//	**
//	** For a translation:
//	**
//	**      geopoly_xform(poly, 1, 0, 0, 1, x-offset, y-offset)
//	**
//	** Rotate by R around the point (0,0):
//	**
//	**      geopoly_xform(poly, cos(R), sin(R), -sin(R), cos(R), 0, 0)
//	*/
func _geopolyXformFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var A, B, C, D, E, F float64
	var ii int32
	var p uintptr
	var x0, x1, y0, y1 TGeoCoord
	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, ii, p, x0, x1, y0, y1
	p = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
	A = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	B = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 2*8)))
	C = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 3*8)))
	D = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 4*8)))
	E = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 5*8)))
	F = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 6*8)))
	_ = argc
	if p != 0 {
		ii = 0
		for {
			if !(ii < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
				break
			}
			x0 = **(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2))*4))
			y0 = **(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2)+int32(1))*4))
			x1 = float32(float64(A*float64(x0)) + float64(B*float64(y0)) + E)
			y1 = float32(float64(C*float64(x0)) + float64(D*float64(y0)) + F)
			**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2))*4)) = x1
			**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2)+int32(1))*4)) = y1
			goto _1
		_1:
			;
			ii = ii + 1
		}
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}
