PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Onyx-VJ 4.5.0/Onyx-VJ-Patches/src/inprogress/DelaunayThing.as

http://onyx-vj.googlecode.com/
ActionScript | 551 lines | 485 code | 40 blank | 26 comment | 68 complexity | c75a7b43633c37a1c6de704e71803413 MD5 | raw file
  1. /**
  2. * Copyright makc3d ( http://wonderfl.net/user/makc3d )
  3. * MIT License ( http://www.opensource.org/licenses/mit-license.php )
  4. * Downloaded from: http://wonderfl.net/c/mDMA
  5. */
  6. // forked from termat's Delaunay三角分割
  7. package inprogress
  8. {
  9. import flash.display.Sprite;
  10. import flash.events.Event;
  11. import flash.events.MouseEvent;
  12. import flash.text.TextField;
  13. import flash.text.TextFieldAutoSize;
  14. import onyx.core.*;
  15. import onyx.parameter.*;
  16. import onyx.plugin.*; /**
  17. * Delaunay三角分割サンプル
  18. *
  19. * @author termat(http://termat.sakura.ne.jp/)
  20. */
  21. public class DelaunayThing extends Patch
  22. {
  23. private var list:Vector.<Circle>;
  24. private var del:Del;
  25. private var sprite:Sprite;
  26. private var numNodes:uint=0;
  27. public function DelaunayThing():void {
  28. sprite = new Sprite();
  29. sprite.graphics.lineStyle(2,0xaaaaaa);
  30. sprite.graphics.drawRect(0,0,DISPLAY_WIDTH,DISPLAY_HEIGHT);
  31. list = new Vector.<Circle>();
  32. del = new Del(list);
  33. sprite.addChild(del);
  34. addEventListener(MouseEvent.MOUSE_DOWN, onClick);
  35. }
  36. private function onClick(e:MouseEvent):void {
  37. if(numNodes<6){
  38. numNodes++;
  39. addNode(e.localX,e.localY)
  40. }
  41. }
  42. private function addNode(x:Number,y:Number):void{
  43. var vx:Number = Math.random() * 12 - 6;
  44. if (Math.abs(vx) < 1e-2) vx=1.0;
  45. var vy:Number = Math.random() * 12 - 6;
  46. if (Math.abs(vy) < 1e-2) vy=1.0;
  47. var velo:Number = vx * vx + vy * vy;
  48. var c:int = Math.floor(Math.random() * 0xffffff);
  49. var p:Circle = new Circle(x,y,2,c,vx,vy);
  50. sprite.addChild(p);
  51. list.push(p);
  52. }
  53. override public function render(info:RenderInfo):void
  54. {
  55. if(numNodes<4/*80*/){
  56. var xx:Number=Math.random()*DISPLAY_WIDTH;
  57. var yy:Number=Math.random()*DISPLAY_HEIGHT;
  58. numNodes++;
  59. addNode(xx,yy);
  60. }
  61. for each(var c:Circle in list ) {
  62. c.update();
  63. }
  64. del.update();
  65. info.render(sprite);
  66. }
  67. }
  68. }
  69. import flash.display.BitmapData;
  70. import flash.display.GradientType;
  71. import flash.display.MovieClip;
  72. import flash.display.Shader;
  73. import flash.display.Shape;
  74. import flash.display.Sprite;
  75. import flash.geom.Matrix;
  76. import flash.geom.Point;
  77. import flash.utils.ByteArray;
  78. import onyx.plugin.*;
  79. class Circle extends MovieClip {
  80. private var vx:Number;
  81. private var vy:Number;
  82. private var color:uint;
  83. public function Circle(x:int, y:int, r:int, c:uint, vx:int, vy:int) {
  84. this.vx = vx;
  85. this.vy = vy;
  86. this.x = x;
  87. this.y = y;
  88. color = c;
  89. /*graphics.lineStyle(2, color) ;
  90. graphics.beginFill(c);
  91. graphics.drawCircle(0, 0, r);
  92. graphics.endFill();
  93. this.alpha = 0.5;*/
  94. }
  95. public function getLineColor():uint {
  96. return color;
  97. }
  98. public function update():void {
  99. var div:Number;
  100. if (x + vx < 0) {
  101. div = Math.abs((x + vx)/vx);
  102. vx *= -1;
  103. x = x + vx * div;
  104. }else if (x + vx > DISPLAY_WIDTH) {
  105. div= Math.abs((x + vx - DISPLAY_WIDTH) / vx);
  106. vx *= -1;
  107. x = x + vx * div;
  108. }else {
  109. x += vx;
  110. }
  111. if (y + vy < 0) {
  112. div = Math.abs((y + vy)/vy);
  113. vy *= -1;
  114. y = y + vy * div;
  115. }else if (y + vy > DISPLAY_HEIGHT) {
  116. div= Math.abs((y + vy-DISPLAY_HEIGHT)/vy);
  117. vy *= -1;
  118. y = y + vy * div;
  119. }else {
  120. y += vy;
  121. }
  122. }
  123. }
  124. class Del extends Sprite {
  125. private var list:Vector.<Circle>;
  126. private var del:Delaunay;
  127. private var matrix:Matrix=new Matrix();
  128. private var s:Shader;
  129. public function Del(l:Vector.<Circle>):void {
  130. var sdata:Array = [165,1,0,0,0,164,18,0,84,104,114,101,101,80,111,105,110,116,71,114,97,100,105,101,110,116,160,12,110,97,109,101,115,112,97,99,101,0,101,120,112,101,114,105,109,101,110,116,97,108,0,160,12,118,101,110,100,111,114,0,109,97,107,99,0,160,8,118,101,114,115,105,111,110,0,1,0,160,12,100,101,115,99,114,105,112,116,105,111,110,0,67,114,101,97,116,101,115,32,97,32,103,114,97,100,105,101,110,116,32,102,105,108,108,32,117,115,105,110,103,32,116,104,114,101,101,32,115,112,101,99,105,102,105,101,100,32,112,111,105,110,116,115,32,97,110,100,32,99,111,108,111,114,115,46,0,161,1,2,0,0,12,95,79,117,116,67,111,111,114,100,0,161,1,2,0,0,3,112,111,105,110,116,49,0,162,2,109,105,110,86,97,108,117,101,0,0,0,0,0,0,0,0,0,162,2,109,97,120,86,97,108,117,101,0,69,122,0,0,69,122,0,0,162,2,100,101,102,97,117,108,116,86,97,108,117,101,0,0,0,0,0,0,0,0,0,161,1,4,1,0,15,99,111,108,111,114,49,0,162,4,100,101,102,97,117,108,116,86,97,108,117,101,0,63,128,0,0,0,0,0,0,0,0,0,0,63,128,0,0,161,1,2,2,0,12,112,111,105,110,116,50,0,162,2,109,105,110,86,97,108,117,101,0,0,0,0,0,0,0,0,0,162,2,109,97,120,86,97,108,117,101,0,69,122,0,0,69,122,0,0,162,2,100,101,102,97,117,108,116,86,97,108,117,101,0,0,0,0,0,67,72,0,0,161,1,4,3,0,15,99,111,108,111,114,50,0,162,4,100,101,102,97,117,108,116,86,97,108,117,101,0,0,0,0,0,63,128,0,0,0,0,0,0,63,128,0,0,161,1,2,2,0,3,112,111,105,110,116,51,0,162,2,109,105,110,86,97,108,117,101,0,0,0,0,0,0,0,0,0,162,2,109,97,120,86,97,108,117,101,0,69,122,0,0,69,122,0,0,162,2,100,101,102,97,117,108,116,86,97,108,117,101,0,67,72,0,0,0,0,0,0,161,1,4,4,0,15,99,111,108,111,114,51,0,162,4,100,101,102,97,117,108,116,86,97,108,117,101,0,0,0,0,0,0,0,0,0,63,128,0,0,63,128,0,0,161,2,4,5,0,15,100,115,116,0,29,6,0,128,2,0,0,0,2,6,0,128,0,0,128,0,29,6,0,64,0,0,192,0,2,6,0,64,2,0,192,0,29,6,0,32,6,0,0,0,3,6,0,32,6,0,64,0,29,6,0,128,0,0,128,0,2,6,0,128,2,0,128,0,29,6,0,64,2,0,64,0,2,6,0,64,0,0,192,0,29,6,0,16,6,0,0,0,3,6,0,16,6,0,64,0,29,6,0,128,6,0,128,0,2,6,0,128,6,0,192,0,24,6,0,64,6,0,0,0,29,6,0,128,6,0,64,0,29,6,0,64,2,0,128,0,2,6,0,64,0,0,128,0,29,6,0,32,0,0,192,0,2,6,0,32,2,0,64,0,29,6,0,16,6,0,64,0,3,6,0,16,6,0,128,0,29,6,0,64,0,0,128,0,2,6,0,64,2,0,0,0,29,6,0,32,2,0,192,0,2,6,0,32,0,0,192,0,29,7,0,128,6,0,64,0,3,7,0,128,6,0,128,0,29,6,0,64,6,0,192,0,2,6,0,64,7,0,0,0,24,6,0,32,6,0,64,0,29,6,0,64,6,0,128,0,29,6,0,32,2,0,128,0,2,6,0,32,2,0,0,0,29,6,0,16,2,0,64,0,2,6,0,16,0,0,192,0,29,7,0,128,6,0,128,0,3,7,0,128,6,0,192,0,29,6,0,32,2,0,0,0,2,6,0,32,0,0,128,0,29,6,0,16,2,0,192,0,2,6,0,16,2,0,64,0,29,7,0,64,6,0,128,0,3,7,0,64,6,0,192,0,29,6,0,32,7,0,0,0,2,6,0,32,7,0,64,0,24,6,0,16,6,0,128,0,29,6,0,32,6,0,192,0,29,7,0,193,0,0,16,0,29,6,0,16,2,0,0,0,2,6,0,16,0,0,128,0,29,7,0,32,0,0,192,0,2,7,0,32,7,0,64,0,29,7,0,16,6,0,192,0,3,7,0,16,7,0,128,0,29,6,0,16,0,0,128,0,2,6,0,16,7,0,0,0,29,7,0,32,2,0,64,0,2,7,0,32,0,0,192,0,29,8,0,128,6,0,192,0,3,8,0,128,7,0,128,0,29,6,0,16,7,0,192,0,2,6,0,16,8,0,0,0,24,7,0,32,6,0,192,0,29,6,0,16,7,0,128,0,29,7,0,32,2,0,128,0,2,7,0,32,0,0,128,0,29,7,0,16,0,0,192,0,2,7,0,16,7,0,64,0,29,8,0,128,7,0,128,0,3,8,0,128,7,0,192,0,29,7,0,32,0,0,128,0,2,7,0,32,7,0,0,0,29,7,0,16,2,0,192,0,2,7,0,16,0,0,192,0,29,8,0,64,7,0,128,0,3,8,0,64,7,0,192,0,29,7,0,32,8,0,0,0,2,7,0,32,8,0,64,0,24,7,0,16,7,0,128,0,29,7,0,32,7,0,192,0,29,7,0,16,2,0,128,0,2,7,0,16,2,0,0,0,29,8,0,128,2,0,64,0,2,8,0,128,7,0,64,0,29,8,0,64,7,0,192,0,3,8,0,64,8,0,0,0,29,7,0,16,2,0,0,0,2,7,0,16,7,0,0,0,29,8,0,128,2,0,192,0,2,8,0,128,2,0,64,0,29,8,0,32,7,0,192,0,3,8,0,32,8,0,0,0,29,7,0,16,8,0,64,0,2,7,0,16,8,0,128,0,24,8,0,128,7,0,192,0,29,7,0,16,8,0,0,0,29,8,0,243,1,0,27,0,3,8,0,243,7,0,255,0,4,9,0,243,6,0,170,0,3,9,0,243,8,0,27,0,29,8,0,243,3,0,27,0,3,8,0,243,7,0,170,0,4,10,0,243,6,0,85,0,3,10,0,243,8,0,27,0,29,8,0,243,9,0,27,0,1,8,0,243,10,0,27,0,29,9,0,243,4,0,27,0,3,9,0,243,6,0,255,0,4,10,0,243,6,0,0,0,3,10,0,243,9,0,27,0,29,9,0,243,8,0,27,0,1,9,0,243,10,0,27,0,29,5,0,243,9,0,27,0];
  131. var ba:ByteArray = new ByteArray; for (var i:int = 0; i < sdata.length; i++) ba.writeByte (sdata [i]);
  132. s = new Shader (ba);
  133. list = l;
  134. del = new Delaunay(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
  135. }
  136. public function update():void {
  137. while(this.numChildren > 0) removeChildAt(this.numChildren - 1);
  138. del.clear();
  139. for each(var c:Circle in list) {
  140. var p:Point = new Point(c.x, c.y);
  141. del.insert(p);
  142. }
  143. var n:Vector.<Point> = del.getNode();
  144. var e:Vector.<Array> = del.getElem();
  145. for each(var ee:Array in e) {
  146. addChild(
  147. getLines(n[ee[0]], n[ee[1]], n[ee[2]],
  148. list[ee[0]].getLineColor(),list[ee[1]].getLineColor(),list[ee[2]].getLineColor()));
  149. }
  150. }
  151. private function getLines(p0:Point, p1:Point, p2:Point, c0:uint, c1:uint, c2:uint):Shape {
  152. s.data.point1.value = [p0.x, p0.y];
  153. s.data.point2.value = [p1.x, p1.y];
  154. s.data.point3.value = [p2.x, p2.y];
  155. s.data.color1.value = [((c0 & 0xFF0000) >> 16) / 255.0, ((c0 & 0x00FF00) >> 8) / 255.0, (c0 & 255) / 255.0, 1.0];
  156. s.data.color2.value = [((c1 & 0xFF0000) >> 16) / 255.0, ((c1 & 0x00FF00) >> 8) / 255.0, (c1 & 255) / 255.0, 1.0];
  157. s.data.color3.value = [((c2 & 0xFF0000) >> 16) / 255.0, ((c2 & 0x00FF00) >> 8) / 255.0, (c2 & 255) / 255.0, 1.0];
  158. var ret:Shape = new Shape();
  159. ret.graphics.beginShaderFill (s);
  160. ret.graphics.moveTo (p0.x, p0.y);
  161. ret.graphics.lineTo (p1.x, p1.y);
  162. ret.graphics.lineTo (p2.x, p2.y);
  163. ret.graphics.endFill ();
  164. /*ret.graphics.lineStyle(1, 0x444444);
  165. ret.graphics.moveTo(p0.x, p0.y);
  166. var tp:Number = Math.min(20 / dist(p0, p1), 1.0);
  167. ret.graphics.lineGradientStyle(GradientType.LINEAR, [c0,c1], [tp,tp], [0, 255], updateMatrix(p0,p1));
  168. ret.graphics.lineTo(p1.x, p1.y);
  169. tp = Math.min(20 / dist(p1, p2), 1.0);
  170. ret.graphics.lineGradientStyle(GradientType.LINEAR, [c1,c2], [tp,tp], [0, 255], updateMatrix(p1,p2));
  171. ret.graphics.lineTo(p2.x, p2.y);
  172. tp = Math.min(20 / dist(p2, p0), 1.0);
  173. ret.graphics.lineGradientStyle(GradientType.LINEAR, [c2, c0], [tp, tp], [0, 255], updateMatrix(p2,p0));
  174. ret.graphics.lineTo(p0.x, p0.y);*/
  175. return ret;
  176. }
  177. private function dist(p0:Point,p1:Point):Number {
  178. var xx:Number = p0.x - p1.x;
  179. var yy:Number = p0.y - p1.y;
  180. return Math.sqrt(xx*xx+yy*yy);
  181. }
  182. private function updateMatrix(p0:Point, p1:Point):Matrix {
  183. matrix.createGradientBox(p1.x - p0.x, p1.y - p0.y, 0, p0.x, p0.y);
  184. return matrix;
  185. }
  186. }
  187. import flash.geom.Point;
  188. import flash.geom.Rectangle;
  189. class Delaunay
  190. {
  191. private var EPS:Number = 1e-16;
  192. private var rect:Rectangle;
  193. private var min:Number;
  194. private var max:Number;
  195. private var data:Vector.<Point>;
  196. private var node:Vector.<Point>;
  197. private var elem:Array;
  198. private var map:Array;
  199. private var stack:Array;
  200. private var boundary:Array;
  201. private var boundaryID:Array;
  202. private var ids:int;
  203. private var bs:int;
  204. public function Delaunay(x:Number, y:Number, w:Number, h:Number ):void {
  205. rect= new Rectangle(x, y, w, h);
  206. min = Math.min(x,y,x+w,y+h);
  207. max = Math.max(x,y,x+w,y+h);
  208. data=new Vector.<Point>();
  209. node=new Vector.<Point>();
  210. elem=new Array();
  211. map=new Array();
  212. stack=new Array();
  213. boundary=new Array();
  214. boundaryID=new Array();
  215. node.push(new Point(-1.23,-0.5));
  216. node.push(new Point(2.23,-0.5));
  217. node.push(new Point(0.5,2.5));
  218. elem.push(new Array(0,1,2));
  219. map.push(new Array(-1,-1,-1));
  220. ids=0;
  221. bs=1;
  222. }
  223. public function clear():void {
  224. data=new Vector.<Point>();
  225. node=new Vector.<Point>();
  226. elem=new Array();
  227. map=new Array();
  228. stack=new Array();
  229. boundary=new Array();
  230. boundaryID=new Array();
  231. node.push(new Point(-1.23,-0.5));
  232. node.push(new Point(2.23,-0.5));
  233. node.push(new Point(0.5,2.5));
  234. elem.push(new Array(0,1,2));
  235. map.push(new Array( -1, -1, -1));
  236. ids=0;
  237. bs=1;
  238. }
  239. private function getTriangleById():Array {
  240. var et:Array=new Array();
  241. var id:int=0;
  242. for(var i:int=0;i<elem.length;i++){
  243. if(!checkBounds(i)){
  244. et.push(-1);
  245. }else if(!checkBoundaryState(i)){
  246. et.push(-1);
  247. }else{
  248. et.push(id++);
  249. }
  250. }
  251. var ee:Array=new Array();
  252. for(i=0;i<et.length;i++){
  253. var e:Array=this.elem[i];
  254. if(et[i]!=-1){
  255. ee.push(new Array(e[0]-3,e[1]-3,e[2]-3));
  256. }
  257. }
  258. return ee;
  259. }
  260. private function getTriangleMapById():Array {
  261. var et:Array=new Array();
  262. var id:int=0;
  263. for(var i:int=0;i<elem.length;i++){
  264. if(!checkBounds(i)){
  265. et.push(-1);
  266. }else if(!this.checkBoundaryState(i)){
  267. et.push(-1);
  268. }else{
  269. et.push(id++);
  270. }
  271. }
  272. var ee:Array=new Array();
  273. var tp:Array=new Array();
  274. for(i=0;i<et.length;i++){
  275. var m:Array=map[i];
  276. if(et[i]!=-1){
  277. for(var j:int=0;j<m.length;j++){
  278. if(m[j]==-1){
  279. tp[j]=-1;
  280. }else{
  281. tp[j]=et[m[j]];
  282. }
  283. }
  284. ee.push(new Array(tp[0],tp[1],tp[2]));
  285. }
  286. }
  287. return ee;
  288. }
  289. private function isLeft(a:Point,b:Point,p:Point):Number{
  290. var v0:Number=(a.y-p.y)*(b.x-p.x);
  291. var v1:Number=(a.x-p.x)*(b.y-p.y);
  292. if(Math.abs(v1-v0)<this.EPS){
  293. return 0;
  294. }else{
  295. return (v1-v0);
  296. }
  297. }
  298. public function getLocation(id:int, p:Point):int {
  299. var e:Array=elem[id];
  300. for(var i:int=0;i<e.length;i++){
  301. var a:Point=node[e[i]];
  302. var b:Point=node[e[(i+1)%3]];
  303. if(isLeft(a,b,p)<0){
  304. var n:int=map[id][i];
  305. if(n==-1){
  306. return -1;
  307. }
  308. return getLocation(n,p);
  309. }
  310. }
  311. return id;
  312. }
  313. private function checkBoundaryState(id:int):Boolean {
  314. if(bs>1){
  315. if(!checkBounds(id))return false;
  316. }
  317. var e:Array=elem[id];
  318. for (var i:int = 0; i < e.length; i++) {
  319. if(typeof boundaryID[e[i]]=="undefined")continue;
  320. var b0:int = boundaryID[e[i]];
  321. if(typeof boundaryID[e[(i + 1) % 3]]=="undefined")continue;
  322. var b1:int = boundaryID[e[(i + 1) % 3]];
  323. if (b0 - b1 == 0) {
  324. if(typeof boundary[e[(i + 1) % 3]]=="undefined")continue;
  325. var v0:int = boundary[e[(i + 1) % 3]];
  326. if(v0==e[i]){
  327. return false;
  328. }
  329. }
  330. }
  331. return true;
  332. }
  333. private function edge(elemId:int, targetId:int, mp:Array ):int {
  334. var j:Array=mp[elemId];
  335. for(var i:int=0;i<j.length;i++){
  336. if(j[i]==targetId)return i;
  337. }
  338. return -1;
  339. }
  340. private function isSwap(aId:int , bId:int, cId:int, pId:int):Boolean {
  341. var x13:Number=node[aId].x-node[cId].x;
  342. var y13:Number=node[aId].y-node[cId].y;
  343. var x23:Number=node[bId].x-node[cId].x;
  344. var y23:Number=node[bId].y-node[cId].y;
  345. var x1p:Number=node[aId].x-node[pId].x;
  346. var y1p:Number=node[aId].y-node[pId].y;
  347. var x2p:Number=node[bId].x-node[pId].x;
  348. var y2p:Number=node[bId].y-node[pId].y;
  349. var cosa:Number=x13*x23+y13*y23;
  350. var cosb:Number=x2p*x1p+y1p*y2p;
  351. if(cosa>=0&&cosb>=0){
  352. return false;
  353. }else if(cosa<0&&cosb<0){
  354. return true;
  355. }else{
  356. var sina:Number=x13*y23-x23*y13;
  357. var sinb:Number=x2p*y1p-x1p*y2p;
  358. if((sina*cosb+sinb*cosa)<0){
  359. return true;
  360. }else{
  361. return false;
  362. }
  363. }
  364. }
  365. public function getNode():Vector.<Point> {
  366. return data;
  367. }
  368. public function getElem():Vector.<Array> {
  369. var ret:Vector.<Array> = new Vector.<Array>();
  370. for each(var e:Array in elem) {
  371. if(e[0]<3||e[1]<3||e[2]<3){
  372. continue;
  373. }else{
  374. ret.push(new Array(e[0]-3, e[1]-3, e[2]-3));
  375. }
  376. }
  377. return ret;
  378. }
  379. private function normalize(x:Number, y:Number):Point {
  380. var xx:Number = (x - min) / (max - min);
  381. var yy:Number = (y - min) / (max - min);
  382. return new Point(xx,yy);
  383. }
  384. private function checkBounds(id:int):Boolean {
  385. var e:Array=elem[id];
  386. if(e[0]<3||e[1]<3||e[2]<3){
  387. return false;
  388. }else{
  389. return true;
  390. }
  391. }
  392. public function insert(pos:Point):Boolean {
  393. if (!rect.containsPoint(pos)) return false;
  394. var p:Point=normalize(pos.x,pos.y);
  395. ids = getLocation(ids, p);
  396. if(ids==-1){
  397. ids=0;
  398. return false;
  399. }else {
  400. if (checkBoundaryState(ids)) {
  401. data.push(pos);
  402. node.push(p);
  403. process(ids, node.length - 1);
  404. return true;
  405. }else {
  406. return false;
  407. }
  408. }
  409. }
  410. public function addBoundary(arg:Array,isClose:Boolean):void {
  411. var sz:int= node.length;
  412. for(var i:int=0;i<arg.length;i++){
  413. var p:Point=normalize(arg[i].x,arg[i].y);
  414. ids=getLocation(ids,p);
  415. if(ids==-1){
  416. ids=0;
  417. continue;
  418. }
  419. if(checkBoundaryState(ids)){
  420. data.push(arg[i]);
  421. node.push(p);
  422. if(i>0){
  423. boundary[sz+i-1]=sz+i;
  424. boundaryID[sz+i-1]=bs;
  425. }
  426. process(ids,node.length-1);
  427. }
  428. }
  429. if(isClose){
  430. boundary[node.length-1]=sz;
  431. boundaryID[node.length-1]=bs;
  432. }
  433. bs++;
  434. }
  435. private function isBoundary(nodeId0:int , nodeId1:int):Boolean {
  436. var p:int=boundary[nodeId0];
  437. if(!(typeof boundary[nodeId0]=="undefined")&&p==nodeId1)return true;
  438. p=boundary[nodeId1];
  439. if(!(typeof boundary[nodeId1]=="undefined")&&p==nodeId0){
  440. return true;
  441. }else{
  442. return false;
  443. }
  444. }
  445. private function process(elemId:int, nodeId:int):void {
  446. var nn:int=elem.length;
  447. var em:Array=elem[elemId];
  448. var te:Array=new Array(em[0],em[1],em[2]);
  449. var e0:Array=new Array(nodeId,em[0],em[1]);
  450. var e1:Array=new Array(nodeId,em[1],em[2]);
  451. var e2:Array=new Array(nodeId,em[2],em[0]);
  452. em[0]=e0[0];em[1]=e0[1];em[2]=e0[2];
  453. elem.push(e1);
  454. elem.push(e2);
  455. var jm:Array=map[elemId];
  456. var tmp:Array=new Array(jm[0],jm[1],jm[2]);
  457. var j0:Array=new Array(nn+1,jm[0],nn);
  458. var j1:Array=new Array(elemId,jm[1],nn+1);
  459. var j2:Array=new Array(nn,jm[2],elemId);
  460. jm[0]=j0[0];jm[1]=j0[1];jm[2]=j0[2];
  461. map.push(j1);
  462. map.push(j2);
  463. if(tmp[0]!=-1){
  464. if(!isBoundary(te[0],te[1]))stack.push(elemId);
  465. }
  466. if(tmp[1]!=-1){
  467. var ix:int=edge(tmp[1],elemId,map);
  468. map[tmp[1]][ix]=nn;
  469. if(!isBoundary(te[1],te[2]))stack.push(nn);
  470. }
  471. if(tmp[2]!=-1){
  472. ix=edge(tmp[2],elemId,map);
  473. map[tmp[2]][ix]=nn+1;
  474. if(!isBoundary(te[2],te[0]))stack.push(nn+1);
  475. }
  476. while (stack.length > 0) {
  477. var il:int=stack.pop();
  478. var ir:int=map[il][1];
  479. var ierl:int=edge(ir,il,map);
  480. var iera:int=(ierl+1)%3;
  481. var ierb:int=(iera+1)%3;
  482. var iv1:int=elem[ir][ierl];
  483. var iv2:int=elem[ir][iera];
  484. var iv3:int=elem[ir][ierb];
  485. if(isSwap(iv1,iv2,iv3,nodeId)){
  486. var ja:int=map[ir][iera];
  487. var jb:int=map[ir][ierb];
  488. var jc:int=map[il][2];
  489. elem[il][2]=iv3;
  490. map[il][1]=ja;
  491. map[il][2]=ir;
  492. var picElem:Array=elem[ir];
  493. picElem[0]=nodeId;picElem[1]=iv3;picElem[2]=iv1;
  494. picElem=map[ir];
  495. picElem[0]=il;picElem[1]=jb;picElem[2]=jc;
  496. if(ja!=-1){
  497. ix=edge(ja,ir,map);
  498. map[ja][ix]=il;
  499. if(!isBoundary(iv2,iv3))stack.push(il);
  500. }
  501. if(jb!=-1){
  502. if(!isBoundary(iv3,iv1))stack.push(ir);
  503. }
  504. if(jc!=-1){
  505. ix=edge(jc,il,this.map);
  506. map[jc][ix]=ir;
  507. }
  508. }
  509. }
  510. }
  511. }