mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Code review nits
This commit is contained in:
parent
071acf476b
commit
345a069201
1 changed files with 20 additions and 20 deletions
|
@ -86,12 +86,15 @@ struct Ellipse {
|
||||||
height: f32,
|
height: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When `Line::new` creates a new `Line` it ensures `start.x <= end.x` for that line.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
struct Line {
|
struct Line {
|
||||||
start: Point2D<f32>,
|
start: Point2D<f32>,
|
||||||
end: Point2D<f32>,
|
end: Point2D<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Line {
|
impl Line {
|
||||||
|
/// Guarantees that `start.x <= end.x` for the returned `Line`.
|
||||||
fn new(start: Point2D<f32>, end: Point2D<f32>) -> Line {
|
fn new(start: Point2D<f32>, end: Point2D<f32>) -> Line {
|
||||||
let line = if start.x <= end.x {
|
let line = if start.x <= end.x {
|
||||||
Line { start: start, end: end }
|
Line { start: start, end: end }
|
||||||
|
@ -419,28 +422,25 @@ impl<'a> PaintContext<'a> {
|
||||||
(Some(x1), Some(x2))
|
(Some(x1), Some(x2))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intersect_ellipse_line(_e: Ellipse, _l: Line) -> (Option<Point2D<f32>>,
|
fn intersect_ellipse_line(mut e: Ellipse, mut line: Line) -> (Option<Point2D<f32>>,
|
||||||
Option<Point2D<f32>>) {
|
Option<Point2D<f32>>) {
|
||||||
let mut line = _l;
|
let mut rotated_axes = false;
|
||||||
let mut e = _e;
|
fn rotate_axes(point: Point2D<f32>, clockwise: bool) -> Point2D<f32> {
|
||||||
let mut rotated_axises = false;
|
|
||||||
|
|
||||||
fn rotate_axises(point: Point2D<f32>, clockwise: bool) -> Point2D<f32> {
|
|
||||||
if clockwise {
|
if clockwise {
|
||||||
// rotate clockwise by 90 degress
|
// rotate clockwise by 90 degrees
|
||||||
Point2D::new(point.y, -point.x)
|
Point2D::new(point.y, -point.x)
|
||||||
} else {
|
} else {
|
||||||
// rotate counter clockwise by 90 degress
|
// rotate counter clockwise by 90 degrees
|
||||||
Point2D::new(-point.y, point.x)
|
Point2D::new(-point.y, point.x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if line height is greater than it's width then rotate the axises by 90 degrees,
|
// if line height is greater than its width then rotate the axes by 90 degrees,
|
||||||
// i.e. (x, y) -> (y, -x).
|
// i.e. (x, y) -> (y, -x).
|
||||||
if (line.end.x - line.start.x).abs() < (line.end.y - line.start.y).abs() {
|
if (line.end.x - line.start.x).abs() < (line.end.y - line.start.y).abs() {
|
||||||
rotated_axises = true;
|
rotated_axes = true;
|
||||||
line = Line::new(rotate_axises(line.start, true), rotate_axises(line.end, true));
|
line = Line::new(rotate_axes(line.start, true), rotate_axes(line.end, true));
|
||||||
e = Ellipse { origin: rotate_axises(e.origin, true),
|
e = Ellipse { origin: rotate_axes(e.origin, true),
|
||||||
width: e.height, height: e.width };
|
width: e.height, height: e.width };
|
||||||
}
|
}
|
||||||
debug_assert!(line.end.x - line.start.x > f32::EPSILON,
|
debug_assert!(line.end.x - line.start.x > f32::EPSILON,
|
||||||
|
@ -471,23 +471,23 @@ impl<'a> PaintContext<'a> {
|
||||||
if x0 > x1 {
|
if x0 > x1 {
|
||||||
mem::swap(&mut p0, &mut p1);
|
mem::swap(&mut p0, &mut p1);
|
||||||
}
|
}
|
||||||
if rotated_axises {
|
if rotated_axes {
|
||||||
p0 = rotate_axises(p0, false);
|
p0 = rotate_axes(p0, false);
|
||||||
p1 = rotate_axises(p1, false);
|
p1 = rotate_axes(p1, false);
|
||||||
}
|
}
|
||||||
(Some(p0), Some(p1))
|
(Some(p0), Some(p1))
|
||||||
},
|
},
|
||||||
(Some(x0), None) => {
|
(Some(x0), None) => {
|
||||||
let mut p = Point2D::new(x0, a * x0 + b) + e.origin;
|
let mut p = Point2D::new(x0, a * x0 + b) + e.origin;
|
||||||
if rotated_axises {
|
if rotated_axes {
|
||||||
p = rotate_axises(p, false);
|
p = rotate_axes(p, false);
|
||||||
}
|
}
|
||||||
(Some(p), None)
|
(Some(p), None)
|
||||||
},
|
},
|
||||||
(None, Some(x1)) => {
|
(None, Some(x1)) => {
|
||||||
let mut p = Point2D::new(x1, a * x1 + b) + e.origin;
|
let mut p = Point2D::new(x1, a * x1 + b) + e.origin;
|
||||||
if rotated_axises {
|
if rotated_axes {
|
||||||
p = rotate_axises(p, false);
|
p = rotate_axes(p, false);
|
||||||
}
|
}
|
||||||
(Some(p), None)
|
(Some(p), None)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue