<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jozef Chúťka&#039;s blog &#187; Point</title>
	<atom:link href="http://blog.yoz.sk/tag/point/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yoz.sk</link>
	<description>My life, my work</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:40:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quick tip: always use global position for hitTestPoint()</title>
		<link>http://blog.yoz.sk/2010/06/quick-tip-always-use-global-position-for-hittestpoint/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quick-tip-always-use-global-position-for-hittestpoint</link>
		<comments>http://blog.yoz.sk/2010/06/quick-tip-always-use-global-position-for-hittestpoint/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 12:28:56 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[hitTestPoint]]></category>
		<category><![CDATA[localToGlobal]]></category>
		<category><![CDATA[Point]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1772</guid>
		<description><![CDATA[Just for the record and myself (I should read all the documentation, also the long sentences &#8230; Make sure you always check hitTestPoint() against global coordinates of some point. Even hitShape object is not directly on a stage (but on myInnerObject), you have to use global points for testing hits.]]></description>
			<content:encoded><![CDATA[<p>Just for the record and myself (I should read all the documentation, also the long sentences <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  &#8230; Make sure you always check hitTestPoint() against global coordinates of some point.</p>
<pre class="brush: as3; title: ; notranslate">// we are somewhere deep in myObject.myObject2.myInnerObject
var point:Point;
var someMovingObject:DisplayObject;
var hitShape:DisplayObject;

point = localToGlobal(new Point(someMovingObject.x, someMovingObject.y));
point = someMovingObject.localToGlobal(new Point());
// both give us same results,
// 2nd method is faster in loops while it can use predefined zero point

hitShape.hitTestPoint(point.x, point.y, true);</pre>
<p>Even hitShape object is not directly on a stage (but on myInnerObject), you have to use global points for testing hits.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/06/quick-tip-always-use-global-position-for-hittestpoint/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Abstract Drawing</title>
		<link>http://blog.yoz.sk/2010/05/abstract-drawing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=abstract-drawing</link>
		<comments>http://blog.yoz.sk/2010/05/abstract-drawing/#comments</comments>
		<pubDate>Fri, 07 May 2010 13:03:30 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Point]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1593</guid>
		<description><![CDATA[While some free time today, I have been playing on guiding script, than suddenly I got an idea, I can create some eye-catching thing with it and voilà, here is little thingy, can be used for screensaver etc&#8230; Have a nice Friday Abstract Drawing (Guide based) &#8211; wonderfl build flash online Full ActionScript 3 code [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/abstractdrawing.jpg" alt="" title="abstractdrawing" width="200" height="100" class="alignleft size-full wp-image-1594" /></p>
<p>While some free time today, I have been playing on guiding script, than suddenly I got an idea, I can create some eye-catching thing with it and voilà, here is little thingy, can be used for screensaver etc&#8230; Have a nice Friday <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><span id="more-1593"></span></p>
<div style="text-align:center;width:465px;"><iframe title="Abstract Drawing (Guide based) - wonderfl build flash online" scrolling="no" src="http://wonderfl.net/blogparts/s2lb" width="465" height="490" style="border:1px black solid;"></iframe><a href="http://wonderfl.net/c/s2lb" title="Abstract Drawing (Guide based) - wonderfl build flash online">Abstract Drawing (Guide based) &#8211; wonderfl build flash online</a></div>
<p><a href="http://blog.yoz.sk/examples/abstractDrawing/GiudeApp.as">Full ActionScript 3 code</a> can be also downloaded from wonderfl.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/05/abstract-drawing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GeometryMath 3 points in line test</title>
		<link>http://blog.yoz.sk/2010/01/geometrymath-3-points-in-line-test/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=geometrymath-3-points-in-line-test</link>
		<comments>http://blog.yoz.sk/2010/01/geometrymath-3-points-in-line-test/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 11:24:34 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[GeometryMath]]></category>
		<category><![CDATA[Point]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=810</guid>
		<description><![CDATA[GeometryMath.isLine() static function tests 3 Points and returns true if these points are in line. Optional 4th parameter defines if you require point2 to be in the middle between 1 and 3. Function is not based on vector algorithm, but on triangle equation. This simple function was developed in order to optimize number of points [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/inLine.png"><img src="http://blog.yoz.sk/wp-content/uploads/inLine-200x100.png" alt="inLine" title="inLine" width="200" height="100" class="alignleft size-medium wp-image-811" /></a>
</p>
<p>GeometryMath.isLine() static function tests 3 Points and returns true if these points are in line. Optional 4th parameter defines if you require point2 to be in the middle between 1 and 3. Function is not based on vector algorithm, but on triangle equation. This simple function was developed in order to optimize number of points necessary to draw some paths. To draw a line, you do not need all the points, you can omit all the middle points that are on the same line and the result looks the same &#8211; optimizes performance or storage.</p>
<p><span id="more-810"></span></p>
<p>isLine() function is a part of <a href="http://classes.yoz.sk/sk/yoz/math/GeometryMath.as">sk.yoz.math. GeometryMath</a> class</p>
<pre class="brush: as3; title: ; notranslate">public static function isLine(point1:Point, point2:Point,
	point3:Point, orderSensitive:Boolean = true):Boolean
{
	var x1:Number = point1.x - point2.x;
	var x2:Number = point2.x - point3.x;
	var y1:Number = point1.y - point2.y;
	var y2:Number = point2.y - point3.y;

	if(orderSensitive &amp;&amp; ((x1 &gt; 0 &amp;&amp; x2 &lt; 0) || (x1 &lt; 0 &amp;&amp; x2 &gt; 0)
		|| (y1 &lt; 0 &amp;&amp; y2 &gt; 0) || (y1 &lt; 0 &amp;&amp; y2 &gt; 0)))
		return false;
	else if(!y2)
		return !y1;
	else if(!x2)
		return !x1;
	else
		return x1 / x2 == y1 / y2;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/01/geometrymath-3-points-in-line-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to resize an image with ActionScript (update)</title>
		<link>http://blog.yoz.sk/2010/01/how-to-resize-an-image-with-actionscript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-resize-an-image-with-actionscript</link>
		<comments>http://blog.yoz.sk/2010/01/how-to-resize-an-image-with-actionscript/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 12:31:43 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ImageResizer]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[pixel bender]]></category>
		<category><![CDATA[Point]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[ResizeMath]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=792</guid>
		<description><![CDATA[If you need to resize an image on client side, I mean real bitmapData resize (not just showing scaled), feel free to use ImageResizer class. This class takes bitmapData of source image, new width and height and resize method (defined by ResizeMath class), and returns new bitmapData of resized image. Update: It seems that bitmapData.draw() [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/imageResizeLanczos.jpg"><img src="http://blog.yoz.sk/wp-content/uploads/imageResizeLanczos-200x153.jpg" alt="imageResizeLanczos" title="imageResizeLanczos" width="200" height="153" class="alignleft size-medium wp-image-856" /></a></p>
<p>If you need to resize an image on client side, I mean real bitmapData resize (not just showing scaled), feel free to use ImageResizer class. This class takes bitmapData of <strong>source</strong> image, new <strong>width</strong> and <strong>height</strong> and <strong>resize method</strong> (defined by ResizeMath class), and returns new bitmapData of resized image.</p>
<p>Update: It seems that bitmapData.draw() method uses bilinear algorithm when scaling via Matrix. Bilinear algorithm gives you fine results when downscaling no more than 2 times (400px -&gt; 200px). So, I added <strong>bilinearIterative() method</strong> into ImageResizer class that creates resized bitmapData by multiple steps achieving <strong>much smoother results</strong>!</p>
<p><span id="more-792"></span></p>
<p style="clear:both;">Source of <a href="http://classes.yoz.sk/sk/yoz/image/ImageResizer.as">sk.yoz.image.ImageResizer</a> class:</p>
<pre class="brush: as3; title: ; notranslate">package sk.yoz.image
{
    import flash.display.BitmapData;
    import flash.geom.Matrix;
    import flash.geom.Point;

    import sk.yoz.math.ResizeMath;

    public class ImageResizer extends Object
    {
        public function ImageResizer()
        {
        }

        public static function bilinear(source:BitmapData, width:uint,
            height:uint, method:String, allowEnlarging:Boolean=true):BitmapData
        {
            var scale:Point = ResizeMath.scale(
                new Point(source.width, source.height),
                new Point(width, height), method, allowEnlarging);
            var result:BitmapData = new BitmapData(width, height, true, 0x0);
            var matrix:Matrix = new Matrix();
            matrix.scale(scale.x, scale.y);
            matrix.tx = (width - source.width * scale.x) / 2;
            matrix.ty = (height - source.height * scale.y) / 2;
            result.draw(source, matrix, null, null, null, true);
            return result;
        }

        public static function bilinearIterative(source:BitmapData, width:uint,
            height:uint, method:String, allowEnlarging:Boolean = true,
            iterationMultiplier:Number = 2):BitmapData
        {
            var w:uint = source.width;
            var h:uint = source.height;
            var result:BitmapData;
            while(!result || w != width || h != height)
            {
                w = source.width &gt; width
                    ? Math.max(w / iterationMultiplier, width)
                    : Math.min(w * iterationMultiplier, width);
                h = source.height &gt; height
                    ? Math.max(h / iterationMultiplier, height)
                    : Math.min(h * iterationMultiplier, height);
                result = bilinear(result || source, w, h, method,
                    allowEnlarging);
            }
            return result;
        }
    }
}</pre>
<p>Usage is pretty simple. You also gonna need <a href="http://classes.yoz.sk/sk/yoz/math/ResizeMath.as">sk.yoz.math.ResizeMath</a> class.</p>
<pre class="brush: as3; title: ; notranslate">var result:BitmapData = ImageResizer.bilinearIterative(sourceBitmapData, 100, 100,
    ResizeMath.METHOD_PAN_AND_SCAN);</pre>
<h2>Alternatives &amp; Benchmarking</h2>
<p>There are also another possible methods to resize/resample images. Read more about <a href="http://www.brooksandrus.com/blog/2009/03/11/bilinear-resampling-with-flash-player-and-pixel-bender/">bilinear resampling</a> and <a href="http://blog.onthewings.net/2009/08/25/bicubic-resampling-by-pixel-bender/">bicubic resampling</a> methods using pixel bender. I benchamrked all methods and here are the results:</p>
<pre class="brush: plain; title: ; notranslate">source    | result  | ImageResizer | ImageResizer        | Bilinear PB | Bicubic PB
          |         | bilinear()   | bilinearIterative() |             |
4x4       | 200x200 |         0 ms |                3 ms |       16 ms |      31 ms
946x946   | 200x200 |         0 ms |                7 ms |       16 ms |      47 ms
1200x1200 | 200x200 |         0 ms |                9 ms |       32 ms |      47 ms</pre>
<p>Comparing ImageResizer.bilinear() method with bilinear and bicubic pixel bender resizing. Even though, all methods are pretty fast, the results are far from beeing as good as <a href="http://en.wikipedia.org/wiki/Lanczos_algorithm">Lanczos algorithm</a> results (e.g. used in <a href="http://www.irfanview.com/">IrfanView</a>):</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/resizingMethodBenchmark1.jpg"><img src="http://blog.yoz.sk/wp-content/uploads/resizingMethodBenchmark1-200x189.jpg" alt="resizingMethodBenchmark" title="resizingMethodBenchmark" width="200" height="189" class="alignnone size-medium wp-image-854" /></a></p>
<p>Comparing ImageResizer.bilinear(), ImageResizer.bilinearIterative() and <a href="http://en.wikipedia.org/wiki/Lanczos_algorithm">Lanczos algorithm</a>:</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/imageResizeLanczos.jpg"><img src="http://blog.yoz.sk/wp-content/uploads/imageResizeLanczos-200x153.jpg" alt="imageResizeLanczos" title="imageResizeLanczos" width="200" height="153" class="alignnone size-medium wp-image-856" /></a></p>
<p>If you are looking for <a href="http://blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/">transformation between BitmapData, Bitmap, ByteArray, read this article</a>. </p>
<p><strong>Update November 10, 2010</strong>: <a href="http://blog.yoz.sk/2010/11/lanczos-resampling-with-actionscript/">Lanczos Resampling With ActionScript</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/01/how-to-resize-an-image-with-actionscript/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

