def Rectangle(*args, **arg): """ INPUT: - ``NW,SE`` - the North-West corner and South-East corner Alternatively, you can pass a bounding box as unique argument. Still alternatively, you can pass xmin,ymin,xmax,ymax """ from yanntricks.src.BoundingBox import BoundingBox if len(args) == 2: NW = args[0] SE = args[1] if len(args) == 1: NW = args[0].NW() SE = args[0].SE() if "xmin" in arg: bb = BoundingBox(xmin=arg["xmin"], ymin=arg["ymin"], xmax=arg["xmax"], ymax=arg["ymax"]) # TODO : I should be able to pass directly the dictionary to BoundingBox NW = bb.getVertex("NW") SE = bb.getVertex("SE") if "mx" in arg: bb = BoundingBox(xmin=arg["mx"], ymin=arg["my"], xmax=arg["Mx"], ymax=arg["My"]) # TODO : I should be able to pass directly the dictionary to BoundingBox NW = bb.getVertex("NW") SE = bb.getVertex("SE") from yanntricks.src.RectangleGraph import RectangleGraph return RectangleGraph(NW, SE)
def bounding_box(self, pspict=None): """ Return the bounding box of the interpolation curve EXAMPLES:: sage: from yanntricks import * sage: print InterpolationCurve([Point(0,0),Point(1,1)]).bounding_box() <BoundingBox xmin=0.0,xmax=1.0; ymin=0.0,ymax=1.0> sage: C=Circle(Point(0,0),1) sage: n=400 sage: print InterpolationCurve([C.get_point(i*SR(360)/n,advised=False) for i in range(n)]).bounding_box() <BoundingBox xmin=-1.0,xmax=1.0; ymin=-1.0,ymax=1.0> NOTE:: Since the bounding box is computed from the give points while the curve is an interpolation, this bounding box is incorrect to the extend that \pscurve does not remains in the convex hull of the given points. EXAMPLE: sage: F=InterpolationCurve([Point(-1,1),Point(1,1),Point(1,-1),Point(-1,-1)]) sage: print F.bounding_box() <BoundingBox xmin=-1.0,xmax=1.0; ymin=-1.0,ymax=1.0> """ from yanntricks.src.point import Point from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox(Point(self.xmin(), self.ymin()), Point(self.xmax(), self.ymax())) return bb
def _bounding_box(self, pspict): from yanntricks.src.BoundingBox import BoundingBox from yanntricks.src.conversion_angles import simplify_degree a = simplify_degree(self.angleI, keep_max=True, number=True) b = simplify_degree(self.angleF, keep_max=True, number=True) if self.angleI < self.angleF: angleI = min(a, b) angleF = max(a, b) else: angleI = max(a, b) angleF = min(a, b) + 360 pI = self.get_point(angleI) pF = self.get_point(angleF) bb = BoundingBox(self.center, self.center) bb.append(pI, pspict) bb.append(pF, pspict) if angleI == 0: bb.addX(self.center.x + self.radius) if angleI < 90 and angleF > 90: bb.addY(self.center.y + self.radius) if angleI < 180 and angleF > 180: bb.addX(self.center.x - self.radius) if angleI < 270 and angleF > 270: bb.addY(self.center.y - self.radius) return bb
def __init__(self, bb=None): from yanntricks.src.BoundingBox import BoundingBox if bb is None: bb = BoundingBox() ObjectGraph.__init__(self, self) self.BB = bb self.separator_name = "GRID" # Default values, have to be integer. self.add_option({"Dx": 1, "Dy": 1}) self.Dx = self.options.DicoOptions["Dx"] self.Dy = self.options.DicoOptions["Dy"] self.num_subX = 2 self.num_subY = 2 self.draw_border = False self.draw_horizontal_grid = True self.draw_vertical_grid = True self.main_horizontal = Segment(Point(0, 1), Point(1, 1)) self.main_horizontal.parameters.color = "gray" self.main_horizontal.parameters.style = "solid" self.main_vertical = Segment(Point(0, 1), Point(1, 1)) self.main_vertical.parameters.color = "gray" self.main_vertical.parameters.style = "solid" self.sub_vertical = Segment(Point(0, 1), Point(1, 1)) self.sub_vertical.parameters.color = "gray" self.sub_vertical.parameters.style = "dotted" self.sub_horizontal = Segment(Point(0, 1), Point(1, 1)) self.sub_horizontal.parameters.color = "gray" self.sub_horizontal.parameters.style = "dotted" self.border = Segment(Point(0, 1), Point(1, 1)) self.border.parameters.color = "gray" self.border.parameters.style = "dotted"
def _bounding_box(self, pspict=None): """ Return the bounding box of the implicit curve. This is NOT the bounding box got that one could expect using Sage's plotting system implicit_plot(f,xrange,yrange).get_minmax_data() Instead the bounding box returned here only contains the points that are actually plotted. In the following example, we know that the ymax has to be half the sqrt of the radius (and not the 5 given in yrange). EXAMPLES:: sage: from yanntricks import * sage: x,y=var('x,y') sage: f=x**2+2*y**2 sage: G=ImplicitCurve(f==sqrt(2),(x,-5,5),(y,-5,5),plot_points=200) sage: print G.bounding_box() <BoundingBox xmin=-1.188,xmax=1.188; ymin=-0.841,ymax=0.841> """ from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox(Point(self.xmin(), self.ymin()), Point(self.xmax(), self.ymax())) return bb
def _bounding_box(self, pspict=None): """ return the bounding box of the point including its mark A small box of radius 0.1 (modulo xunit,yunit[1]) is given in any case. You need to provide a pspict in order to compute the size since it can vary from the place in your document you place the figure. [1] If you dont't know what is the "bounding box", or if you don't wan t to fine tune it, you don't care. """ from yanntricks.src.BoundingBox import BoundingBox if pspict == None: print("You should consider to give a Picture as argument. \ Otherwise the boundig box of %s could be bad" % str(self)) xunit = 1 yunit = 1 else: xunit = pspict.xunit yunit = pspict.yunit Xradius = 0.1 / xunit Yradius = 0.1 / yunit bb = BoundingBox(Point(self.x - Xradius, self.y - Yradius), Point(self.x + Xradius, self.y + Yradius)) for obj in self.added_objects[pspict]: bb.append(obj, pspict) return bb
def getSecondBox(self, pspict): from yanntricks.src.BoundingBox import BoundingBox xmin = min([el.getSecondBox(pspict).xmin for el in self]) ymin = min([el.getSecondBox(pspict).ymin for el in self]) xmax = max([el.getSecondBox(pspict).xmax for el in self]) ymax = max([el.getSecondBox(pspict).ymax for el in self]) return BoundingBox(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
def _math_bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox xmin = self.get_minmax_data(self.mx, self.Mx)["xmin"] xmax = self.get_minmax_data(self.mx, self.Mx)["xmax"] ymin = self.get_minmax_data(self.mx, self.Mx)["ymin"] ymax = self.get_minmax_data(self.mx, self.Mx)["ymax"] return BoundingBox(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
def _bounding_box(self, pspict): from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox() bb.addX(self.minimum) bb.addX(self.maximum) bb.addY(self.delta_y - self.h / 2) bb.addY(self.delta_y + self.h / 2) return bb
def _bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox() for s in self.c1: bb.append(s, pspict) for s in self.c2: bb.append(s, pspict) return bb
def getTextBox(self, pspict): from yanntricks.src.BoundingBox import BoundingBox text_width, text_height = self.getTextSize(pspict) xmin = self.central_point.x - text_width / 2 xmax = self.central_point.x + text_width / 2 ymin = self.central_point.y - text_height / 2 ymax = self.central_point.y + text_height / 2 return BoundingBox(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
def _bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox xmin = self.xmin(self.llamI, self.llamF) xmax = self.xmax(self.llamI, self.llamF) ymin = self.ymin(self.llamI, self.llamF) ymax = self.ymax(self.llamI, self.llamF) bb = BoundingBox(Point(xmin, ymin), Point(xmax, ymax)) return bb
def getSecondBox(self, pspict): from yanntricks.src.BoundingBox import BoundingBox first_box = self.getFirstBox(pspict) xmin = first_box.xmin - MATRIX_ELEMENT_SECOND_BOX_X_BORDER xmax = first_box.xmax + MATRIX_ELEMENT_SECOND_BOX_X_BORDER ymin = first_box.ymin - MATRIX_ELEMENT_SECOND_BOX_Y_BORDER ymax = first_box.ymax + MATRIX_ELEMENT_SECOND_BOX_Y_BORDER return BoundingBox(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
def getFirstBox(self, pspict): from yanntricks.src.BoundingBox import BoundingBox text_box = self.getTextBox(pspict) xmin = text_box.xmin - MATRIX_ELEMENT_FIRST_BOX_X_BORDER xmax = text_box.xmax + MATRIX_ELEMENT_FIRST_BOX_X_BORDER ymin = text_box.ymin - MATRIX_ELEMENT_FIRST_BOX_Y_BORDER ymax = text_box.ymax + MATRIX_ELEMENT_FIRST_BOX_Y_BORDER return BoundingBox(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)
def _bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox from yanntricks.src.segment import Segment if pspict == None: raise ValueError("You have to provide a pspict") bb = BoundingBox() bb.append(self.curve1, pspict) bb.append(self.curve2, pspict) return bb
def _bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox if self.do_cut_y and len(self.pieces) > 0: # In this case, we will in any case look for the # bounding boxes # of the pieces. # Notice that it can happen that self.do_cut_y=True but # that only one piece is found. return BoundingBox() return self.parametric_curve().bounding_box()
def getSecondBox(self, pspict): from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox() bb.append(self.getLine(1).getSecondBox(pspict), pspict=pspict) bb.append(self.getLine(self.nlines).getSecondBox(pspict), pspict=pspict) bb.append(self.getColumn(1).getSecondBox(pspict), pspict=pspict) bb.append(self.getColumn(self.ncolumns).getSecondBox(pspict), pspict=pspict) return bb
def _math_bounding_box(self, pspict=None): ## # Return a bounding box which include itself and that's it. # Here one cannot use BoundingBox(self.point,self.point) because # it creates infinite loop. from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox(xmin=self.point.x, xmax=self.point.x, ymin=self.point.y, ymax=self.point.y) return bb
def _math_bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox BB = BoundingBox() BB.append(self.single_axeX.bounding_box(pspict), pspict) BB.append(self.single_axeY.bounding_box(pspict), pspict) if self.pspict: BB.append(self.pspict.math_bounding_box(), pspict) # Updates the single axes taking the content of pspict into account. self.add_bounding_box(BB, pspict) BB.check_too_large() return BB
def _math_bounding_box(self, pspict): # pylint: disable=unused-argument # The math_bounding box does not take into account the things # that are inside the picture (not even if this are default axes) from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox() for x, _ in self.axes_unit.place_list(self.mx, self.Mx, self.Dx, self.mark_origin): P = (x*self.base).F bb.addX(P.x) bb.addY(P.y) return bb
def _bounding_box(self, pspict=None): """ return the bounding box of the axes. If `self` is a default axe, it take into account the content of the pspicture and update the mx,my of the single axes X and Y. """ from yanntricks.src.BoundingBox import BoundingBox BB = BoundingBox() BB.append(self.single_axeX.bounding_box(pspict), pspict) BB.append(self.single_axeY.bounding_box(pspict), pspict) if self.pspict: BB.append(self.pspict.math_bounding_box(), pspict) # Update the single axes taking the content of pspict into account. self.add_bounding_box(BB, pspict) BB.check_too_large() return BB
def _math_bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox if self.in_math_bounding_box: return self.bounding_box(pspict) return BoundingBox()
def _math_bounding_box(self,pspict): from yanntricks.src.BoundingBox import BoundingBox bb=BoundingBox() for l in self.lines_list: bb.append(l,pspict) return bb
def _bounding_box(self, pspict=None): bb = BoundingBox() bb.append(self.curve1, pspict) bb.append(self.curve2, pspict) return bb
def __init__(self, name="CAN_BE_A_PROBLEM_IF_TRY_TO_PRODUCE_EPS_OR_PDF"): r""" - `self.BB` is the bounding box for LaTeX purpose. - `self.math_BB` is the bounding box of objects that are "mathematically relevant". This bounding box does not take into account marks of points and thinks like that. This is the bounding box that is going to be used for the axes and the grid. When a graph object has a method math_bounding_box, this is the one taken into account in the math_BB here. """ from yanntricks.src.GridGraph import Grid from yanntricks.src.AxesGraph import Axes self.paths = PathsKeeper() self.name = name # for the intermediate files. # A comment. This is not used to create the picture; # the purpose is to remember a specific feature to be # tested when recompiling. self.comment = "" self.tikzfile = self.paths.create("sage_dir", f"tikz{self.name}") self.mother = None self.figure_mother = None self.language = "tikz" self.pstricks_code_list = [] self.newwriteDone = False # self.interWriteFile is redefined in MultiplePictures self.record_marks = [] self.record_bounding_box = [] self.record_draw_graph = [] self.record_draw_bb = [] self.record_force_math_bounding_box = [] # self.record_math_BB=[] # self.record_BB=[] self.counterDone = False self.newlengthDone = False self.listePoint = [] self.xunit = 1 self.yunit = 1 self.xsize = None self.ysize = None self.rotation_angle = None self.LabelSep = 1 self.BB = BoundingBox(mother=self) self.math_BB = BoundingBox(is_math=True) # self.BB and self.math_BB serve to add some objects by hand. # If you need the bounding box, use self.bounding_box() # or self.math_bounding_box() self.axes = Axes(Point(0, 0), BoundingBox(), pspict=self) self.single_axeX = self.axes.single_axeX self.single_axeY = self.axes.single_axeY self.single_axeX.pspict = self self.single_axeY.pspict = self self.draw_default_axes = False self.mx_acceptable_BB = -100 self.my_acceptable_BB = -100 self.Mx_acceptable_BB = 100 self.My_acceptable_BB = 100 self.grid = Grid(BoundingBox()) # The order of declaration is important, because # it is recorded in the Separator.number attribute. self.separator_list = init_picture_separator_list() self.entete_position = "ENTETE PSPICTURE" self.auxiliary_file = AuxFile(self.name, picture=self)
def _math_bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox return BoundingBox()
def _math_bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox BB = BoundingBox() BB.append(self.single_axeX.math_bounding_box(pspict), pspict=pspict) BB.append(self.single_axeY.math_bounding_box(pspict), pspict=pspict) return BB
def _bounding_box(self, pspict): from yanntricks.src.BoundingBox import BoundingBox if self.in_bounding_box: return BoundingBox(self.I, self.F) return BoundingBox()
def _bounding_box(self, pspict=None): from yanntricks.src.BoundingBox import BoundingBox bb = BoundingBox() for v in self.draw_vectors: bb.append(v, pspict) return bb
def _math_bounding_box(self, pspict=None): # a text has no math_bounding_box because the axes do not want to fit them. # return self.mark.math_bounding_box(pspict) # June 1, 2015 from yanntricks.src.BoundingBox import BoundingBox return BoundingBox()