<?xml version="1.0" encoding="UTF-8"?>
<fib_object
			  xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
			  xmlns="http://www.fib-development.org/"
			  xsd:schemaLocation="http://www.fib-development.org/fib.xsd">
	<root>
		<multimedia_info fib_version="3" db_version="2"/>
		<optionalpart>
			<pair key="name" value="evalue fraction"/>
			<pair key="description" value="This object evalues wich part / fraction of a given box is below a line f(x) = a_0 + a_1 * x (e. g. for antialising). (The box (x_1, x_2, y_1, y_2) goes in the first dimension from x_1 to x_2 and in the second dimension from y_1 to y_2 .)"/>
			<pair key="inVar1::description" value="the first parameter a_0 for the line f(x)"/>
			<pair key="inVar2::description" value="the slope or gradien (second parameter) a_1 for the line f(x)"/>
			<pair key="inVar3::description" value="first border in dimension 1 (x_1)"/>
			<pair key="inVar4::description" value="second border in dimension 1 (x_2)"/>
			<pair key="inVar5::description" value="first border in dimension 2 (y_1)"/>
			<pair key="inVar6::description" value="second border in dimension 2 (y_2)"/>
			<pair key="subObj1::description" value="the object for the to return part / fraction of a given box is below a line f(x) = a_0 + a_1 * x"/>
			<pair key="subObj1::outVar1::description" value="the part / fraction of a given box which is below a line f(x) = a_0 + a_1 * x"/>
			<pair key="author" value="Betti Oesterholz"/>
			<pair key="author::email" value="Oesterholz@Fib-Development.org"/>
			<pair key="copyright" value="LGPL3"/>
		</optionalpart>
		<input_variables>
			<variable number="1" default="0"/>
			<variable number="2" default="0"/>
			<variable number="3" default="0"/>
			<variable number="4" default="0"/>
			<variable number="5" default="0"/>
			<variable number="6" default="0"/>
		</input_variables>
		<domains>
			<inVar number="3">
				<domainReference subdomain="1">
					<dim count="2">
						<dimension number="1" direction="anywhere"/>
						<dimension number="2" direction="anywhere"/>
					</dim>
				</domainReference>
			</inVar>
			<inVar number="4">
				<domainReference subdomain="1">
					<dim count="2">
						<dimension number="1" direction="anywhere"/>
						<dimension number="2" direction="anywhere"/>
					</dim>
				</domainReference>
			</inVar>
			<inVar number="5">
				<domainReference subdomain="2">
					<dim count="2">
						<dimension number="1" direction="anywhere"/>
						<dimension number="2" direction="anywhere"/>
					</dim>
				</domainReference>
			</inVar>
			<inVar number="6">
				<domainReference subdomain="2">
					<dim count="2">
						<dimension number="1" direction="anywhere"/>
						<dimension number="2" direction="anywhere"/>
					</dim>
				</domainReference>
			</inVar>
			<externSubobject number="1">
				<vector elements="1">
					<!--actually any number is possible;
						the next line is just a space holder-->
					<naturalNumberB bit="0" />
				</vector>
			</externSubobject>
			<externObject>
				<vector elements="4">
					<integer min="1" max="1" /><!--Identifier-->
					<integer min="6" max="6" /><!--number input values-->
					<naturalNumber max="1" /><!--number subobjects-->
					<naturalNumber max="1" /><!--number output values-->
				</vector>
			</externObject>
			<externObjectInput identifier="1">
				<vector elements="6">
					<naturalNumber max="0" />
					<naturalNumber max="0" />
					<naturalNumber max="0" />
					<naturalNumber max="0" />
					<naturalNumber max="0" />
					<naturalNumber max="0" />
				</vector>
			</externObjectInput>
			<subfunction>
				<integer min="-1" max="2" />
			</subfunction>
		</domains>
		<main_fib_object>
			<!--step 1: - convert problem so that all lines are rising
				( if (a_1 < 1) then a*_1 = -1 * a_1 and x* = -1 * x ),
				so that for step 2 just 4 cases remain (out of 8)
				- order the box borders (if x_2 < x_1 and / or id y_2 < y_1 -> switch them)
			step 2: seperate the problem into 4 cases, depending on which
				border lines of the box are intersected by the line f:
				- case 1 intersecting bottom and top border
				- case 2 intersecting bottom and right border (fraction given by triangle area)
				- case 3 intersecting left and top border (fraction given by box area minus triangle area)
				- case 4 intersecting left and right border
			-->
			<!-- order the box borders (if x_2 < x_1 and id y_2 < y_1 -> switch them) -->
			<function define_variable="7">
				<!-- x*_1 = min( x_1, x_2 )-->
				<subfunction>
					<min>
						<variable>3</variable>
						<variable>4</variable>
					</min>
				</subfunction>
				<function define_variable="8">
					<!-- x*_2 = max( x_1, x_2 )-->
					<subfunction>
						<max>
							<variable>3</variable>
							<variable>4</variable>
						</max>
					</subfunction>
					<function define_variable="9">
						<!-- y*_1 = min( y_1, y_2 )-->
						<subfunction>
							<min>
								<variable>5</variable>
								<variable>6</variable>
							</min>
						</subfunction>
						<function define_variable="10">
							<!-- y*_2 = max( y_1, y_2 )-->
							<subfunction>
								<max>
									<variable>5</variable>
									<variable>6</variable>
								</max>
							</subfunction>
							<if><!--positive slope a_1 do nothing else convert problem-->
								<condition>
									<not>
										<lo>
											<variable>2</variable>
											<value>0</value>
										</lo>
									</not>
								</condition>
								<obj identifier="1">
									<vector type="externObjectInput">
										<variable>1</variable>
										<variable>2</variable>
										<variable>7</variable>
										<variable>8</variable>
										<variable>9</variable>
										<variable>10</variable>
									</vector>
									<subobject>
										<output_variables>
											<variable>11</variable>
										</output_variables>
										<subobject number="1">
											<vector type="externSubobject">
												<variable>11</variable>
											</vector>
										</subobject>
									</subobject>
								</obj>
								<!--else negative slope a_1-> a*_1 = -1 * a_1 and x* = -1 * x-->
								<function define_variable="11">
									<!-- a*_1 = -1 * a_1 -->
									<subfunction>
										<mult>
											<variable>2</variable>
											<value>-1</value>
										</mult>
									</subfunction>
									<function define_variable="12">
										<!-- x*_1 = -1 * x_2 -->
										<subfunction>
											<mult>
												<variable>8</variable>
												<value>-1</value>
											</mult>
										</subfunction>
										<function define_variable="13">
											<!-- x*_2 = -1 * x_1 -->
											<subfunction>
												<mult>
													<variable>7</variable>
													<value>-1</value>
												</mult>
											</subfunction>
											<obj identifier="1">
												<vector type="externObjectInput">
													<variable>1</variable>
													<variable>11</variable>
													<variable>12</variable>
													<variable>13</variable>
													<variable>9</variable>
													<variable>10</variable>
												</vector>
												<subobject>
													<output_variables>
														<variable>14</variable>
													</output_variables>
													<subobject number="1">
														<vector type="externSubobject">
															<variable>14</variable>
														</vector>
													</subobject>
												</subobject>
											</obj>
										</function>
									</function>
								</function>
							</if>
						</function>
					</function>
				</function>
			</function>
		</main_fib_object>
		<sub_roots>
			<sub_root identifier="1">
				<root>
					<optionalpart>
						<pair key="description" value="This object evalues wich part / fraction of a given box is below a line f(x) = a_0 + a_1 * x (e. g. for antialising). (The box (x_1, x_2, y_1, y_2) goes in the first dimension from x_1 to x_2 and in the second dimension from y_1 to y_2, with x_1 lower or equal x_2 and y_1 lower or equal y_2 .) It is a help object for the main Fib object."/>
						<pair key="inVar1::description" value="the first parameter a_0 for the line f(x)"/>
						<pair key="inVar2::description" value="the positive slope or gradien (second parameter) a_1 for the line f(x)"/>
						<pair key="inVar3::description" value="first border in dimension 1 (x_1)"/>
						<pair key="inVar4::description" value="second border in dimension 1 (x_2)"/>
						<pair key="inVar5::description" value="first border in dimension 2 (y_1)"/>
						<pair key="inVar6::description" value="second border in dimension 2 (y_2)"/>
						<pair key="subObj1::description" value="the object for the to return part / fraction of a given box is below a line f(x) = a_0 + a_1 * x"/>
						<pair key="subObj1::outVar1::description" value="the part / fraction of a given box which is below a line f(x) = a_0 + a_1 * x"/>
					</optionalpart>
					<input_variables>
						<variable number="1" default="0"/>
						<variable number="2" default="0"/>
						<variable number="3" default="0"/>
						<variable number="4" default="0"/>
						<variable number="5" default="0"/>
						<variable number="6" default="0"/>
					</input_variables>
					<domains>
						<inVar number="3">
							<domainReference subdomain="1">
								<dim count="2">
									<dimension number="1" direction="anywhere"/>
									<dimension number="2" direction="anywhere"/>
								</dim>
							</domainReference>
						</inVar>
						<inVar number="4">
							<domainReference subdomain="1">
								<dim count="2">
									<dimension number="1" direction="anywhere"/>
									<dimension number="2" direction="anywhere"/>
								</dim>
							</domainReference>
						</inVar>
						<inVar number="5">
							<domainReference subdomain="2">
								<dim count="2">
									<dimension number="1" direction="anywhere"/>
									<dimension number="2" direction="anywhere"/>
								</dim>
							</domainReference>
						</inVar>
						<inVar number="6">
							<domainReference subdomain="2">
								<dim count="2">
									<dimension number="1" direction="anywhere"/>
									<dimension number="2" direction="anywhere"/>
								</dim>
							</domainReference>
						</inVar>
						<externSubobject number="1">
							<vector elements="1">
								<!--actually any number is possible;
									the next line is just a space holder-->
								<naturalNumberB bit="0" />
							</vector>
						</externSubobject>
					</domains>
					<main_fib_object>
						<!--step 2: seperate the problem into 4 cases, depending on which
						border lines of the box are intersected by the line f:
						- case 1 intersecting bottom and top border
						- case 2 intersecting bottom and right border (fraction given by triangle area)
						- case 3 intersecting left and top border (fraction given by box area minus triangle area)
						- case 4 intersecting left and right border
						-->
						<function define_variable="7">
							<!--evalue f(x_1) = a_0 + a_1 * x_1 = left border -->
							<subfunction>
								<add>
									<variable>1</variable>
									<mult>
										<variable>2</variable>
										<variable>3</variable>
									</mult>
								</add>
							</subfunction>
							<if><!-- if y_2 <= f(x_1) -> line above box -> area is box area -->
								<condition>
									<not>
										<lo>
											<variable>7</variable>
											<variable>6</variable>
										</lo>
									</not>
								</condition>
								<function define_variable="8">
									<!-- A = ( x_2 - x_1 ) * ( y_2 - y_1 ) -->
									<subfunction>
										<mult>
											<sub>
												<variable>4</variable>
												<variable>3</variable>
											</sub>
											<sub>
												<variable>6</variable>
												<variable>5</variable>
											</sub>
										</mult>
									</subfunction>
									<subobject number="1">
										<vector type="externSubobject">
											<variable>8</variable>
										</vector>
									</subobject>
								</function>
								<function define_variable="8">
									<!--evalue f( x_2 ) = a_0 + a_1 * x_2 = right border -->
									<subfunction>
										<add>
											<variable>1</variable>
											<mult>
												<variable>2</variable>
												<variable>4</variable>
											</mult>
										</add>
									</subfunction>
									<if><!-- if f(x_2) <= y_1 -> line below box -> area is 0 -->
										<condition>
											<not>
												<lo>
													<variable>5</variable>
													<variable>8</variable>
												</lo>
											</not>
										</condition>
										<subobject number="1">
											<vector type="externSubobject">
												<value>0</value>
											</vector>
										</subobject>
										<!-- line intersecting box -->
										<if><!-- if f(x_1) < y_1 -> intersecting bottom -->
											<condition>
												<lo>
													<variable>7</variable>
													<variable>5</variable>
												</lo>
											</condition>
											<!-- intersecting bottom -->
											<function define_variable="9">
												<!--evalue intersection with bottom border: f( y_1 ) = (y_1 - a_0) / a_1 -->
												<subfunction>
													<div>
														<sub>
															<variable>5</variable>
															<variable>1</variable>
														</sub>
														<variable>2</variable>
													</div>
												</subfunction>
												<if><!-- if f( x_2 ) < y_2 -> not intersecting top border -> intersecting right border -->
													<condition>
														<lo>
															<variable>8</variable>
															<variable>6</variable>
														</lo>
													</condition>
													<!--- case 2 intersecting bottom and right border (fraction given by triangle area)-->
													<function define_variable="10">
														<!-- A = ( ( x_2 - f(y_1) ) * ( f( x_2) - y_1 ) ) / 2 -->
														<subfunction>
															<div>
																<mult>
																	<sub>
																		<variable>4</variable>
																		<variable>9</variable>
																	</sub>
																	<sub>
																		<variable>8</variable>
																		<variable>5</variable>
																	</sub>
																</mult>
																<value>2</value>
															</div>
														</subfunction>
														<subobject number="1">
															<vector type="externSubobject">
																<variable>10</variable>
															</vector>
														</subobject>
													</function>
													<!-- else case 1 intersecting bottom and top border -->
													<function define_variable="10">
														<!-- A = (y_2 - y_1)  * ( x_2 - ( f( y_1 ) + f( y_2 ) ) / 2 )-->
														<subfunction>
															<mult>
																<sub>
																	<variable>6</variable>
																	<variable>5</variable>
																</sub>
																<sub>
																	<variable>4</variable>
																	<div>
																		<add>
																			<variable>9</variable>
																			<!--evalue intersection with top border: f( y_2 ) = ( y_2 - a_0) / a_1 -->
																			<div>
																				<sub>
																					<variable>6</variable>
																					<variable>1</variable>
																				</sub>
																				<variable>2</variable>
																			</div>
																		</add>
																		<value>2</value>
																	</div>
																</sub>
															</mult>
														</subfunction>
														<subobject number="1">
															<vector type="externSubobject">
																<variable>10</variable>
															</vector>
														</subobject>
													</function>
												</if>
											</function>
										<!-- else f(x) > y -> not intersecting bottom -->
											<if><!-- if f( x_2 ) < y_2 -> not intersecting top border -> intersecting right border -->
												<condition>
													<lo>
														<variable>8</variable>
														<variable>6</variable>
													</lo>
												</condition>
												<!-- case 4 intersecting left and right border -->
												<function define_variable="9">
													<!-- A = ( x_2 - x_1 ) * ( ( f( x_1 ) + f( x_2 )) / 2 - y_1 ) -->
													<subfunction>
														<mult>
															<sub>
																<variable>4</variable>
																<variable>3</variable>
															</sub>
															<sub>
																<div>
																	<add>
																		<variable>7</variable>
																		<variable>8</variable>
																	</add>
																	<value>2</value>
																</div>
																<variable>5</variable>
															</sub>
														</mult>
													</subfunction>
													<subobject number="1">
														<vector type="externSubobject">
															<variable>9</variable>
														</vector>
													</subobject>
												</function>
												<!-- else case 3 intersecting left and top border (fraction given by box area minus triangle area) -->
												<function define_variable="9">
													<!-- A = ( x_2 - x_1 ) * ( y_2 - y_1 ) - ( ( y_2 - f(x_1) ) * ( f( y_2 ) - x_1 ) ) / 2 -->
													<subfunction>
														<sub>
															<mult>
																<sub>
																	<variable>4</variable>
																	<variable>3</variable>
																</sub>
																<sub>
																	<variable>6</variable>
																	<variable>5</variable>
																</sub>
															</mult>
															<div>
																<mult>
																	<sub>
																		<variable>6</variable>
																		<variable>7</variable>
																	</sub>
																	<sub>
																		<!--evalue intersection with top border: f( y_2 ) = (y_2 - a_0) / a_1 -->
																		<div>
																			<sub>
																				<variable>6</variable>
																				<variable>1</variable>
																			</sub>
																			<variable>2</variable>
																		</div>
																		<variable>3</variable>
																	</sub>
																</mult>
																<value>2</value>
															</div>
														</sub>
													</subfunction>
													<subobject number="1">
														<vector type="externSubobject">
															<variable>9</variable>
														</vector>
													</subobject>
												</function>
											</if>
										</if>
									</if>
								</function>
							</if>
						</function>
					</main_fib_object>
				</root>
			</sub_root>
		</sub_roots>
	</root>
</fib_object>