transformation

Image changes size as it's rotated. How do I stop this?

不打扰是莪最后的温柔 提交于 2019-11-29 23:47:23
问题 I'm making a game for Android and I need to rotate an image. When I rotate it obviously it's dimensions change. For example when it's rotated 45 degrees (it's square but I'd like this to work for any rectangle so it's a more general solution) it's width and height become the length of the diagonal, which is longer than the original. After some algebra you can work out that the scale factor is sqrt(2). But the only way I know of to rotate a bitmap is with a matrix. Ex: matrix.postRotate

Find and replace entire HTML nodes with Nokogiri

有些话、适合烂在心里 提交于 2019-11-29 17:34:14
问题 i have an HTML, that should be transformed, having some tags replaced with another tags. I don't know about these tags, because they will come from db. So, set_attribute or name methods of Nokogiri are not suitable for me. I need to do it, in a way, like in this pseudo-code: def preprocess_content doc = Nokogiri::HTML( self.content ) doc.css("div.to-replace").each do |div| # "get_html_text" will obtain HTML from db. It can be anything, even another tags, tag groups etc. div.replace self.get

PHP strtr vs str_replace benchmarking

谁都会走 提交于 2019-11-29 16:38:20
I'm curious what the most performant method of doing string transformations is. Given a n input string and a set of translations, what method is the most efficient in general? I currently use strtr() , but have tested various looping methods, str_replace() with an array, etc. The strtr() method benchmarks the fastest on my system, depending on the translations, but I'm curious if there are faster methods I haven't thought of yet. If it's pertinent, my particular use case involves transforming 2-byte strings into ANSI color sequences for a terminal. Example: // In practice, the number of

Transform from Wide to Long without sorting columns

一世执手 提交于 2019-11-29 16:04:17
I want to convert a dataframe from wide format to long format. Here it is a toy example: mydata <- data.frame(ID=1:5, ZA_1=1:5, ZA_2=5:1,BB_1=rep(3,5),BB_2=rep(6,5),CC_7=6:2) ID ZA_1 ZA_2 BB_1 BB_2 CC_7 1 1 5 3 6 6 2 2 4 3 6 5 3 3 3 3 6 4 4 4 2 3 6 3 5 5 1 3 6 2 There are some variables that will remain as is (here only ID) and some that will be transformed to long format (here all other variables, all ending with _1, _2 or _7) In order to transform it to long format I'm using data.table melt and dcast, a generic way able to detect the variables automatically. Other solutions are welcome too.

XSLT, Renaming Elements using mapping table based on Attribute's value

懵懂的女人 提交于 2019-11-29 15:37:34
How to rename the elements according to a mapping table based on attribute's of the element? Any suggestions would be much appreciated. Maybe a XSLT 2.0 template and modifying the mapping table for better solution? Many thanks in advance Thomas Original XML: <transaction> <records type="1" > <record type="1" > <field number="1" > <item>223</item> </field> <field number="2" > <item>456</item> </field> </record> </records> <records type="14" > <record type="14" > <field number="1" > <item>777</item> </field> <field number="2" > <item>678</item> </field> </record> <record type="14" > <field

XSLT, Renaming Elements using mapping table based on Attribute's value

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 15:37:30
How to rename the elements according to a mapping table based on attribute's of the element? Any suggestions would be much appreciated. Maybe a XSLT 2.0 template and modifying the mapping table for better solution? Many thanks in advance Thomas Original XML: <transaction> <records type="1" > <record type="1" > <field number="1" > <item>223</item> </field> <field number="2" > <item>456</item> </field> </record> </records> <records type="14" > <record type="14" > <field number="1" > <item>777</item> </field> <field number="2" > <item>678</item> </field> </record> <record type="14" > <field

XmlResolver: XSLT compiler error

别来无恙 提交于 2019-11-29 15:28:38
I have troubles with XmlResolver class. I have a few XSLT files saved in MS SQL database in xml datatype column. I'm trying to write a XmlResolver class implementation, that would load the text from database instead of from the files. But I'm getting XSLT compiler error. Here is very simple example (text of both input and xslt is hardcoded here): static void Main(string[] args) { string xslt = @"<?xml version=""1.0"" encoding=""utf-8""?> <xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" xmlns:msxsl=""urn:schemas-microsoft-com:xslt"" exclude-result-prefixes="

Shear Matrix as a combination of basic transformation?

℡╲_俬逩灬. 提交于 2019-11-29 14:49:33
问题 I know the transformation matrices for rotation, scaling, translation etc. I also know the matrix for shear transformation. Now, I need to have the shear matrix-- [1 Sx 0] [0 1 0] [0 0 1] in the form of a combination of other aforesaid transformations . Tried searching, tried brainstorming, but unable to strike! Thanks! 回答1: The x-shear operation for a shearing angle theta reduces to rotations and scaling as follows: (a) Rotate by theta/2 counter-clockwise. (b) Scale with x-scaling factor =

SQLAlchemy Column to Row Transformation and vice versa — is it possible?

↘锁芯ラ 提交于 2019-11-29 07:49:40
I'm looking for a SQLAlchemy only solution for converting a dict received from a form submission into a series of rows in the database, one for each field submitted. This is to handle preferences and settings that vary widely across applications. But, it's very likely applicable to creating pivot table like functionality. I've seen this type of thing in ETL tools but I was looking for a way to do it directly in the ORM. I couldn't find any documentation on it but maybe I missed something. Example: Submitted from form: {"UniqueId":1, "a":23, "b":"Hello", "c":"World"} I would like it to be

Imagick: compose with mask

纵饮孤独 提交于 2019-11-29 05:44:01
I try to recreate a script that uses the ImageMagick command "convert" to compose an image. But I want to do the same in PHP using Imagick (version 6.6.2-10). The command is as follows: convert A1.mpc A3.mpc A4.mpc -channel rgba -alpha on -virtual-pixel background -background none -define compose:args=312x26.6776 -compose displace -composite out.mpc I found out that the parameters stand for the following: convert {background} {overlay} [{mask}] [-compose {method}] -composite {result} The PHP Imagick gives me a compose method, but without a mask parameter: http://www.php.net/manual/en/imagick