def _bracepath(self, x0_pt, y0_pt, x1_pt, y1_pt): # <<< height_pt = unit.topt(self.totalheight) totallength_pt = math.hypot(x1_pt - x0_pt, y1_pt - y0_pt) leftlength_pt = self.middlerelpos * totallength_pt rightlength_pt = totallength_pt - leftlength_pt ithick_pt = unit.topt(self.innerstrokesthickness) othick_pt = unit.topt(self.outerstrokesthickness) bthick_pt = unit.topt(self.barthickness) # create the left halfbrace with positive slanting # because we will mirror this part cos_iangle = math.cos( math.radians(0.5 * self.innerstrokesangle - self.slantstrokesangle)) sin_iangle = math.sin( math.radians(0.5 * self.innerstrokesangle - self.slantstrokesangle)) cos_oangle = math.cos( math.radians(self.outerstrokesangle - self.slantstrokesangle)) sin_oangle = math.sin( math.radians(self.outerstrokesangle - self.slantstrokesangle)) cos_slangle = math.cos(math.radians(-self.slantstrokesangle)) sin_slangle = math.sin(math.radians(-self.slantstrokesangle)) ilength_pt = self.innerstrokesrelheight * height_pt / cos_iangle olength_pt = self.outerstrokesrelheight * height_pt / cos_oangle bracepath = self._halfbracepath_pt( leftlength_pt, height_pt, ilength_pt, olength_pt, ithick_pt, othick_pt, bthick_pt, cos_iangle, sin_iangle, cos_oangle, sin_oangle, cos_slangle, sin_slangle).reversed().transformed(trafo.mirror(90)) # create the right halfbrace with negative slanting cos_iangle = math.cos( math.radians(0.5 * self.innerstrokesangle + self.slantstrokesangle)) sin_iangle = math.sin( math.radians(0.5 * self.innerstrokesangle + self.slantstrokesangle)) cos_oangle = math.cos( math.radians(self.outerstrokesangle + self.slantstrokesangle)) sin_oangle = math.sin( math.radians(self.outerstrokesangle + self.slantstrokesangle)) cos_slangle = math.cos(math.radians(-self.slantstrokesangle)) sin_slangle = math.sin(math.radians(-self.slantstrokesangle)) ilength_pt = self.innerstrokesrelheight * height_pt / cos_iangle olength_pt = self.outerstrokesrelheight * height_pt / cos_oangle bracepath = bracepath << self._halfbracepath_pt( rightlength_pt, height_pt, ilength_pt, olength_pt, ithick_pt, othick_pt, bthick_pt, cos_iangle, sin_iangle, cos_oangle, sin_oangle, cos_slangle, sin_slangle) return bracepath.transformed( # two trafos for matching the given endpoints trafo.translate_pt(x0_pt, y0_pt) * trafo.rotate_pt( math.degrees(math.atan2(y1_pt - y0_pt, x1_pt - x0_pt))) * # one trafo to move the brace's left outer stroke to zero trafo.translate_pt(leftlength_pt, 0))
def _decocanvas(self, angle, dp, texrunner): dp.ensurenormpath() dist_pt = unit.topt(self.dist) c = canvas.canvas([canvas.clip(dp.path)]) llx_pt, lly_pt, urx_pt, ury_pt = dp.path.bbox().highrestuple_pt() center_pt = 0.5*(llx_pt+urx_pt), 0.5*(lly_pt+ury_pt) radius_pt = 0.5*math.hypot(urx_pt-llx_pt, ury_pt-lly_pt) + dist_pt n = int(2*radius_pt / dist_pt) + 1 for i in range(n): x_pt = center_pt[0] - radius_pt + i*dist_pt c.stroke(path.line_pt(x_pt, center_pt[1]-radius_pt, x_pt, center_pt[1]+radius_pt), [trafo.rotate_pt(angle, center_pt[0], center_pt[1])] + self.strokestyles) return c
def _bracepath(self, x0_pt, y0_pt, x1_pt, y1_pt): # <<< height_pt = unit.topt(self.totalheight) totallength_pt = math.hypot(x1_pt - x0_pt, y1_pt - y0_pt) leftlength_pt = self.middlerelpos * totallength_pt rightlength_pt = totallength_pt - leftlength_pt ithick_pt = unit.topt(self.innerstrokesthickness) othick_pt = unit.topt(self.outerstrokesthickness) bthick_pt = unit.topt(self.barthickness) # create the left halfbrace with positive slanting # because we will mirror this part cos_iangle = math.cos(math.radians(0.5*self.innerstrokesangle - self.slantstrokesangle)) sin_iangle = math.sin(math.radians(0.5*self.innerstrokesangle - self.slantstrokesangle)) cos_oangle = math.cos(math.radians(self.outerstrokesangle - self.slantstrokesangle)) sin_oangle = math.sin(math.radians(self.outerstrokesangle - self.slantstrokesangle)) cos_slangle = math.cos(math.radians(-self.slantstrokesangle)) sin_slangle = math.sin(math.radians(-self.slantstrokesangle)) ilength_pt = self.innerstrokesrelheight * height_pt / cos_iangle olength_pt = self.outerstrokesrelheight * height_pt / cos_oangle bracepath = self._halfbracepath_pt(leftlength_pt, height_pt, ilength_pt, olength_pt, ithick_pt, othick_pt, bthick_pt, cos_iangle, sin_iangle, cos_oangle, sin_oangle, cos_slangle, sin_slangle).reversed().transformed(trafo.mirror(90)) # create the right halfbrace with negative slanting cos_iangle = math.cos(math.radians(0.5*self.innerstrokesangle + self.slantstrokesangle)) sin_iangle = math.sin(math.radians(0.5*self.innerstrokesangle + self.slantstrokesangle)) cos_oangle = math.cos(math.radians(self.outerstrokesangle + self.slantstrokesangle)) sin_oangle = math.sin(math.radians(self.outerstrokesangle + self.slantstrokesangle)) cos_slangle = math.cos(math.radians(-self.slantstrokesangle)) sin_slangle = math.sin(math.radians(-self.slantstrokesangle)) ilength_pt = self.innerstrokesrelheight * height_pt / cos_iangle olength_pt = self.outerstrokesrelheight * height_pt / cos_oangle bracepath = bracepath << self._halfbracepath_pt(rightlength_pt, height_pt, ilength_pt, olength_pt, ithick_pt, othick_pt, bthick_pt, cos_iangle, sin_iangle, cos_oangle, sin_oangle, cos_slangle, sin_slangle) return bracepath.transformed( # two trafos for matching the given endpoints trafo.translate_pt(x0_pt, y0_pt) * trafo.rotate_pt(math.degrees(math.atan2(y1_pt-y0_pt, x1_pt-x0_pt))) * # one trafo to move the brace's left outer stroke to zero trafo.translate_pt(leftlength_pt, 0))
def _decocanvas(self, angle, dp, texrunner): dp.ensurenormpath() dist_pt = unit.topt(self.dist) c = canvas.canvas([canvas.clip(dp.path)]) llx_pt, lly_pt, urx_pt, ury_pt = dp.path.bbox().highrestuple_pt() center_pt = 0.5 * (llx_pt + urx_pt), 0.5 * (lly_pt + ury_pt) radius_pt = 0.5 * math.hypot(urx_pt - llx_pt, ury_pt - lly_pt) + dist_pt n = int(2 * radius_pt / dist_pt) + 1 for i in range(n): x_pt = center_pt[0] - radius_pt + i * dist_pt c.stroke( path.line_pt(x_pt, center_pt[1] - radius_pt, x_pt, center_pt[1] + radius_pt), [trafo.rotate_pt(angle, center_pt[0], center_pt[1])] + self.strokestyles) return c