CTLineGetBoundsWithOptions() what does the returned frame.origin.y value mean? - core-text

When I do
CGRect lineBounds = CTLineGetBoundsWithOptions(lineRef, 0);
I get
(CGRect) lineBounds = origin=(x=0, y=-3.8560002) size=(width=181.31201, height=19.088001)
What information is the lineBounds.origin.y referring to? And why is it negative?
In contradiction to doing this where I get the excact same height and width - I don't get that -3.85 value.
double width = CTLineGetTypographicBounds(lineRef, &ascent, &descent, &leading);
double height = ascent + descent + leading;
So what does it tell me?

Sadly there is no descent documentation on CTLineGetBoundsWithOptions function, but,
as the header file states, this method returns
The bounds of the line as specified by the type and options, such that the coordinate origin is coincident with the line origin and the rect origin is at the bottom left. If the line is invalid this function will return CGRectNull.
You should obtain line origins using CTFrameGetLineOrigins and append corresponding origin to the obtained bounds origin.
Also, consider looking into CTLineBoundsOptions enumeration to filter unwanted elements

Related

Error when using CVX package with large sparse matrix

The error description is as follows:
Error using full request 68813x68813 (35.3GB) array to exceed the preset maximum array size Creating an array larger than this limit can take a long time and result in no response from MATLAB for more information, see Array Size Limits or Default Items panel.
Error schurmat_sblk (line 35)
if issparse(schur); schur = full(schur); end;
The function file schurmat_sblk is a file in cvx\sdpt3\Solver,
How can I do to avoid this error?
My cvx codes are as follows:
The value you may need are: n=8; d=2^n;m=(d^2)*0.05;the size of Pauli is m*d^2, it's a sparse matrix. The size of y is m*1;
function [rhoE] = test_compressed_cc(n,~,m,Pauli,y)
d = 2^n;
cvx_begin sdp quiet
% how to define the variable ?
variable rhoE(d,d) hermitian;
rhoE == hermitian_semidefinite(d);
% ||x||_tr=tr(sqrt(x^\daggerx))=tr(sqrt(x^2))=Tr(x)
minimize(trace(rhoE));
subject to
(d/m)*(Pauli * vec(rhoE)) == y;
rhoE >= 0;
cvx_end
end
On the other hand, maybe CVX can't solve the 8 qubit case, does anyone know how SVT should be used to solve this convex program.
Paper link: https://arxiv.org/pdf/0909.3304.pdf
Welcome any comment : )

SCNShadable get transformed vertex

Within SCNShadable it is straightforward to get the u_modelViewTransform matrix, but how do you correctly get the current vertex position after transform?
float4 position = u_modelViewTransform * _geometry.position;
The error
program_source:443:19: error: use of undeclared identifier 'u_modelViewTransform'
float4 position = u_modelViewTransform * _geometry.position;
A bit more detail
I'm specifically, trying to get the plane equation of an SCNPlane this way, so maybe this is the wrong way to go?
you should have access to _geometry.position where _geometry is of type SCNShaderGeometry (the documentation for SCNShaderModifierEntryPointGeometry)

Formula for graphing activity of a specific variable

I am trying to figure out a function for recording activity of a value, but still with no success. I will describe everything as detailed as possible to make the comfort you may need to suggest the answer.
I have the function lineto(x, y) that draws a line to x, y position
and changes the offset to the same x, y.
I have the function moveto(x, y) that moves the offset to x, y position.
The initial coordinates of the area are x0:y0 which is the top left corner
What I want to achieve is this:
i.e I specify variable, minimum and maximum and the function
draws a line to the current state of the value, where a full height line will be the maximum. Also assume that height is a variable that represents the height of the graph area (box).
What I have for now is this:
(((current/height)*(range.maximum/height))/height)));
..Which I think.. is a complete nonsense.
So you basically need to translate the interval [minimum, maximum] to the interval [0, height].
Using math :
[minimum, maximum] (-minimum) ->
[0, maximum-minimum] (/(max-min)) ->
[0, 1] -> (* height)
So the formula to represent x from [min,max] space in [0,height] space is
xNew = ( (x-minimum)/(maximum-minimum) )* height; // extra pharathesis for clarity
For your current variable you would have
currentInBox = ( (current - minimum) / (maximum-minimum) ) * height
I think I figured it out with this algorithm:
(((current-range.minimum)*height) / range.maximum-range.minimum)
I used my topercent function partial * 100 / full as a template.

HVS color space in Open CV

I am going to detect a yellow color object when i open up my System CAM using Open CV programming, i got some help from the tutorial Object Recognition in Open CV but i am not clear about this line of code, what it does, i don't know. please elaborate me on the below line of code, which i am using.
cvInRangeS(imgHSV, cvScalar(20, 100, 100), cvScalar(30, 255, 255), imgThreshed);
other part of program:
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
cvMoments(imgYellowThresh, moments, 1);
// The actual moment values
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);
What about reading documentation?
inRange:
Checks if array elements lie between the elements of two other arrays.
And actually that article contains clear explanation:
And the two cvScalars represent the lower and upper bound of values
that are yellowish in colour.
About second code. From that calculations author finds center of object and its square. Quote from article:
You first allocate memory to the moments structure, and then you
calculate the various moments. And then using the moments structure,
you calculate the two first order moments (moment10 and moment01) and
the zeroth order moment (area).
Dividing moment10 by area gives the X coordinate of the yellow ball,
and similarly, dividing moment01 by area gives the Y coordinate.

How to find exact size for an arbitrary glyph in WPF?

I need to find exact size for each character in an arbitrary font.
The font is loaded using GlyphTypeface class.
The problem is that I can access directly only width of a glyph using the AdvanceWidths property, but the height is the same for each characters and it is set to Height property.
It seems that individual character height can be computed using a combination of Baseline, Height, XHeight, BottomSideBearings and TopSideBearings properties, but there is no documentation about real meaning of all these values. Baseline, Height and XHeight values are constant for the entire font, regarding other two - BottomSideBearings and TopSideBearings - I can't find their meaning.
Generally speaking, is there any information how can be computed the size of an individual glyph from an arbitrary font? (having just the 'TTF' file, or anything else GlyphTypeface can be loaded from).
After some research, found the right way to compute character size:
var typeface = new GlyphTypeface(new Uri(fontpath));
var character = 'W';
var charIndex = typeface.CharacterToGlyphMap[character];
var width = typeface.AdvanceWidths[charIndex];
var height = typeface.Height - typeface.TopSideBearings[charIndex]
- typeface.BottomSideBearings[charIndex];
This will give the character size in em - to find real size it needs to be multiplied by the font size.
You could perhaps get the Bounds of the geometry returned by the GlyphTypeface.GetGlyphOutline method:
GlyphTypeface typeface = new GlyphTypeface(new Uri(#"C:\Windows\Fonts\SegoeUI.ttf"));
ushort glyphIndex = typeface.CharacterToGlyphMap['W'];
double emSize = 14d;
Geometry outline = typeface.GetGlyphOutline(glyphIndex, emSize, 0d);
Size size = outline.Bounds.Size;

Resources