on master help sign in
add `insideForm :: Point -> Form -> Bool` function that checks to see if a point is inside of a form.
bb1d53devancz
core-js/Graphics/Collage.js+105−9
@@ -70,27 +70,22 @@ var customLineHelp = function(ctx, pattern, points) {
70};
70};
71
71
72function drawLine(ctx,form) {
72function drawLine(ctx,form) {
73− var points = Foreign.JavaScript.castListToJSArray(form[3][1]);
73+ var points = form[3][1];
74 switch(form[1][0]) {
74 switch(form[1][0]) {
75 case "Solid" : return solid(ctx,form[2],points);
75 case "Solid" : return solid(ctx,form[2],points);
76 case "Dotted": return customLine([3,3],ctx,form[2],points);
76 case "Dotted": return customLine([3,3],ctx,form[2],points);
77 case "Dashed": return customLine([8,4],ctx,form[2],points);
77 case "Dashed": return customLine([8,4],ctx,form[2],points);
78− case "Custom":
79− var pattern = Foreign.JavaScript.castListToJSArray(form[1][1]);
80− customLine(pattern,ctx,form[2],points);
78+ case "Custom": return customLine(form[1][1],ctx,form[2],points);
81 }
79 }
82};
80};
83
81
84function drawShape(redo,ctx,shapeStyle,color,points) {
82function drawShape(redo,ctx,shapeStyle,color,points) {
85− points = Foreign.JavaScript.castListToJSArray(points);
86− if (points.length > 0) points.push(points[0]);
87 switch(shapeStyle[0]) {
83 switch(shapeStyle[0]) {
88 case "Filled": return filled(ctx,color,points);
84 case "Filled": return filled(ctx,color,points);
89 case "Outlined": return solid(ctx,color,points);
85 case "Outlined": return solid(ctx,color,points);
90 case "Textured": return textured(redo,ctx,shapeStyle[1],points);
86 case "Textured": return textured(redo,ctx,shapeStyle[1],points);
91 case "CustomOutline":
87 case "CustomOutline":
92− var pattern = Foreign.JavaScript.castListToJSArray(shapeStyle[1]);
88+ return customLine(shapeStyle[1],ctx,color,points);
93− customLine(pattern,ctx,color,points);
94 }
89 }
95};
90};
96
91
@@ -209,6 +204,107 @@ function updateCollage(node,currs,nexts) {
209 }
204 }
210}
205}
211
206
207+function style(clr,n,list) {
208+ return ["Tuple2",
209+ '<span style="font-size:100%;color:' + clr + ';">' + n + '</span>',
210+ list];
211+}
212+
213+function insideForm(point) { return function(form) {
214+ if (!inBoundsOf(point[1],point[2],form)) return false;
215+ var hw, hh;
216+ switch (form[4][0]) {
217+ case "FShape": return insideShape(point,form[1],form[2],form[3],form[4][3][1]);
218+ case "FLine": return false;
219+ case "FImage":
220+ hw = form[4][1] / 2;
221+ hh = form[4][2] / 2;
222+ break;
223+ case "FElement":
224+ hw = form[4][1][3] / 2;
225+ hh = form[4][1][4] / 2;
226+ break;
227+ }
228+ return insideShape(point,form[1],form[2],form[3],
229+ [ [null, hw, hh],
230+ [null,-hw, hh],
231+ [null,-hw,-hh],
232+ [null, hw,-hh],
233+ [null, hw, hh] ]);
234+ };
235+}
236+
237+function inBoundsOf(px,py,form) {
238+ if (form.length < 6) {
239+ var fx = form[3][1], fy = form[3][2];
240+ var radiusSquared = 0;
241+ var scale = form[2];
242+ switch (form[4][0]) {
243+ case "FShape":
244+ var points = form[4][3][1];
245+ for (var i = points.length; --i; ) {
246+ var p = points[i];
247+ radiusSquared = Math.max(radiusSquared, p[1]*p[1] + p[2]*p[2]);
248+ }
249+ radiusSquared *= scale * scale;
250+ break;
251+ case "FLine":
252+ break;
253+ case "FImage":
254+ var x = scale * form[4][1] / 2;
255+ var y = scale * form[4][2] / 2;
256+ radiusSquared = x*x + y*y;
257+ break;
258+ case "FElement":
259+ var x = scale * form[4][1][3] / 2;
260+ var y = scale * form[4][1][4] / 2;
261+ radiusSquared = x*x + y*y;
262+ break;
263+ }
264+ form.push(function(px,py) {
265+ var dx = px - fx;
266+ var dy = py - fy;
267+ return dx*dx + dy*dy < radiusSquared + 1;
268+ });
269+ }
270+ return form[5](px,py);
271+}
272+
273+function insideShape(point,theta,scale,pos,points) {
274+ var counter = 0;
275+ var list = ["Nil"];
276+ var p1,p2;
277+
278+ var x = (point[1] - pos[1]) / scale;
279+ var y = (point[2] - pos[2]) / scale;
280+ if (theta !== 0) {
281+ var angle = 2 * Math.PI * theta;
282+ var t = x === 0 ? (y > 0 ? Math.PI/2 : -Math.PI/2) - angle
283+ : (Math.atan(y/x) + (x > 0 ? 0 : Math.PI)) - angle;
284+ var r = Math.sqrt(x*x + y*y);
285+ x = r * Math.cos(t);
286+ y = r * Math.sin(t);
287+ }
288+
289+ if (points.length === 0) { return false; }
290+ p1 = points[0];
291+ for (var i = points.length - 1; i--; ) {
292+ p2 = points[i];
293+ var p1x = p1[1], p1y = p1[2], p2x = p2[1], p2y = p2[2];
294+
295+ if (p1y < p2y) {var ymin=p1y, ymax=p2y;} else {var ymin=p2y, ymax=p1y;}
296+ if (p1x < p2x) {var xmin=p1x, xmax=p2x;} else {var xmin=p2x, xmax=p1x;}
297+
298+ if (ymin < y && y <= ymax && x <= xmax) {
299+ if (x <= xmin || x <= ((y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x)) {
300+ ++counter;
301+ }
302+ }
303+ p1 = p2;
304+ }
305+ return (counter % 2) === 1;
306+}
307+
212−return {collage:collage, updateCollage:updateCollage};
308+return {collage:collage, updateCollage:updateCollage, insideForm:insideForm};
213
309
214}();
310}();
core-js/Graphics/Element.js+13−7
@@ -80,19 +80,21 @@ ElmCode.Graphics.Element = function() {
80 var Dotted_69 = ["Dotted"];
80 var Dotted_69 = ["Dotted"];
81 var Dashed_70 = ["Dashed"];
81 var Dashed_70 = ["Dashed"];
82 function Custom_71(a1) {
82 function Custom_71(a1) {
83− return["Custom", a1]
83+ return["Custom", Foreign.JavaScript.castListToJSArray(a1)]
84 }
84 }
85 var Filled_72 = ["Filled"];
85 var Filled_72 = ["Filled"];
86 var Outlined_73 = ["Outlined"];
86 var Outlined_73 = ["Outlined"];
87 function CustomOutline_74(a1) {
87 function CustomOutline_74(a1) {
88− return["CustomOutline", a1]
88+ return["CustomOutline", Foreign.JavaScript.castListToJSArray(a1)]
89 }
89 }
90 function Line_75(a1) {
90 function Line_75(a1) {
91− return["Line", a1]
91+ return["Line", Foreign.JavaScript.castListToJSArray(a1)]
92 }
92 }
93 function Shape_78(a1) {
93 function Shape_78(a1) {
94 return function(a2) {
94 return function(a2) {
95+ var points = Foreign.JavaScript.castListToJSArray(a1);
96+ if (points.length > 0) { points.push(points[0]); }
95− return["Shape", a1, a2]
97+ return["Shape", points, a2];
96 }
98 }
97 }
99 }
98 function Form_84(a1) {
100 function Form_84(a1) {
@@ -365,7 +367,10 @@ ElmCode.Graphics.Element = function() {
365 function rect_80(w_174) {
367 function rect_80(w_174) {
366 return function(h_175) {
368 return function(h_175) {
367 return function(pos_176) {
369 return function(pos_176) {
368− return Shape_78(["Cons", ["Tuple2", 0 - w_174 / 2, 0 - h_175 / 2], ["Cons", ["Tuple2", 0 - w_174 / 2, h_175 / 2], ["Cons", ["Tuple2", w_174 / 2, h_175 / 2], ["Cons", ["Tuple2", w_174 / 2, 0 - h_175 / 2], ["Nil"]]]]])(pos_176)
370+ return Shape_78(["Cons", ["Tuple2", 0 - w_174 / 2, 0 - h_175 / 2],
371+ ["Cons", ["Tuple2", 0 - w_174 / 2, h_175 / 2],
372+ ["Cons", ["Tuple2", w_174 / 2, h_175 / 2],
373+ ["Cons", ["Tuple2", w_174 / 2, 0 - h_175 / 2], ["Nil"]]]]])(pos_176)
369 }
374 }
370 }
375 }
371 }
376 }
@@ -457,7 +462,7 @@ ElmCode.Graphics.Element = function() {
457 function customOutline_95(pattern) {
462 function customOutline_95(pattern) {
458 return function(clr) {
463 return function(clr) {
459 return function(shape) {
464 return function(shape) {
460− return Form_84(0)(1)(shape[2])(FShape_86(["CustomOutline",pattern])(clr)(shape));
465+ return Form_84(0)(1)(shape[2])(FShape_86(CustomOutline_74(pattern))(clr)(shape));
461 }
466 }
462 }
467 }
463 }
468 }
@@ -506,5 +511,6 @@ ElmCode.Graphics.Element = function() {
506 }
511 }
507 return{left:left_6, right:right_7, down:down_8, up:up_9, inward:inward_10, outward:outward_11, topLeft:topLeft_22, topRight:topRight_23, bottomLeft:bottomLeft_24, bottomRight:bottomRight_25, midLeft:midLeft_26, midRight:midRight_27, midTop:midTop_28, midBottom:midBottom_29, middle:middle_30, middleAt:middleAt, topLeftAt:topLeftAt_31, topRightAt:topRightAt_32, bottomLeftAt:bottomLeftAt_33, bottomRightAt:bottomRightAt_34, absolute:absolute_35, relative:relative_36, width:width_47, height:height_48, size:size_49, opacity:opacity_50,
512 return{left:left_6, right:right_7, down:down_8, up:up_9, inward:inward_10, outward:outward_11, topLeft:topLeft_22, topRight:topRight_23, bottomLeft:bottomLeft_24, bottomRight:bottomRight_25, midLeft:midLeft_26, midRight:midRight_27, midTop:midTop_28, midBottom:midBottom_29, middle:middle_30, middleAt:middleAt, topLeftAt:topLeftAt_31, topRightAt:topRightAt_32, bottomLeftAt:bottomLeftAt_33, bottomRightAt:bottomRightAt_34, absolute:absolute_35, relative:relative_36, width:width_47, height:height_48, size:size_49, opacity:opacity_50,
508 color:color_51, link:link, widthOf:widthOf_52, heightOf:heightOf_53, sizeOf:sizeOf_54, text:text_56, asText:asText, plainText:plainText, centeredText:centeredText, justifiedText:justifiedText, rightedText:rightedText, image:image_57, images:images, video:video_58, fittedImage:fittedImage_59, flow:flow_60, above:above_61, below:below_62, beside:beside_63, layers:layers_64, collage:collage_65, spacer:spacer_66, container:container_67, line:line_76, segment:segment_77, polygon:polygon_79, rect:rect_80, oval:oval_81, circle:circle_82, ngon:ngon_83, solid:solid_89, dotted:dotted_90, dashed:dashed_91, customLine:customLine_92, filled:filled_93,
513 color:color_51, link:link, widthOf:widthOf_52, heightOf:heightOf_53, sizeOf:sizeOf_54, text:text_56, asText:asText, plainText:plainText, centeredText:centeredText, justifiedText:justifiedText, rightedText:rightedText, image:image_57, images:images, video:video_58, fittedImage:fittedImage_59, flow:flow_60, above:above_61, below:below_62, beside:beside_63, layers:layers_64, collage:collage_65, spacer:spacer_66, container:container_67, line:line_76, segment:segment_77, polygon:polygon_79, rect:rect_80, oval:oval_81, circle:circle_82, ngon:ngon_83, solid:solid_89, dotted:dotted_90, dashed:dashed_91, customLine:customLine_92, filled:filled_93,
509− outlined:outlined_94, customOutline:customOutline_95, textured:textured, sprite:sprite_96, toForm:toForm_97, rotate:rotate_98, scale:scale_99, move:move_100}
514+ outlined:outlined_94, customOutline:customOutline_95, textured:textured, sprite:sprite_96, toForm:toForm_97, rotate:rotate_98, scale:scale_99, move:move_100,
515+ insideForm: Collage.insideForm}
510}();
516}();