

'''simple docstring'''







import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


_lowerCamelCase    =  1_0_0_0
class 					__a   :

						def __init__(		self	:						Dict    ,			lowercase__	:						Optional[Any]    ,			lowercase__	:						Any=1.2    ,			lowercase__	:						List[str]="g"    ,			lowercase__	:						Tuple=0.5    ,			lowercase__	:						Tuple="-"    ,			lowercase__	:						List[str]="test_out.jpg"    ,			lowercase__	:						Union[str, Any]=True    ,			lowercase__	:						int=False    ,			lowercase__	:						Tuple=None    ,			lowercase__	:						List[str]=None    ,			lowercase__	:						List[str]=0.7    ,			)						->Dict:

							"""simple docstring"""



							if isinstance(lowercase__    ,			torch.Tensor):
								_lowercase							=     img.numpy().astype("""np.uint8""")
							if isinstance(lowercase__    ,			lowercase__):
								_lowercase							=     img_tensorize(lowercase__)
							assert isinstance(lowercase__    ,			np.ndarray)

							_lowercase		,		_lowercase							=     img.shape[1], img.shape[0]
							_lowercase							=     mplfigure.Figure(frameon=lowercase__)
							_lowercase							=     fig.get_dpi()
							_lowercase							=     (width * scale + 1e-2) / dpi
							_lowercase							=     (height * scale + 1e-2) / dpi
							fig.set_size_inches(lowercase__    ,			lowercase__)
							_lowercase							=     fig.add_axes([0.0, 0.0, 1.0, 1.0])
							ax.axis("""off""")
							ax.set_xlim(0.0    ,			lowercase__)
							ax.set_ylim(lowercase__)

							_lowercase							=     saveas
							_lowercase							=     rgb
							_lowercase							=     pynb
							_lowercase							=     img
							_lowercase							=     edgecolor
							_lowercase							=     0.5
							_lowercase							=     linestyle
							_lowercase							=     int(np.sqrt(min(lowercase__    ,			lowercase__)) * scale // 3)
							_lowercase							=     width
							_lowercase							=     height
							_lowercase							=     scale
							_lowercase							=     fig
							_lowercase							=     ax
							_lowercase							=     pad
							_lowercase							=     idaobj
							_lowercase							=     idaattr
							_lowercase							=     FigureCanvasAgg(lowercase__)

						def 	_UpperCAmelCase							(		self	:						int    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						List[Any]=None)						->Tuple:

							"""simple docstring"""



							if color is None:
								_lowercase							=     self.edgecolor
							((_lowercase)		,		(_lowercase)		,		(_lowercase)		,		(_lowercase))							=     box
							_lowercase							=     xa - xa
							_lowercase							=     ya - ya
							self.ax.add_patch(
							    mpl.patches.Rectangle(
							        (xa, ya)    ,			lowercase__    ,			lowercase__    ,			fill=lowercase__    ,			edgecolor=lowercase__    ,			linewidth=self.font_size // 3    ,			alpha=self.alpha    ,			linestyle=self.linestyle    ,			))

						def 	_UpperCAmelCase							(		self	:						Tuple    ,			lowercase__	:						Tuple    ,			lowercase__	:						Optional[Any]=None    ,			lowercase__	:						Optional[int]=None    ,			lowercase__	:						Optional[int]=None    ,			lowercase__	:						Dict=None)						->Tuple:

							"""simple docstring"""



							if len(boxes.shape) > 2:
								_lowercase							=     boxes[0]
							if len(obj_ids.shape) > 1:
								_lowercase							=     obj_ids[0]
							if len(obj_scores.shape) > 1:
								_lowercase							=     obj_scores[0]
							if len(attr_ids.shape) > 1:
								_lowercase							=     attr_ids[0]
							if len(attr_scores.shape) > 1:
								_lowercase							=     attr_scores[0]
							if isinstance(lowercase__    ,			torch.Tensor):
								_lowercase							=     boxes.numpy()
							if isinstance(lowercase__    ,			lowercase__):
								_lowercase							=     np.array(lowercase__)
							assert isinstance(lowercase__    ,			np.ndarray)
							_lowercase							=     np.prod(boxes[:, 2:] - boxes[:, :2]    ,			axis=1)
							_lowercase							=     np.argsort(-areas).tolist()
							_lowercase							=     boxes[sorted_idxs] if boxes is not None else None
							_lowercase							=     obj_ids[sorted_idxs] if obj_ids is not None else None
							_lowercase							=     obj_scores[sorted_idxs] if obj_scores is not None else None
							_lowercase							=     attr_ids[sorted_idxs] if attr_ids is not None else None
							_lowercase							=     attr_scores[sorted_idxs] if attr_scores is not None else None

							_lowercase							=     [self._random_color(maximum=1) for _ in range(len(lowercase__))]
							_lowercase							=     [assigned_colors[idx] for idx in sorted_idxs]
							if obj_ids is not None:
								_lowercase							=     self._create_text_labels_attr(lowercase__    ,			lowercase__    ,			lowercase__    ,			lowercase__)
								for i in range(len(lowercase__)):
									_lowercase							=     assigned_colors[i]
									self.add_box(boxes[i]    ,			lowercase__)
									self.draw_labels(labels[i]    ,			boxes[i]    ,			lowercase__)

						def 	_UpperCAmelCase							(		self	:						Union[str, Any]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Any    ,			lowercase__	:						Optional[int])						->int:

							"""simple docstring"""



							_lowercase		,		_lowercase		,		_lowercase		,		_lowercase							=     box
							_lowercase							=     (xa, ya)
							_lowercase							=     (ya - ya) * (xa - xa)
							_lowercase							=     _SMALL_OBJ * self.scale
							if instance_area < small or ya - ya < 40 * self.scale:
								if ya >= self.height - 5:
									_lowercase							=     (xa, ya)
								else:
									_lowercase							=     (xa, ya)

							_lowercase							=     (ya - ya) / np.sqrt(self.height * self.width)
							_lowercase							=     self._change_color_brightness(lowercase__    ,			brightness_factor=0.7)
							_lowercase							=     np.clip((height_ratio - 0.02) / 0.08 + 1    ,			1.2    ,			2)
							font_size *= 0.75 * self.font_size

							self.draw_text(
							    text=lowercase__    ,			position=lowercase__    ,			color=lowercase__    ,			)

						def 	_UpperCAmelCase							(		self	:						Dict    ,			lowercase__	:						List[str]    ,			lowercase__	:						Dict    ,			lowercase__	:						Optional[Any]="g"    ,			lowercase__	:						Optional[int]="left"    ,			)						->Union[str, Any]:

							"""simple docstring"""



							_lowercase							=     0
							_lowercase							=     self.font_size
							_lowercase							=     np.maximum(list(mplc.to_rgb(lowercase__))    ,			0.2)
							_lowercase							=     max(0.8    ,			np.max(lowercase__))
							_lowercase							=     {
							    """facecolor""": """black""",
							    """alpha""": self.alpha,
							    """pad""": self.pad,
							    """edgecolor""": """none""",
							}
							_lowercase		,		_lowercase							=     position
							self.ax.text(
							    lowercase__    ,			lowercase__    ,			lowercase__    ,			size=font_size * self.scale    ,			family="""sans-serif"""    ,			bbox=lowercase__    ,			verticalalignment="""top"""    ,			horizontalalignment=lowercase__    ,			color=lowercase__    ,			zorder=10    ,			rotation=lowercase__    ,			)

						def 	_UpperCAmelCase							(		self	:						Dict    ,			lowercase__	:						str=None)						->Dict:

							"""simple docstring"""



							if saveas is None:
								_lowercase							=     self.saveas
							if saveas.lower().endswith(""".jpg""") or saveas.lower().endswith(""".png"""):
								cva.imwrite(
								    lowercase__    ,			self._get_buffer()[:, :, ::-1]    ,			)
							else:
								self.fig.savefig(lowercase__)

						def 	_UpperCAmelCase							(		self	:						Dict    ,			lowercase__	:						int    ,			lowercase__	:						str    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						Tuple)						->int:

							"""simple docstring"""



							_lowercase							=     [self.idaobj[i] for i in classes]
							_lowercase							=     [self.idaattr[i] for i in attr_classes]
							_lowercase							=     [
							    f"""{label} {score:.2f} {attr} {attr_score:.2f}"""
							    for label, score, attr, attr_score in zip(lowercase__    ,			lowercase__    ,			lowercase__    ,			lowercase__)
							]
							return labels

						def 	_UpperCAmelCase							(		self	:						str    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Optional[Any])						->Tuple:

							"""simple docstring"""



							_lowercase							=     [self.idaobj[i] for i in classes]
							if scores is not None:
								if labels is None:
									_lowercase							=     ["""{:.0f}%""".format(s * 1_00) for s in scores]
								else:
									_lowercase							=     ["""{} {:.0f}%""".format(lowercase__    ,			s * 1_00) for li, s in zip(lowercase__    ,			lowercase__)]
							return labels

						def 	_UpperCAmelCase							(		self	:						List[Any]    ,			lowercase__	:						str=2_55)						->Tuple:

							"""simple docstring"""



							_lowercase							=     np.random.randint(0    ,			len(_COLORS))
							_lowercase							=     _COLORS[idx] * maximum
							if not self.rgb:
								_lowercase							=     ret[::-1]
							return ret

						def 	_UpperCAmelCase							(		self	:						str)						->str:

							"""simple docstring"""



							if not self.pynb:
								_lowercase		,		_lowercase							=     self.canvas.print_to_buffer()
								if (width, height) != (self.width, self.height):
									_lowercase							=     cva.resize(self.img    ,			(width, height))
								else:
									_lowercase							=     self.img
							else:
								_lowercase							=     io.BytesIO()  # works for cairo backend
								self.canvas.print_rgba(lowercase__)
								_lowercase		,		_lowercase							=     self.width, self.height
								_lowercase							=     buf.getvalue()
								_lowercase							=     self.img

							_lowercase							=     np.frombuffer(lowercase__    ,			dtype="""uint8""")
							_lowercase							=     buffer.reshape(lowercase__    ,			lowercase__    ,			4)
							_lowercase		,		_lowercase							=     np.split(lowercase__    ,			[3]    ,			axis=2)

							try:
								import numexpr as ne  # fuse them with numexpr

								_lowercase							=     ne.evaluate("""img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)""")
							except ImportError:
								_lowercase							=     alpha.astype("""float32""") / 255.0
								_lowercase							=     img * (1 - alpha) + rgb * alpha

							return visualized_image.astype("""uint8""")


						def 	_UpperCAmelCase							(		self	:						str    ,			lowercase__	:						Dict    ,			lowercase__	:						str)						->List[Any]:

							"""simple docstring"""



							assert brightness_factor >= -1.0 and brightness_factor <= 1.0
							_lowercase							=     mplc.to_rgb(lowercase__)
							_lowercase							=     colorsys.rgb_to_hls(*mplc.to_rgb(lowercase__))
							_lowercase							=     polygon_color[1] + (brightness_factor * polygon_color[1])
							_lowercase							=     0.0 if modified_lightness < 0.0 else modified_lightness
							_lowercase							=     1.0 if modified_lightness > 1.0 else modified_lightness
							_lowercase							=     colorsys.hls_to_rgb(polygon_color[0]    ,			lowercase__    ,			polygon_color[2])
							return modified_color






_lowerCamelCase    =  (
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)







'''simple docstring'''







from __future__ import annotations

from pathlib import Path






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	return pointa[0] * pointa[1] - pointa[1] * pointa[0]






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_							,       snake_case_							,       snake_case_							,       snake_case_							,       snake_case_	):
	_lowercase							=     (xa, ya)
	_lowercase							=     (xa - xa, ya - ya)
	_lowercase							=     (xa - xa, ya - ya)
	_lowercase							=     -vector_product(snake_case_							,       snake_case_	) / vector_product(
	    snake_case_							,       snake_case_	)
	_lowercase							=     +vector_product(snake_case_							,       snake_case_	) / vector_product(
	    snake_case_							,       snake_case_	)

	return a > 0 and b > 0 and a + b < 1






def 					_SCREAMING_SNAKE_CASE		(						snake_case_ = "p102_triangles.txt"	):
	_lowercase							=     Path(snake_case_	).parent.joinpath(snake_case_	).read_text(encoding="""utf-8"""	)

	_lowercase							=     []
	for line in data.strip().split("""\n"""	):
		triangles.append([int(snake_case_	) for number in line.split(""","""	)]	)

	_lowercase							=     0
	_lowercase							=     42

	for triangle in triangles:
		ret += contains_origin(*snake_case_	)

	return ret


if __name__ == "__main__":
							print(F"""{solution() = }""")




