Skip to content

Implement S2R2Rect#253

Open
rubenpoppe wants to merge 4 commits intogolang:masterfrom
rubenpoppe:feature/r2rect
Open

Implement S2R2Rect#253
rubenpoppe wants to merge 4 commits intogolang:masterfrom
rubenpoppe:feature/r2rect

Conversation

@rubenpoppe
Copy link
Copy Markdown

Fully implement S2R2Rect with testing

return math.Max(i.Lo, math.Min(i.Hi, p))
}

func (i Interval) Project(p float64) float64 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document all public methods. You can take inspiration from the cpp implementation at https://github.com/google/s2geometry/blob/ac448e2e939863dfefdeb6500ea74fda92d8187c/src/s2/r1interval.h#L172, but make sure you follow https://go.dev/doc/comment#func.

s2/r2rect.go Outdated
return r.CapBound().CellUnionBound()
}

// func (r R2Rect) ContainsPoint(p Point) bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these commented out?

s2/r2rect.go Outdated
return r.CapBound().CellUnionBound()
}

// func (r R2Rect) ContainsPoint(p Point) bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Copy Markdown
Collaborator

@jmr jmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I get too far into the details, why do you want this?

Are you just checking things off the "done" list, or do you have a use case?

This class isn't really used much. There was once an idea that the geometry library would handle both planar and spherical geometry, but the planar part isn't well developed.

The comments say it's a "stopgap measure" (which is admittedly now 20 years old).

https://github.com/google/s2geometry/blob/ac448e2e939863dfefdeb6500ea74fda92d8187c/src/s2/s2r2rect.h#L39

}

func (i Interval) Project(p float64) float64 {
if p < i.Lo {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's clampInt, add clamp there if #256 doesn't get merged first.

geo/s2/util.go

Line 29 in fd65259

func clampInt(x, lo, hi int) int {

}
}

func (r Rect) Vertex(k int) Point {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All public functions should be directly tested.

return Point{r.X.ClampPoint(p.X), r.Y.ClampPoint(p.Y)}
}

func (r Rect) Project(p Point) Point {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't come from C++ as far as I can see.

@jmr
Copy link
Copy Markdown
Collaborator

jmr commented Jan 8, 2026

Tests are broken, but should be fixed by #255.

@rubenpoppe
Copy link
Copy Markdown
Author

Before I get too far into the details, why do you want this?

Are you just checking things off the "done" list, or do you have a use case?

Hi @jmr, I don't have a specific use case, just checking off indeed. If you want to put this on hold or drop it, it's fine by me.

// We use the rectangle's center in (s,t)-space as the cap axis. This
// doesn't yield the minimal cap but it's pretty close.
cap := CapFromPoint(toPoint(r.Center()))
for k := 0; k < 4; k++ {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range?

}

u, v := validFaceXYZToUV(0, p.Vector)
return r.Rect.ContainsPoint(r2.Point{X: u, Y: v})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the UVtoST call and why is no test failing?

}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change unrelated files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants