From bd2880afe3e944767f280702fc513066968a386f Mon Sep 17 00:00:00 2001 From: Jan Marsch Date: Sun, 3 Apr 2016 23:57:10 +0200 Subject: [PATCH] missing vector methods added --- Gruntfile.js | 13 +- README.md | 4 + dist/GeoJSON.triangulate.js | 1 - ...angulate.debug.js => Triangulate.debug.js} | 718 +++++++++--------- dist/Triangulate.js | 1 + package.json | 4 +- src/triangulate.js | 6 +- src/vec2.js | 10 + src/vec3.js | 26 + src/vector.js | 34 - 10 files changed, 410 insertions(+), 407 deletions(-) delete mode 100644 dist/GeoJSON.triangulate.js rename dist/{GeoJSON.triangulate.debug.js => Triangulate.debug.js} (98%) create mode 100644 dist/Triangulate.js create mode 100644 src/vec2.js create mode 100644 src/vec3.js delete mode 100644 src/vector.js diff --git a/Gruntfile.js b/Gruntfile.js index 318e3fb..ef1ed06 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,20 +21,21 @@ module.exports = function(grunt) { separator: '\n', banner: "(function(global) {", footer: "if (typeof global.define === 'function') {"+ - "global.define([], GeoJSON);"+ + "global.define([], <%=pkg.name%>);"+ "} else if (typeof global.exports === 'object') {"+ - "global.module.exports = GeoJSON;"+ + "global.exports = <%=pkg.name%>;"+ "} else {"+ - "global.GeoJSON = GeoJSON;"+ + "global.<%=pkg.name%> = <%=pkg.name%>;"+ "}\n"+ "}(this));" }, src: [ - 'node_modules/Color/dist/Color.debug.js', + 'node_modules/Color/src/Color.js', 'node_modules/earcut/src/earcut.js', - 'src/GeoJSON.js', + 'src/vec2.js', + 'src/vec3.js', 'src/triangulate.js', - 'src/vector.js' + 'src/GeoJSON.js' ], dest: 'dist/<%=pkg.name%>.debug.js' } diff --git a/README.md b/README.md index e69de29..62b72dc 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,4 @@ + +# Triangulate + +Triangulation utility for OSM Buildings \ No newline at end of file diff --git a/dist/GeoJSON.triangulate.js b/dist/GeoJSON.triangulate.js deleted file mode 100644 index 14a55bd..0000000 --- a/dist/GeoJSON.triangulate.js +++ /dev/null @@ -1 +0,0 @@ -!function(a){function b(a,b,d){d=d||2;var f=b&&b.length,g=f?b[0]*d:a.length,h=c(a,0,g,d,!0),i=[];if(!h)return i;var k,l,m,n,o,p,q;if(f&&(h=j(a,b,h,d)),a.length>80*d){k=m=a[0],l=n=a[1];for(var r=d;g>r;r+=d)o=a[r],p=a[r+1],k>o&&(k=o),l>p&&(l=p),o>m&&(m=o),p>n&&(n=p);q=Math.max(m-k,n-l)}return e(h,i,d,k,l,q),i}function c(a,b,c,d,e){var f,g;if(e===D(a,b,c,d)>0)for(f=b;c>f;f+=d)g=A(f,a[f],a[f+1],g);else for(f=c-d;f>=b;f-=d)g=A(f,a[f],a[f+1],g);return g&&u(g,g.next)&&(B(g),g=g.next),g}function d(a,b){if(!a)return a;b||(b=a);var c,d=a;do if(c=!1,d.steiner||!u(d,d.next)&&0!==t(d.prev,d,d.next))d=d.next;else{if(B(d),d=b=d.prev,d===d.next)return null;c=!0}while(c||d!==b);return b}function e(a,b,c,j,k,l,m){if(a){!m&&l&&n(a,j,k,l);for(var o,p,q=a;a.prev!==a.next;)if(o=a.prev,p=a.next,l?g(a,j,k,l):f(a))b.push(o.i/c),b.push(a.i/c),b.push(p.i/c),B(a),a=p.next,q=p.next;else if(a=p,a===q){m?1===m?(a=h(a,b,c),e(a,b,c,j,k,l,2)):2===m&&i(a,b,c,j,k,l):e(d(a),b,c,j,k,l,1);break}}}function f(a){var b=a.prev,c=a,d=a.next;if(t(b,c,d)>=0)return!1;for(var e=a.next.next;e!==a.prev;){if(r(b.x,b.y,c.x,c.y,d.x,d.y,e.x,e.y)&&t(e.prev,e,e.next)>=0)return!1;e=e.next}return!0}function g(a,b,c,d){var e=a.prev,f=a,g=a.next;if(t(e,f,g)>=0)return!1;for(var h=e.xf.x?e.x>g.x?e.x:g.x:f.x>g.x?f.x:g.x,k=e.y>f.y?e.y>g.y?e.y:g.y:f.y>g.y?f.y:g.y,l=p(h,i,b,c,d),m=p(j,k,b,c,d),n=a.nextZ;n&&n.z<=m;){if(n!==a.prev&&n!==a.next&&r(e.x,e.y,f.x,f.y,g.x,g.y,n.x,n.y)&&t(n.prev,n,n.next)>=0)return!1;n=n.nextZ}for(n=a.prevZ;n&&n.z>=l;){if(n!==a.prev&&n!==a.next&&r(e.x,e.y,f.x,f.y,g.x,g.y,n.x,n.y)&&t(n.prev,n,n.next)>=0)return!1;n=n.prevZ}return!0}function h(a,b,c){var d=a;do{var e=d.prev,f=d.next.next;!u(e,f)&&v(e,d,d.next,f)&&x(e,f)&&x(f,e)&&(b.push(e.i/c),b.push(d.i/c),b.push(f.i/c),B(d),B(d.next),d=a=f),d=d.next}while(d!==a);return d}function i(a,b,c,f,g,h){var i=a;do{for(var j=i.next.next;j!==i.prev;){if(i.i!==j.i&&s(i,j)){var k=z(i,j);return i=d(i,i.next),k=d(k,k.next),e(i,b,c,f,g,h),void e(k,b,c,f,g,h)}j=j.next}i=i.next}while(i!==a)}function j(a,b,e,f){var g,h,i,j,m,n=[];for(g=0,h=b.length;h>g;g++)i=b[g]*f,j=h-1>g?b[g+1]*f:a.length,m=c(a,i,j,f,!1),m===m.next&&(m.steiner=!0),n.push(q(m));for(n.sort(k),g=0;g=d.next.y){var h=d.x+(f-d.y)*(d.next.x-d.x)/(d.next.y-d.y);if(e>=h&&h>g){if(g=h,h===e){if(f===d.y)return d;if(f===d.next.y)return d.next}c=d.x=d.x&&d.x>=k&&r(l>f?e:g,f,k,l,l>f?g:e,f,d.x,d.y)&&(i=Math.abs(f-d.y)/(e-d.x),(m>i||i===m&&d.x>c.x)&&x(d,a)&&(c=d,m=i)),d=d.next;return c}function n(a,b,c,d){var e=a;do null===e.z&&(e.z=p(e.x,e.y,b,c,d)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next;while(e!==a);e.prevZ.nextZ=null,e.prevZ=null,o(e)}function o(a){var b,c,d,e,f,g,h,i,j=1;do{for(c=a,a=null,f=null,g=0;c;){for(g++,d=c,h=0,b=0;j>b&&(h++,d=d.nextZ,d);b++);for(i=j;h>0||i>0&&d;)0===h?(e=d,d=d.nextZ,i--):0!==i&&d?c.z<=d.z?(e=c,c=c.nextZ,h--):(e=d,d=d.nextZ,i--):(e=c,c=c.nextZ,h--),f?f.nextZ=e:a=e,e.prevZ=f,f=e;c=d}f.nextZ=null,j*=2}while(g>1);return a}function p(a,b,c,d,e){return a=32767*(a-c)/e,b=32767*(b-d)/e,a=16711935&(a|a<<8),a=252645135&(a|a<<4),a=858993459&(a|a<<2),a=1431655765&(a|a<<1),b=16711935&(b|b<<8),b=252645135&(b|b<<4),b=858993459&(b|b<<2),b=1431655765&(b|b<<1),a|b<<1}function q(a){var b=a,c=a;do b.x=0&&(a-g)*(d-h)-(c-g)*(b-h)>=0&&(c-g)*(f-h)-(e-g)*(d-h)>=0}function s(a,b){return a.next.i!==b.i&&a.prev.i!==b.i&&!w(a,b)&&x(a,b)&&x(b,a)&&y(a,b)}function t(a,b,c){return(b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y)}function u(a,b){return a.x===b.x&&a.y===b.y}function v(a,b,c,d){return u(a,b)&&u(c,d)||u(a,d)&&u(c,b)?!0:t(a,b,c)>0!=t(a,b,d)>0&&t(c,d,a)>0!=t(c,d,b)>0}function w(a,b){var c=a;do{if(c.i!==a.i&&c.next.i!==a.i&&c.i!==b.i&&c.next.i!==b.i&&v(c,c.next,a,b))return!0;c=c.next}while(c!==a);return!1}function x(a,b){return t(a.prev,a,a.next)<0?t(a,b,a.next)>=0&&t(a,a.prev,b)>=0:t(a,b,a.prev)<0||t(a,a.next,b)<0}function y(a,b){var c=a,d=!1,e=(a.x+b.x)/2,f=(a.y+b.y)/2;do c.y>f!=c.next.y>f&&e<(c.next.x-c.x)*(f-c.y)/(c.next.y-c.y)+c.x&&(d=!d),c=c.next;while(c!==a);return d}function z(a,b){var c=new C(a.i,a.x,a.y),d=new C(b.i,b.x,b.y),e=a.next,f=b.prev;return a.next=b,b.prev=a,c.next=e,e.prev=c,d.next=c,c.prev=d,f.next=d,d.prev=f,d}function A(a,b,c,d){var e=new C(a,b,c);return d?(e.next=d.next,e.prev=d,d.next.prev=e,d.next=e):(e.prev=e,e.next=e),e}function B(a){a.next.prev=a.prev,a.prev.next=a.next,a.prevZ&&(a.prevZ.nextZ=a.nextZ),a.nextZ&&(a.nextZ.prevZ=a.prevZ)}function C(a,b,c){this.i=a,this.x=b,this.y=c,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function D(a,b,c,d){for(var e=0,f=b,g=c-d;c>f;f+=d)e+=(a[g]-a[f])*(a[f+1]+a[g+1]),g=f;return e}var E=function(a){function b(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+(b-a)*(2/3-c)*6:a}function c(a,b){return Math.min(b,Math.max(0,a||0))}var d={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},e=function(a){if(a=a||"","object"==typeof a){var b=a;this.R=c(b.r,max),this.G=c(b.g,max),this.B=c(b.b,max),this.A=void 0!==b.a?c(b.a,1):1,this.isValid=!0}else if("string"==typeof a){a=a.toLowerCase(),a=d[a]||a;var e;(e=a.match(/^#?(\w{2})(\w{2})(\w{2})$/))?(this.R=parseInt(e[1],16)/255,this.G=parseInt(e[2],16)/255,this.B=parseInt(e[3],16)/255,this.A=1,this.isValid=!0):(e=a.match(/rgba?\((\d+)\D+(\d+)\D+(\d+)(\D+([\d.]+))?\)/))&&(this.R=parseInt(e[1],10)/255,this.G=parseInt(e[2],10)/255,this.B=parseInt(e[3],10)/255,this.A=e[4]?parseFloat(e[5]):1,this.isValid=!0)}};return e.prototype={toHSL:function(){var a,b,c=Math.max(this.R,this.G,this.B),d=Math.min(this.R,this.G,this.B),e=(c+d)/2,f=c-d;if(f){switch(b=e>.5?f/(2-c-d):f/(c+d),c){case this.R:a=(this.G-this.B)/f+(this.Gh;h++){var j=b[h]*c,k=i-1>h?b[h+1]*c:a.length;g-=Math.abs(D(a,j,k,c))}var l=0;for(h=0;hg;g++)c.vertices.push(a[e][f][g]);e>0&&(d+=a[e-1].length,c.holes.push(d))}return c},void 0===F)var F={};!function(){function a(a,f,i,l,m,o){var p=g(l,m),q=h(p[0]),r=(q.maxX-q.minX)/2,s=[q.minX+(q.maxX-q.minX)/2,q.minY+(q.maxY-q.minY)/2],t=i.height||(i.levels?i.levels*n:j),u=i.minHeight||(i.minLevel?i.minLevel*n:0),v=i.roofHeight||k,w=(f/2%2?-1:1)*(f%2?.03:.06),x=d(o||i.roofColor||i.color||e(i.roofMaterial),w),y=d(o||i.wallColor||i.color||e(i.material),w);switch(i.roofShape){case"cone":case"dome":case"onion":case"pyramid":case"pyramidal":t=Math.max(0,t-v);break;default:v=0}b(a,i,p,s,r,t-u,u,y),c(a,i,p,s,r,v,t,x)}function b(a,b,c,d,e,f,g,h){switch(b.shape){case"cylinder":G.cylinder(a,d,e,e,f,g,h);break;case"cone":G.cylinder(a,d,e,0,f,g,h);break;case"dome":G.dome(a,d,e,f||e,g,h);break;case"sphere":G.sphere(a,d,e,f||2*e,g,h);break;case"pyramid":case"pyramidal":G.pyramid(a,c,d,f,g,h);break;case"none":return;default:var i=.2,j=.4;"glass"!==b.material&&(i=0,j=0,b.levels&&(j=parseFloat(b.levels)-parseFloat(b.minLevel||0)<<0)),G.extrusion(a,c,f,g,h,[0,m,i/f,j/f])}}function c(a,b,c,d,e,f,g,h){switch(b.shape){case"cone":case"pyramid":case"pyramidal":return}switch(b.roofShape){case"cone":G.cylinder(a,d,e,0,f,g,h);break;case"dome":case"onion":G.dome(a,d,e,f||e,g,h);break;case"pyramid":case"pyramidal":"cylinder"===b.shape?G.cylinder(a,d,e,0,f,g,h):G.pyramid(a,c,d,f,g,h);break;default:"cylinder"===b.shape?G.circle(a,d,e,g,h):G.polygon(a,c,g,h)}}function d(a,b){var c=new E(a||l).toArray();return[c[0]+b,c[1]+b,c[2]+b]}function e(a){return"string"!=typeof a?null:(a=a.toLowerCase(),"#"===a[0]?a:o[p[a]||a]||null)}function f(a){switch(a.type){case"MultiPolygon":return a.coordinates;case"Polygon":return[a.coordinates];default:return[]}}function g(a,b){var c=i*Math.cos(b[1]/180*Math.PI);return a.map(function(a,d){return 0===d!==isClockWise(a)&&a.reverse(),a.map(function(a){return[(a[0]-b[0])*c,-(a[1]-b[1])*i]})})}function h(a){for(var b=1/0,c=1/0,d=-(1/0),e=-(1/0),f=0;fi;i++)a(b,c,d.properties,h[i],e,g)}}();var G={NUM_Y_SEGMENTS:24,NUM_X_SEGMENTS:32,quad:function(a,b,c,d,e,f){this.triangle(a,b,c,d,f),this.triangle(a,d,e,b,f)},triangle:function(a,b,c,d,e){var f=H.normal3(b,c,d);[].push.apply(a.vertices,[].concat(b,d,c)),[].push.apply(a.normals,[].concat(f,f,f)),[].push.apply(a.colors,[].concat(e,e,e)),a.texCoords.push(0,0,0,0,0,0)},circle:function(a,b,c,d,e){d=d||0;for(var f,g,h=0;hf;f++){for(var k=0;kf;f+=3)this.triangle(a,[h[2*l[f]],h[2*l[f]+1],d],[h[2*l[f+1]],h[2*l[f+1]+1],d],[h[2*l[f+2]],h[2*l[f+2]+1],d],e)},cube:function(a,b,c,d,e,f,g,h){e=e||0,f=f||0,g=g||0;var i=[e,f,g],j=[e+b,f,g],k=[e+b,f+c,g],l=[e,f+c,g],m=[e,f,g+d],n=[e+b,f,g+d],o=[e+b,f+c,g+d],p=[e,f+c,g+d];this.quad(a,j,i,l,k,h),this.quad(a,m,n,o,p,h),this.quad(a,i,j,n,m,h),this.quad(a,j,k,o,n,h),this.quad(a,k,l,p,o,h),this.quad(a,l,i,m,p,h)},cylinder:function(a,b,c,d,e,f,g){f=f||0;for(var h,i,j,k,l,m,n=this.NUM_X_SEGMENTS,o=2*Math.PI,p=0;n>p;p++)h=p/n*o,i=(p+1)/n*o,j=Math.sin(h),k=Math.cos(h),l=Math.sin(i),m=Math.cos(i),this.triangle(a,[b[0]+c*j,b[1]+c*k,f],[b[0]+d*l,b[1]+d*m,f+e],[b[0]+c*l,b[1]+c*m,f],g),0!==d&&this.triangle(a,[b[0]+d*j,b[1]+d*k,f+e],[b[0]+d*l,b[1]+d*m,f+e],[b[0]+c*j,b[1]+c*k,f],g)},dome:function(a,b,c,d,e,f){e=e||0;for(var g,h,i,j,k,l,m,n,o,p,q=this.NUM_Y_SEGMENTS/2,r=Math.PI/2,s=0;q>s;s++)g=s/q*r-r,h=(s+1)/q*r-r,i=Math.sin(g),j=Math.cos(g),k=Math.sin(h),l=Math.cos(h),m=j*c,n=l*c,o=(k-i)*d,p=e-k*d,this.cylinder(a,b,n,m,o,p,f)},sphere:function(a,b,c,d,e,f){return e=e||0,this.cylinder(a,b,c,c,d,e,f)},pyramid:function(a,b,c,d,e,f){e=e||0,b=b[0];for(var g=0,h=b.length-1;h>g;g++)this.triangle(a,[b[g][0],b[g][1],e],[b[g+1][0],b[g+1][1],e],[c[0],c[1],e+d],f)},extrusion:function(a,b,c,d,e,f){d=d||0;for(var g,h,i,j,k,l,m,n,o,p,q,r,s=f[2]*c,t=f[3]*c,u=0,v=b.length;v>u;u++){g=b[u],h=g.length-1,g[0][0]===g[h][0]&&g[0][1]===g[h][1]||(g.push(g[0]),h++);for(var w=0;h>w;w++)i=g[w],j=g[w+1],k=H.len2(H.sub2(i,j)),q=f[0]*k<<0,r=f[1]*k<<0,l=[i[0],i[1],d],m=[j[0],j[1],d],n=[j[0],j[1],d+c],o=[i[0],i[1],d+c],p=H.normal3(l,m,n),[].push.apply(a.vertices,[].concat(l,n,m,l,o,n)),[].push.apply(a.normals,[].concat(p,p,p,p,p,p)),[].push.apply(a.colors,[].concat(e,e,e,e,e,e)),a.texCoords.push(q,t,r,s,r,t,q,t,q,s,r,s)}}},H={len2:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])},len3:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])},sub2:function(a,b){return[a[0]-b[0],a[1]-b[1]]},sub3:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},unit3:function(a){var b=this.len3(a);return[a[0]/b,a[1]/b,a[2]/b]},normal3:function(a,b,c){var d=this.sub3(a,b),e=this.sub3(b,c);return this.unit3([d[1]*e[2]-d[2]*e[1],d[2]*e[0]-d[0]*e[2],d[0]*e[1]-d[1]*e[0]])}};"function"==typeof a.define?a.define([],F):"object"==typeof a.exports?a.module.exports=F:a.GeoJSON=F}(this); \ No newline at end of file diff --git a/dist/GeoJSON.triangulate.debug.js b/dist/Triangulate.debug.js similarity index 98% rename from dist/GeoJSON.triangulate.debug.js rename to dist/Triangulate.debug.js index 1562c0e..fe2075f 100644 --- a/dist/GeoJSON.triangulate.debug.js +++ b/dist/Triangulate.debug.js @@ -1,6 +1,4 @@ -(function(global) {var Color = (function(window) { - - +(function(global) { var w3cColors = { aliceblue: '#f0f8ff', antiquewhite: '#faebd7', @@ -177,7 +175,6 @@ var Color = function(str) { this.G = clamp(rgba.g, max); this.B = clamp(rgba.b, max); this.A = (rgba.a !== undefined ? clamp(rgba.a, 1) : 1); - this.isValid = true; } else if (typeof str === 'string') { str = str.toLowerCase(); str = w3cColors[str] || str; @@ -187,13 +184,11 @@ var Color = function(str) { this.G = parseInt(m[2], 16) / 255; this.B = parseInt(m[3], 16) / 255; this.A = 1; - this.isValid = true; } else if ((m = str.match(/rgba?\((\d+)\D+(\d+)\D+(\d+)(\D+([\d.]+))?\)/))) { this.R = parseInt(m[1], 10) / 255; this.G = parseInt(m[2], 10) / 255; this.B = parseInt(m[3], 10) / 255; this.A = m[4] ? parseFloat(m[5]) : 1; - this.isValid = true; } } }; @@ -264,7 +259,6 @@ Color.prototype = { }, saturation: function(s) { - debugger var hsl = this.toHSL(); hsl.s *= s; this.fromHSL(hsl); @@ -283,7 +277,6 @@ Color.prototype = { return this; } }; -return Color; }(this)); 'use strict'; module.exports = earcut; @@ -930,348 +923,111 @@ earcut.flatten = function (data) { }; -if (GeoJSON === undefined) { - var GeoJSON = {}; -} - -(function() { - - //var EARTH_RADIUS_IN_METERS = 6378137; - //var EARTH_CIRCUMFERENCE_IN_METERS = EARTH_RADIUS_IN_METERS * Math.PI * 2; - //var METERS_PER_DEGREE_LATITUDE = EARTH_CIRCUMFERENCE_IN_METERS / 360; - - var METERS_PER_DEGREE_LATITUDE = 6378137 * Math.PI / 180; - - var DEFAULT_HEIGHT = 10; - var DEFAULT_ROOF_HEIGHT = 3; - var DEFAULT_COLOR = 'rgb(220, 210, 200)'; - - // number of windows per horizontal meter of building wall - var WINDOWS_PER_METER = 0.5; - var METERS_PER_LEVEL = 3; - - var MATERIAL_COLORS = { - brick: '#cc7755', - bronze: '#ffeecc', - canvas: '#fff8f0', - concrete: '#999999', - copper: '#a0e0d0', - glass: '#e8f8f8', - gold: '#ffcc00', - plants: '#009933', - metal: '#aaaaaa', - panel: '#fff8f0', - plaster: '#999999', - roof_tiles: '#f08060', - silver: '#cccccc', - slate: '#666666', - stone: '#996666', - tar_paper: '#333333', - wood: '#deb887' - }; - - var BASE_MATERIALS = { - asphalt: 'tar_paper', - bitumen: 'tar_paper', - block: 'stone', - bricks: 'brick', - glas: 'glass', - glassfront: 'glass', - grass: 'plants', - masonry: 'stone', - granite: 'stone', - panels: 'panel', - paving_stones: 'stone', - plastered: 'plaster', - rooftiles: 'roof_tiles', - roofingfelt: 'tar_paper', - sandstone: 'stone', - sheet: 'canvas', - sheets: 'canvas', - shingle: 'tar_paper', - shingles: 'tar_paper', - slates: 'slate', - steel: 'metal', - tar: 'tar_paper', - tent: 'canvas', - thatch: 'plants', - tile: 'roof_tiles', - tiles: 'roof_tiles' - // cardboard - // eternit - // limestone - // straw - }; - - GeoJSON.getPosition = function(geometry) { - var coordinates = geometry.coordinates; - switch (geometry.type) { - case 'Point': - return coordinates; - - case 'MultiPoint': - case 'LineString': - return coordinates[0]; - - case 'MultiLineString': - case 'Polygon': - return coordinates[0][0]; - - case 'MultiPolygon': - return coordinates[0][0][0]; - } - }; +var vec2 = { + len: function(a) { + return Math.sqrt(a[0]*a[0] + a[1]*a[1]); + }, - GeoJSON.triangulate = function(res, id, feature, position, color) { - var geometries = flattenGeometry(feature.geometry); - for (var i = 0, il = geometries.length; ic&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+(b-a)*(2/3-c)*6:a}function c(a,b){return Math.min(b,Math.max(0,a||0))}function d(a,b,c){c=c||2;var d=b&&b.length,f=d?b[0]*c:a.length,h=e(a,0,f,c,!0),i=[];if(!h)return i;var j,k,m,n,o,p,q;if(d&&(h=l(a,b,h,c)),a.length>80*c){j=m=a[0],k=n=a[1];for(var r=c;f>r;r+=c)o=a[r],p=a[r+1],j>o&&(j=o),k>p&&(k=p),o>m&&(m=o),p>n&&(n=p);q=Math.max(m-j,n-k)}return g(h,i,c,j,k,q),i}function e(a,b,c,d,e){var f,g;if(e===F(a,b,c,d)>0)for(f=b;c>f;f+=d)g=C(f,a[f],a[f+1],g);else for(f=c-d;f>=b;f-=d)g=C(f,a[f],a[f+1],g);return g&&w(g,g.next)&&(D(g),g=g.next),g}function f(a,b){if(!a)return a;b||(b=a);var c,d=a;do if(c=!1,d.steiner||!w(d,d.next)&&0!==v(d.prev,d,d.next))d=d.next;else{if(D(d),d=b=d.prev,d===d.next)return null;c=!0}while(c||d!==b);return b}function g(a,b,c,d,e,l,m){if(a){!m&&l&&p(a,d,e,l);for(var n,o,q=a;a.prev!==a.next;)if(n=a.prev,o=a.next,l?i(a,d,e,l):h(a))b.push(n.i/c),b.push(a.i/c),b.push(o.i/c),D(a),a=o.next,q=o.next;else if(a=o,a===q){m?1===m?(a=j(a,b,c),g(a,b,c,d,e,l,2)):2===m&&k(a,b,c,d,e,l):g(f(a),b,c,d,e,l,1);break}}}function h(a){var b=a.prev,c=a,d=a.next;if(v(b,c,d)>=0)return!1;for(var e=a.next.next;e!==a.prev;){if(t(b.x,b.y,c.x,c.y,d.x,d.y,e.x,e.y)&&v(e.prev,e,e.next)>=0)return!1;e=e.next}return!0}function i(a,b,c,d){var e=a.prev,f=a,g=a.next;if(v(e,f,g)>=0)return!1;for(var h=e.xf.x?e.x>g.x?e.x:g.x:f.x>g.x?f.x:g.x,k=e.y>f.y?e.y>g.y?e.y:g.y:f.y>g.y?f.y:g.y,l=r(h,i,b,c,d),m=r(j,k,b,c,d),n=a.nextZ;n&&n.z<=m;){if(n!==a.prev&&n!==a.next&&t(e.x,e.y,f.x,f.y,g.x,g.y,n.x,n.y)&&v(n.prev,n,n.next)>=0)return!1;n=n.nextZ}for(n=a.prevZ;n&&n.z>=l;){if(n!==a.prev&&n!==a.next&&t(e.x,e.y,f.x,f.y,g.x,g.y,n.x,n.y)&&v(n.prev,n,n.next)>=0)return!1;n=n.prevZ}return!0}function j(a,b,c){var d=a;do{var e=d.prev,f=d.next.next;!w(e,f)&&x(e,d,d.next,f)&&z(e,f)&&z(f,e)&&(b.push(e.i/c),b.push(d.i/c),b.push(f.i/c),D(d),D(d.next),d=a=f),d=d.next}while(d!==a);return d}function k(a,b,c,d,e,h){var i=a;do{for(var j=i.next.next;j!==i.prev;){if(i.i!==j.i&&u(i,j)){var k=B(i,j);return i=f(i,i.next),k=f(k,k.next),g(i,b,c,d,e,h),void g(k,b,c,d,e,h)}j=j.next}i=i.next}while(i!==a)}function l(a,b,c,d){var g,h,i,j,k,l=[];for(g=0,h=b.length;h>g;g++)i=b[g]*d,j=h-1>g?b[g+1]*d:a.length,k=e(a,i,j,d,!1),k===k.next&&(k.steiner=!0),l.push(s(k));for(l.sort(m),g=0;g=d.next.y){var h=d.x+(f-d.y)*(d.next.x-d.x)/(d.next.y-d.y);if(e>=h&&h>g){if(g=h,h===e){if(f===d.y)return d;if(f===d.next.y)return d.next}c=d.x=d.x&&d.x>=k&&t(l>f?e:g,f,k,l,l>f?g:e,f,d.x,d.y)&&(i=Math.abs(f-d.y)/(e-d.x),(m>i||i===m&&d.x>c.x)&&z(d,a)&&(c=d,m=i)),d=d.next;return c}function p(a,b,c,d){var e=a;do null===e.z&&(e.z=r(e.x,e.y,b,c,d)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next;while(e!==a);e.prevZ.nextZ=null,e.prevZ=null,q(e)}function q(a){var b,c,d,e,f,g,h,i,j=1;do{for(c=a,a=null,f=null,g=0;c;){for(g++,d=c,h=0,b=0;j>b&&(h++,d=d.nextZ,d);b++);for(i=j;h>0||i>0&&d;)0===h?(e=d,d=d.nextZ,i--):0!==i&&d?c.z<=d.z?(e=c,c=c.nextZ,h--):(e=d,d=d.nextZ,i--):(e=c,c=c.nextZ,h--),f?f.nextZ=e:a=e,e.prevZ=f,f=e;c=d}f.nextZ=null,j*=2}while(g>1);return a}function r(a,b,c,d,e){return a=32767*(a-c)/e,b=32767*(b-d)/e,a=16711935&(a|a<<8),a=252645135&(a|a<<4),a=858993459&(a|a<<2),a=1431655765&(a|a<<1),b=16711935&(b|b<<8),b=252645135&(b|b<<4),b=858993459&(b|b<<2),b=1431655765&(b|b<<1),a|b<<1}function s(a){var b=a,c=a;do b.x=0&&(a-g)*(d-h)-(c-g)*(b-h)>=0&&(c-g)*(f-h)-(e-g)*(d-h)>=0}function u(a,b){return a.next.i!==b.i&&a.prev.i!==b.i&&!y(a,b)&&z(a,b)&&z(b,a)&&A(a,b)}function v(a,b,c){return(b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y)}function w(a,b){return a.x===b.x&&a.y===b.y}function x(a,b,c,d){return w(a,b)&&w(c,d)||w(a,d)&&w(c,b)?!0:v(a,b,c)>0!=v(a,b,d)>0&&v(c,d,a)>0!=v(c,d,b)>0}function y(a,b){var c=a;do{if(c.i!==a.i&&c.next.i!==a.i&&c.i!==b.i&&c.next.i!==b.i&&x(c,c.next,a,b))return!0;c=c.next}while(c!==a);return!1}function z(a,b){return v(a.prev,a,a.next)<0?v(a,b,a.next)>=0&&v(a,a.prev,b)>=0:v(a,b,a.prev)<0||v(a,a.next,b)<0}function A(a,b){var c=a,d=!1,e=(a.x+b.x)/2,f=(a.y+b.y)/2;do c.y>f!=c.next.y>f&&e<(c.next.x-c.x)*(f-c.y)/(c.next.y-c.y)+c.x&&(d=!d),c=c.next;while(c!==a);return d}function B(a,b){var c=new E(a.i,a.x,a.y),d=new E(b.i,b.x,b.y),e=a.next,f=b.prev;return a.next=b,b.prev=a,c.next=e,e.prev=c,d.next=c,c.prev=d,f.next=d,d.prev=f,d}function C(a,b,c,d){var e=new E(a,b,c);return d?(e.next=d.next,e.prev=d,d.next.prev=e,d.next=e):(e.prev=e,e.next=e),e}function D(a){a.next.prev=a.prev,a.prev.next=a.next,a.prevZ&&(a.prevZ.nextZ=a.nextZ),a.nextZ&&(a.nextZ.prevZ=a.prevZ)}function E(a,b,c){this.i=a,this.x=b,this.y=c,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function F(a,b,c,d){for(var e=0,f=b,g=c-d;c>f;f+=d)e+=(a[g]-a[f])*(a[f+1]+a[g+1]),g=f;return e}var G={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},H=function(a){if(a=a||"","object"==typeof a){var b=a;this.R=c(b.r,max),this.G=c(b.g,max),this.B=c(b.b,max),this.A=void 0!==b.a?c(b.a,1):1}else if("string"==typeof a){a=a.toLowerCase(),a=G[a]||a;var d;(d=a.match(/^#?(\w{2})(\w{2})(\w{2})$/))?(this.R=parseInt(d[1],16)/255,this.G=parseInt(d[2],16)/255,this.B=parseInt(d[3],16)/255,this.A=1):(d=a.match(/rgba?\((\d+)\D+(\d+)\D+(\d+)(\D+([\d.]+))?\)/))&&(this.R=parseInt(d[1],10)/255,this.G=parseInt(d[2],10)/255,this.B=parseInt(d[3],10)/255,this.A=d[4]?parseFloat(d[5]):1)}};H.prototype={toHSL:function(){var a,b,c=Math.max(this.R,this.G,this.B),d=Math.min(this.R,this.G,this.B),e=(c+d)/2,f=c-d;if(f){switch(b=e>.5?f/(2-c-d):f/(c+d),c){case this.R:a=(this.G-this.B)/f+(this.Gh;h++){var j=b[h]*c,k=i-1>h?b[h+1]*c:a.length;g-=Math.abs(F(a,j,k,c))}var l=0;for(h=0;hg;g++)c.vertices.push(a[e][f][g]);e>0&&(d+=a[e-1].length,c.holes.push(d))}return c};var I={len:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])},sub:function(a,b){return[a[0]-b[0],a[1]-b[1]]}},J={len:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])},sub:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},unit:function(a){var b=this.len(a);return[a[0]/b,a[1]/b,a[2]/b]},normal:function(a,b,c){var d=this.sub(a,b),e=this.sub(b,c);return this.unit([d[1]*e[2]-d[2]*e[1],d[2]*e[0]-d[0]*e[2],d[0]*e[1]-d[1]*e[0]])}},K={NUM_Y_SEGMENTS:24,NUM_X_SEGMENTS:32,quad:function(a,b,c,d,e,f){this.triangle(a,b,c,d,f),this.triangle(a,d,e,b,f)},triangle:function(a,b,c,d,e){var f=J.normal(b,c,d);[].push.apply(a.vertices,[].concat(b,d,c)),[].push.apply(a.normals,[].concat(f,f,f)),[].push.apply(a.colors,[].concat(e,e,e)),a.texCoords.push(0,0,0,0,0,0)},circle:function(a,b,c,d,e){d=d||0;for(var f,g,h=0;hf;f++){for(var k=0;kf;f+=3)this.triangle(a,[h[2*l[f]],h[2*l[f]+1],c],[h[2*l[f+1]],h[2*l[f+1]+1],c],[h[2*l[f+2]],h[2*l[f+2]+1],c],e)},cube:function(a,b,c,d,e,f,g,h){e=e||0,f=f||0,g=g||0;var i=[e,f,g],j=[e+b,f,g],k=[e+b,f+c,g],l=[e,f+c,g],m=[e,f,g+d],n=[e+b,f,g+d],o=[e+b,f+c,g+d],p=[e,f+c,g+d];this.quad(a,j,i,l,k,h),this.quad(a,m,n,o,p,h),this.quad(a,i,j,n,m,h),this.quad(a,j,k,o,n,h),this.quad(a,k,l,p,o,h),this.quad(a,l,i,m,p,h)},cylinder:function(a,b,c,d,e,f,g){f=f||0;for(var h,i,j,k,l,m,n=this.NUM_X_SEGMENTS,o=2*Math.PI,p=0;n>p;p++)h=p/n*o,i=(p+1)/n*o,j=Math.sin(h),k=Math.cos(h),l=Math.sin(i),m=Math.cos(i),this.triangle(a,[b[0]+c*j,b[1]+c*k,f],[b[0]+d*l,b[1]+d*m,f+e],[b[0]+c*l,b[1]+c*m,f],g),0!==d&&this.triangle(a,[b[0]+d*j,b[1]+d*k,f+e],[b[0]+d*l,b[1]+d*m,f+e],[b[0]+c*j,b[1]+c*k,f],g)},dome:function(a,b,c,d,e,f){e=e||0;for(var g,h,i,j,k,l,m,n,o,p,q=this.NUM_Y_SEGMENTS/2,r=Math.PI/2,s=0;q>s;s++)g=s/q*r-r,h=(s+1)/q*r-r,i=Math.sin(g),j=Math.cos(g),k=Math.sin(h),l=Math.cos(h),m=j*c,n=l*c,o=(k-i)*d,p=e-k*d,this.cylinder(a,b,n,m,o,p,f)},sphere:function(a,b,c,d,e,f){return e=e||0,this.cylinder(a,b,c,c,d,e,f)},pyramid:function(a,b,c,d,e,f){e=e||0,b=b[0];for(var g=0,h=b.length-1;h>g;g++)this.triangle(a,[b[g][0],b[g][1],e],[b[g+1][0],b[g+1][1],e],[c[0],c[1],e+d],f)},extrusion:function(a,b,c,d,e,f){d=d||0;for(var g,h,i,j,k,l,m,n,o,p,q,r,s=f[2]*c,t=f[3]*c,u=0,v=b.length;v>u;u++){g=b[u],h=g.length-1,g[0][0]===g[h][0]&&g[0][1]===g[h][1]||(g.push(g[0]),h++);for(var w=0;h>w;w++)i=g[w],j=g[w+1],k=I.len(I.sub(i,j)),q=f[0]*k<<0,r=f[1]*k<<0,l=[i[0],i[1],d],m=[j[0],j[1],d],n=[j[0],j[1],d+c],o=[i[0],i[1],d+c],p=J.normal(l,m,n),[].push.apply(a.vertices,[].concat(l,n,m,l,o,n)),[].push.apply(a.normals,[].concat(p,p,p,p,p,p)),[].push.apply(a.colors,[].concat(e,e,e,e,e,e)),a.texCoords.push(q,t,r,s,r,t,q,t,q,s,r,s)}}};if(void 0===L)var L={};!function(){function a(a,f,i,l,m,o){var p=g(l,m),q=h(p[0]),r=(q.maxX-q.minX)/2,s=[q.minX+(q.maxX-q.minX)/2,q.minY+(q.maxY-q.minY)/2],t=i.height||(i.levels?i.levels*n:j),u=i.minHeight||(i.minLevel?i.minLevel*n:0),v=i.roofHeight||k,w=(f/2%2?-1:1)*(f%2?.03:.06),x=d(o||i.roofColor||i.color||e(i.roofMaterial),w),y=d(o||i.wallColor||i.color||e(i.material),w);switch(i.roofShape){case"cone":case"dome":case"onion":case"pyramid":case"pyramidal":t=Math.max(0,t-v);break;default:v=0}b(a,i,p,s,r,t-u,u,y),c(a,i,p,s,r,v,t,x)}function b(a,b,c,d,e,f,g,h){switch(b.shape){case"cylinder":K.cylinder(a,d,e,e,f,g,h);break;case"cone":K.cylinder(a,d,e,0,f,g,h);break;case"dome":K.dome(a,d,e,f||e,g,h);break;case"sphere":K.sphere(a,d,e,f||2*e,g,h);break;case"pyramid":case"pyramidal":K.pyramid(a,c,d,f,g,h);break;case"none":return;default:var i=.2,j=.4;"glass"!==b.material&&(i=0,j=0,b.levels&&(j=parseFloat(b.levels)-parseFloat(b.minLevel||0)<<0)),K.extrusion(a,c,f,g,h,[0,m,i/f,j/f])}}function c(a,b,c,d,e,f,g,h){switch(b.shape){case"cone":case"pyramid":case"pyramidal":return}switch(b.roofShape){case"cone":K.cylinder(a,d,e,0,f,g,h);break;case"dome":case"onion":K.dome(a,d,e,f||e,g,h);break;case"pyramid":case"pyramidal":"cylinder"===b.shape?K.cylinder(a,d,e,0,f,g,h):K.pyramid(a,c,d,f,g,h);break;default:"cylinder"===b.shape?K.circle(a,d,e,g,h):K.polygon(a,c,g,h)}}function d(a,b){var c=new H(a||l).toArray();return[c[0]+b,c[1]+b,c[2]+b]}function e(a){return"string"!=typeof a?null:(a=a.toLowerCase(),"#"===a[0]?a:o[p[a]||a]||null)}function f(a){switch(a.type){case"MultiPolygon":return a.coordinates;case"Polygon":return[a.coordinates];default:return[]}}function g(a,b){var c=i*Math.cos(b[1]/180*Math.PI);return a.map(function(a,d){return 0===d!==isClockWise(a)&&a.reverse(),a.map(function(a){return[(a[0]-b[0])*c,-(a[1]-b[1])*i]})})}function h(a){for(var b=1/0,c=1/0,d=-(1/0),e=-(1/0),f=0;fi;i++)a(b,c,d.properties,h[i],e,g)}}(),"function"==typeof a.define?a.define([],Triangulate):"object"==typeof a.exports?a.exports=Triangulate:a.Triangulate=Triangulate}(this); \ No newline at end of file diff --git a/package.json b/package.json index 21e6fb9..b32c8f7 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "GeoJSON.triangulate", + "name": "Triangulate", "version": "0.1.0", "homepage": "http://osmbuildings.org", "description": "GeoJSON triangulation scripts collection. Mainly used for OSM Buildings backend + frontend.", @@ -7,7 +7,7 @@ "scripts": {}, "repository": { "type": "git", - "url": "https://github.com/OSMBuildings/GeoJSON.triangulate.git" + "url": "https://github.com/OSMBuildings/Triangulate.git" }, "author": "@kekscom", "dependencies": { diff --git a/src/triangulate.js b/src/triangulate.js index 3ebde55..82800e1 100644 --- a/src/triangulate.js +++ b/src/triangulate.js @@ -14,7 +14,7 @@ var triangulate = { }, triangle: function(data, a, b, c, color) { - var n = vector.normal3(a, b, c); + var n = vec3.normal(a, b, c); [].push.apply(data.vertices, [].concat(a, c, b)); [].push.apply(data.normals, [].concat(n, n, n)); [].push.apply(data.colors, [].concat(color, color, color)); @@ -259,7 +259,7 @@ var triangulate = { for (var r = 0; r < last; r++) { a = ring[r]; b = ring[r+1]; - L = vector.len2(vector.sub2(a, b)); + L = vec2.len(vec2.sub(a, b)); tx1 = (tx[0]*L) <<0; tx2 = (tx[1]*L) <<0; @@ -269,7 +269,7 @@ var triangulate = { v2 = [ b[0], b[1], Z+height]; v3 = [ a[0], a[1], Z+height]; - n = vector.normal3(v0, v1, v2); + n = vec3.normal(v0, v1, v2); [].push.apply(data.vertices, [].concat(v0, v2, v1, v0, v3, v2)); [].push.apply(data.normals, [].concat(n, n, n, n, n, n)); [].push.apply(data.colors, [].concat(color, color, color, color, color, color)); diff --git a/src/vec2.js b/src/vec2.js new file mode 100644 index 0000000..efcd249 --- /dev/null +++ b/src/vec2.js @@ -0,0 +1,10 @@ + +var vec2 = { + len: function(a) { + return Math.sqrt(a[0]*a[0] + a[1]*a[1]); + }, + + sub: function(a, b) { + return [a[0]-b[0], a[1]-b[1]]; + } +}; diff --git a/src/vec3.js b/src/vec3.js new file mode 100644 index 0000000..49aea0b --- /dev/null +++ b/src/vec3.js @@ -0,0 +1,26 @@ + +var vec3 = { + len: function(a) { + return Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); + }, + + sub: function(a, b) { + return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]; + }, + + unit: function(a) { + var l = this.len(a); + return [a[0]/l, a[1]/l, a[2]/l]; + }, + + normal: function(a, b, c) { + var d1 = this.sub(a, b); + var d2 = this.sub(b, c); + // normalized cross product of d1 and d2 + return this.unit([ + d1[1]*d2[2] - d1[2]*d2[1], + d1[2]*d2[0] - d1[0]*d2[2], + d1[0]*d2[1] - d1[1]*d2[0] + ]); + } +}; diff --git a/src/vector.js b/src/vector.js deleted file mode 100644 index 803f6ad..0000000 --- a/src/vector.js +++ /dev/null @@ -1,34 +0,0 @@ - -var vector = { - len2: function(a) { - return Math.sqrt(a[0]*a[0] + a[1]*a[1]); - }, - - len3: function(a) { - return Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); - }, - - sub2: function(a, b) { - return [a[0]-b[0], a[1]-b[1]]; - }, - - sub3: function(a, b) { - return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]; - }, - - unit3: function(a) { - var l = this.len3(a); - return [a[0]/l, a[1]/l, a[2]/l]; - }, - - normal3: function(a, b, c) { - var d1 = this.sub3(a, b); - var d2 = this.sub3(b, c); - // normalized cross product of d1 and d2 - return this.unit3([ - d1[1]*d2[2] - d1[2]*d2[1], - d1[2]*d2[0] - d1[0]*d2[2], - d1[0]*d2[1] - d1[1]*d2[0] - ]); - } -};