Skip to content

Commit

Permalink
FIX Deleted redundant methods and code that could not work
Browse files Browse the repository at this point in the history
  • Loading branch information
NelleV committed Sep 3, 2012
1 parent a7aaa83 commit 92c21fa
Showing 1 changed file with 6 additions and 72 deletions.
78 changes: 6 additions & 72 deletions lib/matplotlib/bezier.py
Expand Up @@ -4,8 +4,6 @@


from __future__ import print_function from __future__ import print_function
import numpy as np import numpy as np
from math import sqrt

from matplotlib.path import Path from matplotlib.path import Path


from operator import xor from operator import xor
Expand All @@ -17,6 +15,7 @@ class NonIntersectingPathException(ValueError):


# some functions # some functions



def get_intersection(cx1, cy1, cos_t1, sin_t1, def get_intersection(cx1, cy1, cos_t1, sin_t1,
cx2, cy2, cos_t2, sin_t2): cx2, cy2, cos_t2, sin_t2):
""" return a intersecting point between a line through (cx1, cy1) """ return a intersecting point between a line through (cx1, cy1)
Expand Down Expand Up @@ -48,7 +47,6 @@ def get_intersection(cx1, cy1, cos_t1, sin_t1,
return x, y return x, y





def get_normal_points(cx, cy, cos_t, sin_t, length): def get_normal_points(cx, cy, cos_t, sin_t, length):
""" """
For a line passing through (*cx*, *cy*) and having a angle *t*, For a line passing through (*cx*, *cy*) and having a angle *t*,
Expand All @@ -67,21 +65,17 @@ def get_normal_points(cx, cy, cos_t, sin_t, length):
return x1, y1, x2, y2 return x1, y1, x2, y2






## BEZIER routines ## BEZIER routines






# subdividing bezier curve # subdividing bezier curve
# http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-sub.html # http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-sub.html



def _de_casteljau1(beta, t): def _de_casteljau1(beta, t):
next_beta = beta[:-1] * (1-t) + beta[1:] * t next_beta = beta[:-1] * (1-t) + beta[1:] * t
return next_beta return next_beta



def split_de_casteljau(beta, t): def split_de_casteljau(beta, t):
"""split a bezier segment defined by its controlpoints *beta* """split a bezier segment defined by its controlpoints *beta*
into two separate segment divided at *t* and return their control points. into two separate segment divided at *t* and return their control points.
Expand All @@ -100,11 +94,6 @@ def split_de_casteljau(beta, t):
return left_beta, right_beta return left_beta, right_beta









def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedpath, def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedpath,
t0=0., t1=1., tolerence=0.01): t0=0., t1=1., tolerence=0.01):
""" Find a parameter t0 and t1 of the given bezier path which """ Find a parameter t0 and t1 of the given bezier path which
Expand Down Expand Up @@ -152,9 +141,6 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedp
start_inside = middle_inside start_inside = middle_inside







class BezierSegment: class BezierSegment:
""" """
A simple class of a 2-dimensional bezier segment A simple class of a 2-dimensional bezier segment
Expand Down Expand Up @@ -215,7 +201,6 @@ def split_bezier_intersecting_with_closedpath(bezier,
return _left, _right return _left, _right





def find_r_to_boundary_of_closedpath(inside_closedpath, xy, def find_r_to_boundary_of_closedpath(inside_closedpath, xy,
cos_t, sin_t, cos_t, sin_t,
rmin=0., rmax=1., tolerence=0.01): rmin=0., rmax=1., tolerence=0.01):
Expand All @@ -236,10 +221,9 @@ def _f(r):
find_bezier_t_intersecting_with_closedpath(_f, inside_closedpath, find_bezier_t_intersecting_with_closedpath(_f, inside_closedpath,
t0=rmin, t1=rmax, tolerence=tolerence) t0=rmin, t1=rmax, tolerence=tolerence)




## matplotlib specific ## matplotlib specific



def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False): def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):
""" divide a path into two segment at the point where inside(x, y) """ divide a path into two segment at the point where inside(x, y)
becomes False. becomes False.
Expand Down Expand Up @@ -308,9 +292,6 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):
return path_in, path_out return path_in, path_out







def inside_circle(cx, cy, r): def inside_circle(cx, cy, r):
r2 = r**2 r2 = r**2
def _f(xy): def _f(xy):
Expand All @@ -319,14 +300,14 @@ def _f(xy):
return _f return _f





# quadratic bezier lines # quadratic bezier lines


def get_cos_sin(x0, y0, x1, y1): def get_cos_sin(x0, y0, x1, y1):
dx, dy = x1-x0, y1-y0 dx, dy = x1-x0, y1-y0
d = (dx*dx + dy*dy)**.5 d = (dx*dx + dy*dy)**.5
return dx/d, dy/d return dx/d, dy/d



def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5): def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5):
""" returns """ returns
* 1 if two lines are parralel in same direction * 1 if two lines are parralel in same direction
Expand Down Expand Up @@ -407,40 +388,6 @@ def get_parallels(bezier2, width):
return path_left, path_right return path_left, path_right





def make_wedged_bezier2(bezier2, length, shrink_factor=0.5):
"""
Being similar to get_parallels, returns
control points of two quadrativ bezier lines having a width roughly parralel to given
one separated by *width*.
"""

xx1, yy1 = bezier2[2]
xx2, yy2 = bezier2[1]
xx3, yy3 = bezier2[0]

cx, cy = xx3, yy3
x0, y0 = xx2, yy2

dist = sqrt((x0-cx)**2 + (y0-cy)**2)
cos_t, sin_t = (x0-cx)/dist, (y0-cy)/dist,

x1, y1, x2, y2 = get_normal_points(cx, cy, cos_t, sin_t, length)

xx12, yy12 = (xx1+xx2)/2., (yy1+yy2)/2.,
xx23, yy23 = (xx2+xx3)/2., (yy2+yy3)/2.,

dist = sqrt((xx12-xx23)**2 + (yy12-yy23)**2)
cos_t, sin_t = (xx12-xx23)/dist, (yy12-yy23)/dist,

xm1, ym1, xm2, ym2 = get_normal_points(xx2, yy2, cos_t, sin_t, length*shrink_factor)

l_plus = [(x1, y1), (xm1, ym1), (xx1, yy1)]
l_minus = [(x2, y2), (xm2, ym2), (xx1, yy1)]

return l_plus, l_minus


def find_control_points(c1x, c1y, mmx, mmy, c2x, c2y): def find_control_points(c1x, c1y, mmx, mmy, c2x, c2y):
""" Find control points of the bezier line throught c1, mm, c2. We """ Find control points of the bezier line throught c1, mm, c2. We
simply assume that c1, mm, c2 which have parameteric value 0, 0.5, and 1. simply assume that c1, mm, c2 which have parameteric value 0, 0.5, and 1.
Expand Down Expand Up @@ -504,8 +451,6 @@ def make_wedged_bezier2(bezier2, width, w1=1., wm=0.5, w2=0.):
return path_left, path_right return path_left, path_right






def make_path_regular(p): def make_path_regular(p):
""" """
fill in the codes if None. fill in the codes if None.
Expand All @@ -520,6 +465,7 @@ def make_path_regular(p):
else: else:
return p return p



def concatenate_paths(paths): def concatenate_paths(paths):
""" """
concatenate list of paths into a single path. concatenate list of paths into a single path.
Expand All @@ -535,15 +481,3 @@ def concatenate_paths(paths):
_path = Path(np.concatenate(vertices), _path = Path(np.concatenate(vertices),
np.concatenate(codes)) np.concatenate(codes))
return _path return _path



if 0:
path = Path([(0, 0), (1, 0), (2, 2)],
[Path.MOVETO, Path.CURVE3, Path.CURVE3])
left, right = divide_path_inout(path, inside)
clf()
ax = gca()



0 comments on commit 92c21fa

Please sign in to comment.