#include "triangle.cuh"

// custom rounding function to support needed pixel rounding

Triangle::Triangle(Point *a, Point *b, Point *c) {
	vertices[0] = a;
	vertices[1] = b;
	vertices[2] = c;
	if(getSignedArea() < 0) { // reverse direction
		vertices[1] = c;
		vertices[2] = b;
	}
}

double Triangle::getSignedArea() {
	double ax = vertices[0]->getX();
	double ay = vertices[0]->getY();
	double bx = vertices[1]->getX();
	double by = vertices[1]->getY();
	double cx = vertices[2]->getX();
	double cy = vertices[2]->getY();
	// determinant of matrix [bx - ax, cx - ax, by - ay, cy - ay] / 2
	return ((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2;
}

double Triangle::getArea() {
	double signedArea = getSignedArea();
	if (signedArea < 0) {
		return -signedArea;
	}
	return signedArea;
}

double Triangle::dA(int &p, double vx, double vy) {
	// first extract the other two endpoints; note order matters
	Point* edgePoints[2];
	// retrieve in ccw order
	edgePoints[0] = vertices[(p+1)%3];
	edgePoints[1] = vertices[(p+2)%3];
	// change is -velocity dot edge normal of length |e|/2
	Segment opposite(edgePoints[0], edgePoints[1]);
	// get normal to segment
	double nx, ny;
	opposite.scaledNormal(&nx, &ny);
	// return negative of dot product
	return -(vx * nx + vy * ny);
}

double Triangle::gradX(int &p) {
	return dA(p, 1, 0);
}

double Triangle::gradY(int &p) {
	return dA(p, 0, 1);
}

__device__ bool Triangle::contains(Point &p) {
	// p is inside the triangle iff the orientations of the triangles
	// with vertices (vertices[i], vertices[i+1], p) are all ccw
	for(int i = 0; i < 3; i++) {
		if (Triangle::getSignedArea(vertices[i], vertices[(i+1)%3], &p) < 0) {
			return false;
		}
	}
	return true;
}

int Triangle::midVertex() {
	double distances[3];
	for(int i = 0; i < 3; i++) {
		// get length of opposite side
		distances[i] = vertices[(i+1)%3]->distance(*vertices[(i+2)%3]);
	}
	for(int i = 0; i < 3; i++) {
		if(distances[i] >= min(distances[(i+1)%3], distances[(i+2)%3]) && 
			distances[i] <= max(distances[(i+1)%3], distances[(i+2)%3])) return i;
	}
	throw runtime_error("should not get here");
	return -1; // to make compiler happy
}

double Triangle::maxLength() {
	double distance = 0;
	for(int i = 0; i < 3; i++) {
		distance = max(distance, vertices[(i+1)%3]->distance(*vertices[(i+2)%3]));
	}
	return distance;
}

void Triangle::copyVertices(Point *ptrA, Point *ptrB, Point *ptrC) {
	*ptrA = *vertices[0];
	*ptrB = *vertices[1];
	*ptrC = *vertices[2];
}

double Triangle::getSignedArea(Point *a, Point *b, Point *c) {
	double ax = a->getX();
	double ay = a->getY();
	double bx = b->getX();
	double by = b->getY();
	double cx = c->getX();
	double cy = c->getY();
	return ((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2;
}

ostream& operator<<(ostream& os, const Triangle &t) {
	os << "Triangle ";
	for(Point *ptr : t.vertices) {
		os << *ptr << " ";
	}
	os << "\n";
	return os;
}

	.file	"tmpxft_002a82f1_00000000-6_triangle.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3931:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3931:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN8Triangle13getSignedAreaEv
	.type	_ZN8Triangle13getSignedAreaEv, @function
_ZN8Triangle13getSignedAreaEv:
.LFB3918:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	movq	(%rdi), %rdi
	call	_ZNK5Point4getXEv@PLT
	movq	(%rbx), %rdi
	movsd	%xmm0, 40(%rsp)
	call	_ZNK5Point4getYEv@PLT
	movq	8(%rbx), %rdi
	movsd	%xmm0, 32(%rsp)
	call	_ZNK5Point4getXEv@PLT
	movq	8(%rbx), %rdi
	movsd	%xmm0, 24(%rsp)
	call	_ZNK5Point4getYEv@PLT
	movq	16(%rbx), %rdi
	movsd	%xmm0, 16(%rsp)
	call	_ZNK5Point4getXEv@PLT
	movq	16(%rbx), %rdi
	movsd	%xmm0, 8(%rsp)
	call	_ZNK5Point4getYEv@PLT
	movsd	40(%rsp), %xmm5
	movsd	32(%rsp), %xmm4
	movsd	24(%rsp), %xmm1
	movsd	8(%rsp), %xmm2
	movsd	16(%rsp), %xmm3
	subsd	%xmm4, %xmm0
	subsd	%xmm5, %xmm1
	subsd	%xmm5, %xmm2
	subsd	%xmm4, %xmm3
	mulsd	%xmm1, %xmm0
	movaps	%xmm2, %xmm1
	mulsd	%xmm3, %xmm1
	subsd	%xmm1, %xmm0
	mulsd	.LC0(%rip), %xmm0
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3918:
	.size	_ZN8Triangle13getSignedAreaEv, .-_ZN8Triangle13getSignedAreaEv
	.align 2
	.globl	_ZN8TriangleC2EP5PointS1_S1_
	.type	_ZN8TriangleC2EP5PointS1_S1_, @function
_ZN8TriangleC2EP5PointS1_S1_:
.LFB3916:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movq	%rsi, (%rdi)
	movq	%rdx, 8(%rdi)
	movq	%rcx, 16(%rdi)
	call	_ZN8Triangle13getSignedAreaEv
	xorps	%xmm1, %xmm1
	comisd	%xmm0, %xmm1
	jbe	.L4
	movq	%r12, 8(%rbx)
	movq	%rbp, 16(%rbx)
.L4:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3916:
	.size	_ZN8TriangleC2EP5PointS1_S1_, .-_ZN8TriangleC2EP5PointS1_S1_
	.globl	_ZN8TriangleC1EP5PointS1_S1_
	.set	_ZN8TriangleC1EP5PointS1_S1_,_ZN8TriangleC2EP5PointS1_S1_
	.align 2
	.globl	_ZN8Triangle7getAreaEv
	.type	_ZN8Triangle7getAreaEv, @function
_ZN8Triangle7getAreaEv:
.LFB3919:
	.cfi_startproc
	endbr64
	pushq	%rdx
	.cfi_def_cfa_offset 16
	call	_ZN8Triangle13getSignedAreaEv
	xorps	%xmm1, %xmm1
	comisd	%xmm0, %xmm1
	jbe	.L10
	xorps	.LC2(%rip), %xmm0
.L10:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3919:
	.size	_ZN8Triangle7getAreaEv, .-_ZN8Triangle7getAreaEv
	.align 2
	.globl	_ZN8Triangle2dAERidd
	.type	_ZN8Triangle2dAERidd, @function
_ZN8Triangle2dAERidd:
.LFB3920:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$64, %rsp
	.cfi_def_cfa_offset 80
	movl	(%rsi), %ecx
	movl	$3, %esi
	movsd	%xmm0, 8(%rsp)
	leaq	40(%rsp), %rbx
	movsd	%xmm1, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leal	2(%rcx), %eax
	cltd
	idivl	%esi
	leal	1(%rcx), %eax
	movslq	%edx, %rdx
	movq	(%rdi,%rdx,8), %r8
	cltd
	idivl	%esi
	movslq	%edx, %rdx
	movq	(%rdi,%rdx,8), %rsi
	movq	%r8, %rdx
	movq	%rbx, %rdi
	call	_ZN7SegmentC1EP5PointS1_@PLT
	leaq	32(%rsp), %rdx
	leaq	24(%rsp), %rsi
	movq	%rbx, %rdi
	call	_ZN7Segment12scaledNormalEPdS0_@PLT
	movsd	8(%rsp), %xmm0
	movsd	(%rsp), %xmm1
	mulsd	24(%rsp), %xmm0
	mulsd	32(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	xorps	.LC2(%rip), %xmm0
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$64, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3920:
	.size	_ZN8Triangle2dAERidd, .-_ZN8Triangle2dAERidd
	.align 2
	.globl	_ZN8Triangle5gradXERi
	.type	_ZN8Triangle5gradXERi, @function
_ZN8Triangle5gradXERi:
.LFB3921:
	.cfi_startproc
	endbr64
	movsd	.LC3(%rip), %xmm0
	xorps	%xmm1, %xmm1
	jmp	_ZN8Triangle2dAERidd
	.cfi_endproc
.LFE3921:
	.size	_ZN8Triangle5gradXERi, .-_ZN8Triangle5gradXERi
	.align 2
	.globl	_ZN8Triangle5gradYERi
	.type	_ZN8Triangle5gradYERi, @function
_ZN8Triangle5gradYERi:
.LFB3922:
	.cfi_startproc
	endbr64
	movsd	.LC3(%rip), %xmm1
	xorps	%xmm0, %xmm0
	jmp	_ZN8Triangle2dAERidd
	.cfi_endproc
.LFE3922:
	.size	_ZN8Triangle5gradYERi, .-_ZN8Triangle5gradYERi
	.align 2
	.globl	_ZN8Triangle8containsER5Point
	.type	_ZN8Triangle8containsER5Point, @function
_ZN8Triangle8containsER5Point:
.LFB3923:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE3923:
	.size	_ZN8Triangle8containsER5Point, .-_ZN8Triangle8containsER5Point
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"should not get here"
	.text
	.align 2
	.globl	_ZN8Triangle9midVertexEv
	.type	_ZN8Triangle9midVertexEv, @function
_ZN8Triangle9midVertexEv:
.LFB3924:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3924
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	$3, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	16(%rdi), %rsi
	movq	8(%rdi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
.LEHB0:
	call	_ZN5Point8distanceERS_@PLT
	movq	16(%rbx), %rdi
	movq	(%rbx), %rsi
	movsd	%xmm0, 16(%rsp)
	call	_ZN5Point8distanceERS_@PLT
	movq	8(%rbx), %rsi
	movq	(%rbx), %rdi
	xorl	%ebx, %ebx
	movsd	%xmm0, 24(%rsp)
	call	_ZN5Point8distanceERS_@PLT
.LEHE0:
	movsd	%xmm0, 32(%rsp)
.L26:
	leal	2(%rbx), %eax
	movsd	16(%rsp,%rbx,8), %xmm2
	cltd
	idivl	%ebp
	movsd	%xmm2, (%rsp)
	leal	1(%rbx), %eax
	movslq	%edx, %rdx
	movsd	16(%rsp,%rdx,8), %xmm3
	cltd
	idivl	%ebp
	movaps	%xmm3, %xmm0
	movq	%xmm3, %r14
	movslq	%edx, %rdx
	movsd	16(%rsp,%rdx,8), %xmm1
	movsd	%xmm1, 8(%rsp)
	call	fmin@PLT
	movsd	(%rsp), %xmm4
	comisd	%xmm0, %xmm4
	jb	.L23
	movsd	8(%rsp), %xmm1
	movq	%r14, %xmm0
	call	fmax@PLT
	comisd	(%rsp), %xmm0
	jb	.L23
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	jmp	.L35
.L23:
	incq	%rbx
	cmpq	$3, %rbx
	jne	.L26
	movl	$16, %edi
	call	__cxa_allocate_exception@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	movq	%rax, %rbx
.LEHB1:
	call	_ZNSt13runtime_errorC1EPKc@PLT
.LEHE1:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	movq	_ZNSt13runtime_errorD1Ev@GOTPCREL(%rip), %rdx
	leaq	_ZTISt13runtime_error(%rip), %rsi
	movq	%rbx, %rdi
.LEHB2:
	call	__cxa_throw@PLT
.L31:
	endbr64
	movq	%rax, %rbp
.L28:
	movq	%rbx, %rdi
	call	__cxa_free_exception@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L35
	movq	%rbp, %rdi
	call	_Unwind_Resume@PLT
.LEHE2:
.L35:
	call	__stack_chk_fail@PLT
.L30:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3924:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3924:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3924-.LLSDACSB3924
.LLSDACSB3924:
	.uleb128 .LEHB0-.LFB3924
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3924
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L31-.LFB3924
	.uleb128 0
	.uleb128 .LEHB2-.LFB3924
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3924:
	.text
	.size	_ZN8Triangle9midVertexEv, .-_ZN8Triangle9midVertexEv
	.align 2
	.globl	_ZN8Triangle9maxLengthEv
	.type	_ZN8Triangle9maxLengthEv, @function
_ZN8Triangle9maxLengthEv:
.LFB3925:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorps	%xmm1, %xmm1
	movl	$3, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
.L39:
	movl	%ebx, %eax
	incl	%ebx
	movsd	%xmm1, 8(%rsp)
	addl	$2, %eax
	cltd
	idivl	%r12d
	movl	%ebx, %eax
	movslq	%edx, %rdx
	movq	0(%rbp,%rdx,8), %rsi
	cltd
	idivl	%r12d
	movslq	%edx, %rdx
	movq	0(%rbp,%rdx,8), %rdi
	call	_ZN5Point8distanceERS_@PLT
	movsd	8(%rsp), %xmm1
	call	fmax@PLT
	movaps	%xmm0, %xmm1
	cmpl	$3, %ebx
	jne	.L39
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3925:
	.size	_ZN8Triangle9maxLengthEv, .-_ZN8Triangle9maxLengthEv
	.align 2
	.globl	_ZN8Triangle12copyVerticesEP5PointS1_S1_
	.type	_ZN8Triangle12copyVerticesEP5PointS1_S1_, @function
_ZN8Triangle12copyVerticesEP5PointS1_S1_:
.LFB3926:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	movups	(%rax), %xmm0
	movups	%xmm0, (%rsi)
	movw	16(%rax), %ax
	movw	%ax, 16(%rsi)
	movq	8(%rdi), %rax
	movups	(%rax), %xmm1
	movups	%xmm1, (%rdx)
	movw	16(%rax), %ax
	movw	%ax, 16(%rdx)
	movq	16(%rdi), %rax
	movups	(%rax), %xmm2
	movups	%xmm2, (%rcx)
	movw	16(%rax), %ax
	movw	%ax, 16(%rcx)
	ret
	.cfi_endproc
.LFE3926:
	.size	_ZN8Triangle12copyVerticesEP5PointS1_S1_, .-_ZN8Triangle12copyVerticesEP5PointS1_S1_
	.align 2
	.globl	_ZN8Triangle13getSignedAreaEP5PointS1_S1_
	.type	_ZN8Triangle13getSignedAreaEP5PointS1_S1_, @function
_ZN8Triangle13getSignedAreaEP5PointS1_S1_:
.LFB3927:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdx, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, 8(%rsp)
	call	_ZNK5Point4getXEv@PLT
	movq	8(%rsp), %rdi
	movsd	%xmm0, 40(%rsp)
	call	_ZNK5Point4getYEv@PLT
	movq	%rbp, %rdi
	movsd	%xmm0, 32(%rsp)
	call	_ZNK5Point4getXEv@PLT
	movq	%rbp, %rdi
	movsd	%xmm0, 24(%rsp)
	call	_ZNK5Point4getYEv@PLT
	movq	%rbx, %rdi
	movsd	%xmm0, 16(%rsp)
	call	_ZNK5Point4getXEv@PLT
	movq	%rbx, %rdi
	movsd	%xmm0, 8(%rsp)
	call	_ZNK5Point4getYEv@PLT
	movsd	40(%rsp), %xmm5
	movsd	32(%rsp), %xmm4
	movsd	24(%rsp), %xmm1
	movsd	8(%rsp), %xmm2
	movsd	16(%rsp), %xmm3
	subsd	%xmm4, %xmm0
	subsd	%xmm5, %xmm1
	subsd	%xmm5, %xmm2
	subsd	%xmm4, %xmm3
	mulsd	%xmm1, %xmm0
	movaps	%xmm2, %xmm1
	mulsd	%xmm3, %xmm1
	subsd	%xmm1, %xmm0
	mulsd	.LC0(%rip), %xmm0
	addq	$56, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3927:
	.size	_ZN8Triangle13getSignedAreaEP5PointS1_S1_, .-_ZN8Triangle13getSignedAreaEP5PointS1_S1_
	.section	.rodata.str1.1
.LC5:
	.string	"Triangle "
.LC6:
	.string	" "
.LC7:
	.string	"\n"
	.text
	.globl	_ZlsRSoRK8Triangle
	.type	_ZlsRSoRK8Triangle, @function
_ZlsRSoRK8Triangle:
.LFB3928:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$9, %edx
	leaq	.LC6(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	leaq	.LC5(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
.L46:
	movq	(%r12,%rbp), %rsi
	movq	%rbx, %rdi
	addq	$8, %rbp
	call	_ZlsRSoRK5Point@PLT
	movl	$1, %edx
	movq	%r13, %rsi
	movq	%rax, %rdi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	cmpq	$24, %rbp
	jne	.L46
	movl	$1, %edx
	movq	%rbx, %rdi
	leaq	.LC7(%rip), %rsi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3928:
	.size	_ZlsRSoRK8Triangle, .-_ZlsRSoRK8Triangle
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3954:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3954:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1071644672
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC3:
	.long	0
	.long	1072693248
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#ifndef triangle_cuh
#define triangle_cuh

#ifdef __HIPCC__
#define CUDA_HOSTDEV __host__ __device__
#define CUDA_DEV __device__
#else
#define CUDA_HOSTDEV
#define CUDA_DEV
#endif

#include <math.h>
#include "point.cuh"
#include "segment.cuh"

/**
 * represent a triangle whose vertices are movable
 */

class Triangle {
	private:
		Point* vertices[3];
	public:
		// construct from three point pointers and orient in ccw direction
		Triangle(Point *a, Point *b, Point *c);
		CUDA_HOSTDEV double getArea();
		// get signed area based on the order of vertices
		// with ccw direction positive
		CUDA_HOSTDEV double getSignedArea();
		// get the change in area when the pth vertex is moving at velocity (vx, vy)
		double dA(int &p, double vx, double vy);
		// get the gradient in the x direction for pth vertex
		double gradX(int &p);
		// get the gradient in the y direction for pth vertex
		double gradY(int &p);

		// determine if triangle contains point p, including boundary points
		CUDA_DEV bool contains(Point &p);

		// return index of vertex opposite the middle length side
		int midVertex();
		// return length of longest side
		double maxLength();

		// get vertices of triangle, store in a, b, c
		void copyVertices(Point *a, Point *b, Point *c);

		// static signed area function
		CUDA_HOSTDEV static double getSignedArea(Point *a, Point *b, Point *c);

		friend ostream& operator<<(ostream& os, const Triangle &t);
		
		friend class Approx;
		friend class ParallelIntegrator;
		friend class Pixel;
};

#endif

	.text
	.file	"triangle.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
