diff options
| author | Alvin Penner <penner@vaxxine.com> | 2014-02-08 20:49:04 +0000 |
|---|---|---|
| committer | apenner <penner@vaxxine.com> | 2014-02-08 20:49:04 +0000 |
| commit | d8cb55512fe7cdb3cc5ab83a9d173079885fd87d (patch) | |
| tree | b378f0a173296fad6f683695f5197e90411b3363 | |
| parent | Fix for Bug #879058 (Spray Single Path Mode includes original object). (diff) | |
| download | inkscape-d8cb55512fe7cdb3cc5ab83a9d173079885fd87d.tar.gz inkscape-d8cb55512fe7cdb3cc5ab83a9d173079885fd87d.zip | |
more robust versions of triangle.py and wireframe_sphere.py, see rev 13007
(bzr r13012)
| -rwxr-xr-x | share/extensions/triangle.py | 20 | ||||
| -rwxr-xr-x | share/extensions/wireframe_sphere.py | 16 |
2 files changed, 21 insertions, 15 deletions
diff --git a/share/extensions/triangle.py b/share/extensions/triangle.py index 81945f370..019db3147 100755 --- a/share/extensions/triangle.py +++ b/share/extensions/triangle.py @@ -69,7 +69,7 @@ def is_valid_tri_from_sides(a,b,c):#check whether triangle with sides a,b,c is v return (a+b)>c and (a+c)>b and (b+c)>a and a > 0 and b> 0 and c>0#two sides must always be greater than the third #no zero-length sides, no degenerate case -def draw_tri_from_3_sides(s_a, s_b, s_c, offset, parent): #draw a triangle from three sides (with a given offset +def draw_tri_from_3_sides(s_a, s_b, s_c, offset, width, parent): #draw a triangle from three sides (with a given offset if is_valid_tri_from_sides(s_a,s_b,s_c): a_b = angle_from_3_sides(s_a, s_c, s_b) @@ -82,7 +82,7 @@ def draw_tri_from_3_sides(s_a, s_b, s_c, offset, parent): #draw a triangle from offy = c[1]/2 #c is the highest point offset = ( offset[0]-offx , offset[1]-offy ) #add the centre of the triangle to the offset - draw_SVG_tri(a, b, c , offset, 2, 'Triangle', parent) + draw_SVG_tri(a, b, c , offset, width, 'Triangle', parent) else: sys.stderr.write('Error:Invalid Triangle Specifications.\n') @@ -122,12 +122,16 @@ class Grid_Polar(inkex.Effect): tri = self.current_layer offset = (self.view_center[0],self.view_center[1]) #the offset require to centre the triangle + self.options.s_a = self.unittouu(str(self.options.s_a) + 'px') + self.options.s_b = self.unittouu(str(self.options.s_b) + 'px') + self.options.s_c = self.unittouu(str(self.options.s_c) + 'px') + stroke_width = self.unittouu('2px') if self.options.mode == '3_sides': s_a = self.options.s_a s_b = self.options.s_b s_c = self.options.s_c - draw_tri_from_3_sides(s_a, s_b, s_c, offset, tri) + draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri) elif self.options.mode == 's_ab_a_c': s_a = self.options.s_a @@ -135,7 +139,7 @@ class Grid_Polar(inkex.Effect): a_c = self.options.a_c*pi/180 #in rad s_c = third_side_from_enclosed_angle(s_a,s_b,a_c) - draw_tri_from_3_sides(s_a, s_b, s_c, offset, tri) + draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri) elif self.options.mode == 's_ab_a_a': s_a = self.options.s_a @@ -159,13 +163,13 @@ class Grid_Polar(inkex.Effect): if not(error) and (a_b < pi) and (a_c < pi): #check that the solution is valid, if so draw acute solution s_c = third_side_from_enclosed_angle(s_a,s_b,a_c) - draw_tri_from_3_sides(s_a, s_b, s_c, offset, tri) + draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri) if not(error) and ((a_b > pi) or (a_c > pi) or ambiguous):#we want the obtuse solution a_b = pi - a_b a_c = pi - a_a - a_b s_c = third_side_from_enclosed_angle(s_a,s_b,a_c) - draw_tri_from_3_sides(s_a, s_b, s_c, offset, tri) + draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri) elif self.options.mode == 's_a_a_ab': s_a = self.options.s_a @@ -176,7 +180,7 @@ class Grid_Polar(inkex.Effect): s_b = s_a*sin(a_b)/sin(a_a) s_c = s_a*sin(a_c)/sin(a_a) - draw_tri_from_3_sides(s_a, s_b, s_c, offset, tri) + draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri) elif self.options.mode == 's_c_a_ab': s_c = self.options.s_c @@ -187,7 +191,7 @@ class Grid_Polar(inkex.Effect): s_a = s_c*sin(a_a)/sin(a_c) s_b = s_c*sin(a_b)/sin(a_c) - draw_tri_from_3_sides(s_a, s_b, s_c, offset, tri) + draw_tri_from_3_sides(s_a, s_b, s_c, offset, stroke_width, tri) if __name__ == '__main__': e = Grid_Polar() diff --git a/share/extensions/wireframe_sphere.py b/share/extensions/wireframe_sphere.py index 5804a1b45..bcd676dc4 100755 --- a/share/extensions/wireframe_sphere.py +++ b/share/extensions/wireframe_sphere.py @@ -63,10 +63,10 @@ import simplestyle inkex.localize() #SVG OUTPUT FUNCTIONS ================================================ -def draw_SVG_ellipse((rx, ry), (cx, cy), parent, start_end=(0,2*pi),transform='' ): +def draw_SVG_ellipse((rx, ry), (cx, cy), width, parent, start_end=(0,2*pi),transform='' ): style = { 'stroke' : '#000000', - 'stroke-width' : '1', + 'stroke-width' : str(width), 'fill' : 'none' } circ_attribs = {'style':simplestyle.formatStyle(style), inkex.addNS('cx','sodipodi') :str(cx), @@ -120,8 +120,10 @@ class Wireframe_Sphere(inkex.Effect): else: flip = '' #no flip + so.RADIUS = self.unittouu(str(so.RADIUS) + 'px') so.TILT = abs(so.TILT)*(pi/180) #Convert to radians so.ROT_OFFSET = so.ROT_OFFSET*(pi/180) #Convert to radians + stroke_width = self.unittouu('1px') EPSILON = 0.001 #add a tiny value to the ellipse radii, so that if we get a zero radius, the ellipse still shows up as a line @@ -174,7 +176,7 @@ class Wireframe_Sphere(inkex.Effect): #finally, draw the line of longitude #the centre is always at the centre of the sphere - draw_SVG_ellipse( ( minorRad, so.RADIUS ), (0,0), grp_long , start_end,transform) + draw_SVG_ellipse( ( minorRad, so.RADIUS ), (0,0), stroke_width, grp_long , start_end,transform) # LINES OF LATITUDE if so.NUM_LAT > 0: @@ -201,18 +203,18 @@ class Wireframe_Sphere(inkex.Effect): if so.HIDE_BACK: if lat_angle > so.TILT: #this LoLat is partially or fully visible if lat_angle > pi-so.TILT: #this LoLat is fully visible - draw_SVG_ellipse((majorRad, minorRad), (cx,cy), grp_lat) + draw_SVG_ellipse((majorRad, minorRad), (cx,cy), stroke_width, grp_lat) else: #this LoLat is partially visible proportion = -(acos( tan(lat_angle - pi/2)/tan(pi/2 - so.TILT)) )/pi + 1 start_end = ( pi/2 - proportion*pi, pi/2 + proportion*pi ) #make the start and end angles (mirror image around pi/2) - draw_SVG_ellipse((majorRad, minorRad), (cx,cy), grp_lat, start_end) + draw_SVG_ellipse((majorRad, minorRad), (cx,cy), stroke_width, grp_lat, start_end) else: #just draw the full lines of latitude - draw_SVG_ellipse((majorRad, minorRad), (cx,cy), grp_lat) + draw_SVG_ellipse((majorRad, minorRad), (cx,cy), stroke_width, grp_lat) #THE HORIZON CIRCLE - draw_SVG_ellipse((so.RADIUS, so.RADIUS), (0,0), grp) #circle, centred on the sphere centre + draw_SVG_ellipse((so.RADIUS, so.RADIUS), (0,0), stroke_width, grp) #circle, centred on the sphere centre if __name__ == '__main__': e = Wireframe_Sphere() |
