units-of-measurement

Font-size 1px to use with rem units

这一生的挚爱 提交于 2019-12-22 06:59:40
问题 I'm going after a layout that would scale nicely along with zoom (user pressing ctr/cmd + [plus]). For that I need dimensions to scale along with font-size. Using em units is too tricky, so I'm thinking of going with rem (and duplicating every dimensional property for old ie). My initial idea was to set font-size on html element to 10px and then use 1/10rem as a pixel replacement. But since font-size on body is set arbitrary in px, the one on html would be used exclusively for rem measurement

Which unit of measurement does the Paint.setTextSize(float) use?

萝らか妹 提交于 2019-12-22 01:51:59
问题 I want to draw text with an specific height(in pixels) on a view using Canvas . Can you simply use Paint.setTextSize(float) with the number of pixels or is this using dp or sp ? 回答1: It uses pixels, but you can convert it to dp using this code: double getDPFromPixels(double pixels) { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); switch(metrics.densityDpi){ case DisplayMetrics.DENSITY_LOW: pixels = pixels * 0.75; break; case

F# Unit of Measure, Casting without losing the measure type

眉间皱痕 提交于 2019-12-21 07:55:11
问题 Is there built in version of the type casting functions that preserves units and if not how would I make them? So for example with this code how would I cast intWithSecondsMeasure to a float without losing the measure or multiplying by 1.0<s> ? [<Measure>] type s let intWithSecondsMeasure = 1<s> let justAFloat = float intWithSecondsMeasure 回答1: The answer provided by @kvb certainly works, but I'd prefer not to use the unbox operator for this conversion. There's a better, built in way that I

Should I use % or 'px' in HTML

喜夏-厌秋 提交于 2019-12-21 05:29:08
问题 Regardless of whether it is HTML, XHTML or HTML5 you find those annoying percentages littered throughout the place. Yet... I see an awful lot of websites dare not go near them. Yet I was always encouraged through uni to use them. So which should I be using? Which would lead to better site design and why? I'm aware to avoid the use of height although HTML5 really doesn't like me not specifying height if I want to use percentages. Thanks for taking the time to read. 回答1: It really depends on

Converting from m/s to km/h using F# Units of Measure

孤街醉人 提交于 2019-12-21 04:37:10
问题 I'm in the process of learning F# - and is currently looking into Units of Measure. I have a simple calculation returning meters per second, and I want to introduce a function converting it to kilometres per hour. My code looks like this: [<Measure>] type kg [<Measure>] type s [<Measure>] type m [<Measure>] type km [<Measure>] type h let msToKmph(speed : float<m/s>) = (float speed) * 3.6<km/h> let gravityOnEarth = 9.81<m/s^2> let heightOfJump = 3.5<m> let speedOfImpact = sqrt (2.0 *

Using relative instead of fixed size in CSS

不问归期 提交于 2019-12-20 05:46:40
问题 I want to use relative size instead of fixed size. I want to use em. My CSS is: body{ font:10px; } #wrap { font:1.2em; } #wrap ul li { padding-left:2em; } What is value of the li 's padding in px? I would have guessed it's 2.0*10 = 20px, but it looks like it's taking 1em = 12px, I mean it taking it parent size. I would like for it to take 1x the parent fontsize in px (that means font-size of body not wrap ). I appreciate your suggestions. 回答1: ems are always relative to their parent element,

Why is the implicit conversion not considered in this case with generic parameters?

 ̄綄美尐妖づ 提交于 2019-12-20 02:48:11
问题 Consider the following code, derived from the metascala project: object Units { case class Quantity[M <: MInt, T: Numeric](value: T) { type This = Quantity[M, T] def *[M2 <: MInt](m: Quantity[M2, T]) = Quantity[M + M2, T](numeric[T].times(value, m.value)) def /[M2 <: MInt](m: Quantity[M2, T]) = Quantity[M - M2, T](numeric[T].div(value, m.value)) def apply(v: T) = Quantity[M, T](numeric[T].times(v, value)) } implicit def measure[T: Numeric](v: T) = Quantity[_0, T](v) implicit def

F# compiler error FS0030, problems with the Value Restriction

雨燕双飞 提交于 2019-12-19 09:37:58
问题 I've read the blurb at StrangeLights, I've read the passage from Expert F# (page 119), but I can't see how they apply to my code: For my tests, I want to check equality between floats, with a bit of tolerance. I'm converting everything to units of measure, but I want to be able to be 'generic': let toleq (e:float<_>) a b = (abs ( a - b ) ) < e I can then use this to check equality on different 'types' of float, or curry it to make a custom one: toleqm = toleq 1.0e-10<m> But I get the

Fractional power of units of measures in F#

心已入冬 提交于 2019-12-19 05:50:08
问题 Is it true to say that : there are no fractional power units in F# 回答1: In addition to what has already been said, the best resource for information about (not just) F# units of measure is Andrew Kennedy's PhD thesis, who actually designed F# units. He mentions fractional units: The most important decision is whether or not to allow fractional exponents of dimensions. The argument against them is philosophical: a quantity with a dimension such as M 1/2 makes no sense physically, and if such a

Does java -Xmx1G mean 10^9 or 2^30 bytes?

心已入冬 提交于 2019-12-18 18:57:07
问题 And in general, are the units used for the -Xmx , -Xms and -Xmn options ("k", "M" and "G", or the less standard possibilities "K", "m" or "g") Binary prefix multiples (i.e. powers of 1024), or are they powers of 1000? The manuals say they represent kilobytes (kB), megabytes (MB) and gigabytes (GB), suggesting they are powers of 1000 as defined in the original SI system. My informal tests (that I'm not very confident about) suggest they are really kibibytes (kiB), mebibytes (MiB) and gibibytes