[Gridflow-cvs] [svn] commit: r3462 - in /trunk/base: flow_objects.c flow_objects.rb

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Fri Apr 4 10:08:11 EDT 2008


Author: matju
Date: Fri Apr  4 10:08:10 2008
New Revision: 3462

Log:
[rotatificator] rewritten in C++

Modified:
    trunk/base/flow_objects.c
    trunk/base/flow_objects.rb

Modified: trunk/base/flow_objects.c
==============================================================================
--- trunk/base/flow_objects.c (original)
+++ trunk/base/flow_objects.c Fri Apr  4 10:08:10 2008
@@ -2373,6 +2373,41 @@
 
 //****************************************************************
 
+\class GridRotatificator : GridObject {
+	int angle;
+	int from, to, n;
+	\decl 0 float (int scale);
+	\decl 0 axis (int from, int to, int n);
+	\decl void initialize(int from=0, int to=1, int n=2);
+	\decl 1 float(int angle);
+};
+\def 0 float (int scale) {
+	int32 rotator[n*n];
+	for (int i=0; i<n; i++) for (int j=0; j<n; j++) rotator[i*n+j] = scale * (i==j);
+	float th = angle * M_PI / 18000;
+	for (int i=0; i<2; i++) for (int j=0; j<2; j++)
+		rotator[(i?to:from)*n+(j?to:from)] = (int32)round(scale*cos(th+(j-i)*M_PI/2));
+	GridOutlet out(this,0,new Dim(n,n),int32_e);
+	out.send(n*n,rotator);
+}
+\def 0 axis(int from, int to, int n) {
+	if (n<0) RAISE("n-axis number incorrect");
+	if (from<0 || from>=n) RAISE("from-axis number incorrect");
+	if (to  <0 || to  >=n) RAISE(  "to-axis number incorrect");
+	this->from = from;
+	this->  to =   to;
+	this->   n =    n;
+}
+\def void initialize(int from=0, int to=1, int n=2) {
+	SUPER;
+	angle=0;
+	_0_axis(0,0,from,to,n);
+}
+\def 1 float(int angle) {this->angle = angle;}
+\end class {install("#rotatificator",2,1);}
+
+//****************************************************************
+
 template <class T> void swap (T &a, T &b) {T c; c=a; a=b; b=c;}
 
 \class ListReverse : FObject {
@@ -2387,6 +2422,18 @@
 	outlet_list(bself->te_outlet,&s_list,argc,at);
 }
 \end class {install("listreverse",1,1);}
+
+\class ListFlatten : FObject {
+	\decl void initialize();
+	\decl 0 list(...);
+};
+\def void initialize () {SUPER;}
+\def 0 list (...) {
+	t_atom at[argc];
+	ruby2pd(argc,argv,at);
+	outlet_list(bself->te_outlet,&s_list,argc,at);
+}
+\end class {install("listflatten",1,1);}
 
 //****************************************************************
 

Modified: trunk/base/flow_objects.rb
==============================================================================
--- trunk/base/flow_objects.rb (original)
+++ trunk/base/flow_objects.rb Fri Apr  4 10:08:10 2008
@@ -142,36 +142,6 @@
 	end
 }
 
-FObject.subclass("#rotatificator",2,1) {
-	def _0_float(scale)
-		n = @axis[2]
-		rotator = (0...n).map {|i| (0...n).map {|j| if i==j then scale else 0 end }}
-		th = @angle * Math::PI / 18000
-		(0...2).each {|i| (0...2).each {|j|
-				a = @axis[i].to_i
-				b = @axis[j].to_i
-				rotator[a][b] = (scale*Math.cos(th+(j-i)*Math::PI/2)).to_i
-		}}
-		send_out 0,:list,n,n,:"#",*rotator.flatten
-	end
-	def _0_axis(from,to,total)
-		total>=0 or raise "total-axis number incorrect"
-		from>=0 and from<total or raise "from-axis number incorrect"
-		to  >=0 and to  <total or raise   "to-axis number incorrect"
-		@axis = [from.to_i,to.to_i,total.to_i]
-	end
-	def initialize(axis=[0,1,2])
-		super
-		@angle=0
-		_0_axis(*axis)
-	end
-	def _1_float(angle) @angle = angle end
-}
-
-FObject.subclass("listflatten",1,1) {
-	def initialize() super end
-	def _0_list(*a) send_out 0,:list,*a.flatten end
-}
 FObject.subclass("rubysprintf",2,1) {
   def initialize(*format) _1_list(format) end
   def _0_list(*a) send_out 0, :symbol, (sprintf @format, *a).intern end



More information about the Gridflow-cvs mailing list