code: def bezier_real_minmax(p):
      
      local_extremizers = [0, 1]
      if len(p) == 4:  # cubic case
          a = [p.real for p in p]
          denom = a[0] - 3*a[1] + 3*a[2] - a[3]
          if denom != 0:
              delta = a[1]**2 - (a[0] + a[1])*a[2] + a[2]**2 + (a[0] - a[1])*a[3]
              if delta >= 0:  # otherwise no local extrema
                  sqdelta = sqrt(delta)
                  tau = a[0] - 2*a[1] + a[2]
                  r1 = (tau + sqdelta)/denom
                  r2 = (tau - sqdelta)/denom
                  if 0 < r1 < 1:
                      local_extremizers.append(r1)
                  if 0 < r2 < 1:
                      local_extremizers.append(r2)
              local_extrema = [bezier_point(a, t) for t in local_extremizers]
              return min(local_extrema), max(local_extrema)
  
      # find reverse standard coefficients of the derivative
      dcoeffs = bezier2polynomial(a, return_poly1d=True).deriv().coeffs
  
      # find real roots, r, such that 0 <= r <= 1
      local_extremizers += polyroots01(dcoeffs)
      local_extrema = [bezier_point(a, t) for t in local_extremizers]
      return min(local_extrema), max(local_extrema)
docs: returns the minimum and maximum for any real cubic bezier