Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2007-03-20 15:07:02 +0300
committerCampbell Barton <ideasman42@gmail.com>2007-03-20 15:07:02 +0300
commit83a9a844985dd6f1aece3418ccb4134478bdb053 (patch)
tree4394493340c123a2fa987729101081202407eab6 /source/blender
parentbafc50df9b826851bd2e6ccaa5ef6665cd3cee29 (diff)
BoxPack2D example in epydocs, small cleanup on Geometry.c
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/api2_2x/Geometry.c15
-rw-r--r--source/blender/python/api2_2x/Geometry.h2
-rw-r--r--source/blender/python/api2_2x/doc/Geometry.py83
-rw-r--r--source/blender/python/api2_2x/vector.h2
4 files changed, 57 insertions, 45 deletions
diff --git a/source/blender/python/api2_2x/Geometry.c b/source/blender/python/api2_2x/Geometry.c
index de522fd9348..c1bdf47a368 100644
--- a/source/blender/python/api2_2x/Geometry.c
+++ b/source/blender/python/api2_2x/Geometry.c
@@ -44,8 +44,7 @@
/* needed for EXPP_ReturnPyObjError and EXPP_check_sequence_consistency */
#include "gen_utils.h"
-
-//#include "util.h" /* MIN2 and MAX2 */
+
#include "BKE_utildefines.h"
#define SWAP_FLOAT(a,b,tmp) tmp=a; a=b; b=tmp
@@ -305,7 +304,7 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
#define SET_BOXTOP(b, f) b->v[BL]->y = f - b->h; b->v[TR]->y = f; UPDATE_V34Y(b)
#define BOXINTERSECT(b1, b2) (!(BOXLEFT(b1)+EUL>=BOXRIGHT(b2) || BOXBOTTOM(b1)+EUL>=BOXTOP(b2) || BOXRIGHT(b1)-EUL<=BOXLEFT(b2) || BOXTOP(b1)-EUL<=BOXBOTTOM(b2) ))
-#define BOXDEBUG(b) printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n", b->index, b->w, b->h, b->x, b->y)
+/* #define BOXDEBUG(b) printf("\tBox Debug i %i, w:%.3f h:%.3f x:%.3f y:%.3f\n", b->index, b->w, b->h, b->x, b->y) */
static int box_areasort(const void *p1, const void *p2)
@@ -315,7 +314,6 @@ static int box_areasort(const void *p1, const void *p2)
a1 = BOXAREA(b1);
a2 = BOXAREA(b2);
- /*printf("a1 a2 %f %f\n", a1, a2);*/
/* sort largest to smallest */
if ( a1 < a2 ) return 1;
@@ -336,20 +334,15 @@ static int vertex_sort(const void *p1, const void *p2)
v1 = vertarray + ((int *) p1)[0];
v2 = vertarray + ((int *) p2)[0];
- // self.verts.sort(key = lambda b: max(b.x+w, b.y+h) ) # Reverse area sort
-
a1 = MAX2(v1->x+box_width, v1->y+box_height);
a2 = MAX2(v2->x+box_width, v2->y+box_height);
- /*printf("a1 a2 %f %f\n", a1, a2);*/
-
/* sort largest to smallest */
if ( a1 > a2 ) return 1;
else if ( a1 < a2 ) return -1;
return 0;
}
-
static void boxPackAll(boxPack *boxarray, int len, float *tot_width, float *tot_height)
{
boxVert *vert;
@@ -544,14 +537,12 @@ static void boxPackAll(boxPack *boxarray, int len, float *tot_width, float *tot_
box->v[BL]->free &= ~(BRF|BLF);
box->v[BR]->free &= ~(BRF|BLF);
}
+
/* The following block of code does a logical
* check with 2 adjacent boxes, its possible to
* flag verts on one or both of the boxes
* as being used by checking the width or
* height of both boxes */
-
-
-
if (vert->tlb && vert->trb && (box == vert->tlb || box == vert->trb)) {
if (vert->tlb->h > vert->trb->h) {
vert->trb->v[TL]->free &= ~(TLF|BLF);
diff --git a/source/blender/python/api2_2x/Geometry.h b/source/blender/python/api2_2x/Geometry.h
index a601d39f274..09a1a27800e 100644
--- a/source/blender/python/api2_2x/Geometry.h
+++ b/source/blender/python/api2_2x/Geometry.h
@@ -29,7 +29,7 @@
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
-//Include this file for access to vector, quat, matrix, euler, etc...
+/*Include this file for access to vector, quat, matrix, euler, etc...*/
#ifndef EXPP_Geometry_H
#define EXPP_Geometry_H
diff --git a/source/blender/python/api2_2x/doc/Geometry.py b/source/blender/python/api2_2x/doc/Geometry.py
index 610582bd110..bd44484177c 100644
--- a/source/blender/python/api2_2x/doc/Geometry.py
+++ b/source/blender/python/api2_2x/doc/Geometry.py
@@ -10,36 +10,36 @@ This new module provides access to a geometry function.
"""
def PolyFill(polylines):
- """
- Takes a list of polylines and calculates triangles that would fill in the polylines.
- Multiple lines can be used to make holes inside a polyline, or fill in 2 seperate lines at once.
- @type polylines: List of lists containing vectors, each representing a closed polyline.
- @rtype: list
- @return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given.
- @note: 2D Vectors will have an assumed Z axis of zero, 4D Vectors W axis is ignored.
- @note: The order of points in a polyline effect the direction returned triangles face, reverse the order of a polyline to flip the normal of returned faces.
-
- I{B{Example:}}
-
- The example below creates 2 polylines and fills them in with faces, then makes a mesh in the current scene::
- import Blender
- Vector= Blender.Mathutils.Vector
-
- # Outline of 5 points
- polyline1= [Vector(-2.0, 1.0, 1.0), Vector(-1.0, 2.0, 1.0), Vector(1.0, 2.0, 1.0), Vector(1.0, -1.0, 1.0), Vector(-1.0, -1.0, 1.0)]
- polyline2= [Vector(-1, 1, 1.0), Vector(0, 1, 1.0), Vector(0, 0, 1.0), Vector(-1.0, 0.0, 1.0)]
- fill= Blender.Geometry.PolyFill([polyline1, polyline2])
-
- # Make a new mesh and add the truangles into it
- me= Blender.Mesh.New()
- me.verts.extend(polyline1)
- me.verts.extend(polyline2)
- me.faces.extend(fill) # Add the faces, they reference the verts in polyline 1 and 2
-
- scn = Blender.Scene.GetCurrent()
- ob = scn.objects.new(me)
- Blender.Redraw()
- """
+ """
+ Takes a list of polylines and calculates triangles that would fill in the polylines.
+ Multiple lines can be used to make holes inside a polyline, or fill in 2 seperate lines at once.
+ @type polylines: List of lists containing vectors, each representing a closed polyline.
+ @rtype: list
+ @return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given.
+ @note: 2D Vectors will have an assumed Z axis of zero, 4D Vectors W axis is ignored.
+ @note: The order of points in a polyline effect the direction returned triangles face, reverse the order of a polyline to flip the normal of returned faces.
+
+ I{B{Example:}}
+
+ The example below creates 2 polylines and fills them in with faces, then makes a mesh in the current scene::
+ import Blender
+ Vector= Blender.Mathutils.Vector
+
+ # Outline of 5 points
+ polyline1= [Vector(-2.0, 1.0, 1.0), Vector(-1.0, 2.0, 1.0), Vector(1.0, 2.0, 1.0), Vector(1.0, -1.0, 1.0), Vector(-1.0, -1.0, 1.0)]
+ polyline2= [Vector(-1, 1, 1.0), Vector(0, 1, 1.0), Vector(0, 0, 1.0), Vector(-1.0, 0.0, 1.0)]
+ fill= Blender.Geometry.PolyFill([polyline1, polyline2])
+
+ # Make a new mesh and add the truangles into it
+ me= Blender.Mesh.New()
+ me.verts.extend(polyline1)
+ me.verts.extend(polyline2)
+ me.faces.extend(fill) # Add the faces, they reference the verts in polyline 1 and 2
+
+ scn = Blender.Scene.GetCurrent()
+ ob = scn.objects.new(me)
+ Blender.Redraw()
+ """
def LineIntersect2D(vec1, vec2, vec3, vec4):
"""
@@ -51,10 +51,31 @@ def LineIntersect2D(vec1, vec2, vec3, vec4):
def BoxPack2D(boxlist):
"""
Takes a list of 2D boxes and packs them into a square.
-
Each box in boxlist must be a list of at least 4 items - [x,y,w,h], after running this script,
the X and Y values in each box will be moved to packed, non overlapping locations.
+ Example::
+
+ # Make 500 random boxes, pack them and make a mesh from it
+ from Blender import Geometry, Scene, Mesh
+ import random
+ boxes = []
+ for i in xrange(500):
+ boxes.append( [0,0, random.random()+0.1, random.random()+0.1] )
+ boxsize = Geometry.BoxPack2D(boxes)
+ print 'BoxSize', boxsize
+ me = Mesh.New()
+ for x in boxes:
+ me.verts.extend([(x[0],x[1], 0), (x[0],x[1]+x[3], 0), (x[0]+x[2],x[1]+x[3], 0), (x[0]+x[2],x[1], 0) ])
+ v1= me.verts[-1]
+ v2= me.verts[-2]
+ v3= me.verts[-3]
+ v4= me.verts[-4]
+ me.faces.extend([(v1,v2,v3,v4)])
+ scn = Scene.GetCurrent()
+ scn.objects.new(me)
+
+ @note: Each boxlist item can be longer then 4, the extra items are ignored and stay untouched.
@rtype: tuple
@return: a tuple pair - (width, height) of all the packed boxes.
"""
diff --git a/source/blender/python/api2_2x/vector.h b/source/blender/python/api2_2x/vector.h
index 8f8dda99a7f..3f58d9fa6d5 100644
--- a/source/blender/python/api2_2x/vector.h
+++ b/source/blender/python/api2_2x/vector.h
@@ -46,7 +46,7 @@ typedef struct {
short wrapped; /* is wrapped data? */
} VectorObject;
-//prototypes
+/*prototypes*/
PyObject *Vector_Zero( VectorObject * self );
PyObject *Vector_Normalize( VectorObject * self );
PyObject *Vector_Negate( VectorObject * self );