Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
stb_truetype-rs
Commits
53d0f01a
Verified
Commit
53d0f01a
authored
Aug 24, 2018
by
Alex Butler
Browse files
Merge branch 'safe'
parents
dd5251d8
77055823
Pipeline
#1110
passed with stages
in 3 minutes and 31 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/lib.rs
View file @
53d0f01a
...
...
@@ -39,11 +39,39 @@ pub struct Vertex {
impl
Vertex
{
pub
fn
vertex_type
(
&
self
)
->
VertexType
{
unsafe
{::
std
::
mem
::
transmute
(
self
.type_
)}
match
self
.type_
{
1
=>
VertexType
::
MoveTo
,
2
=>
VertexType
::
LineTo
,
3
=>
VertexType
::
CurveTo
,
type_
=>
panic!
(
"Invalid vertex type: {}"
,
type_
),
}
}
}
#[derive(Copy,
Clone,
Debug)]
#[test]
fn
test_vertex_type
()
{
fn
v
(
type_
:
VertexType
)
->
Vertex
{
Vertex
{
x
:
0
,
y
:
0
,
cx
:
0
,
cy
:
0
,
type_
:
type_
as
u8
}
}
assert_eq!
(
v
(
VertexType
::
MoveTo
)
.vertex_type
(),
VertexType
::
MoveTo
);
assert_eq!
(
v
(
VertexType
::
LineTo
)
.vertex_type
(),
VertexType
::
LineTo
);
assert_eq!
(
v
(
VertexType
::
CurveTo
)
.vertex_type
(),
VertexType
::
CurveTo
);
}
#[test]
#[should_panic]
fn
test_invalid_vertex_type
()
{
let
v
=
Vertex
{
x
:
0
,
y
:
0
,
cx
:
0
,
cy
:
0
,
type_
:
255
};
let
s
=
match
v
.vertex_type
()
{
VertexType
::
MoveTo
=>
"move to"
,
VertexType
::
LineTo
=>
"line to"
,
VertexType
::
CurveTo
=>
"curve to"
,
};
// With `Vertex::vertex_type` defined as `transmute` this would be undefined behavior:
println!
(
"{}"
,
s
);
}
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq)]
#[repr(u8)]
pub
enum
VertexType
{
MoveTo
=
1
,
...
...
@@ -775,7 +803,7 @@ impl<Data: Deref<Target=[u8]>> FontInfo<Data> {
}
close_shape
(
&
mut
vertices
[
..
],
&
mut
num_vertices
,
was_off
,
start_off
,
sx
,
sy
,
scx
,
scy
,
cx
,
cy
);
assert
!
(
num_vertices
<=
vertices
.len
());
unsafe
{
vertices
.
set_len
(
num_vertices
)
}
;
vertices
.
truncate
(
num_vertices
);
vertices
}
else
if
number_of_contours
==
-
1
{
// Compound shapes
...
...
Alex Butler
@alexheretic
mentioned in merge request
!1 (closed)
·
Aug 24, 2018
mentioned in merge request
!1 (closed)
mentioned in merge request !1
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment